Abstract: The request time is too long, which affects user experience. Use Fundebug to monitor slow requests.
The micro program monitoring plug-in of Fundebug supports monitoring HTTP request errors in version 0.5.0. HTTP requests are initiated through wx.request in the small program. If the request fails, it will be captured and reported. After a year, the wechat applet plug-in has been updated to 1.3.1 and provides a very useful function to monitor slow HTTP requests. This is sufficient for lightweight performance analysis.
In this article, we use a weather wechat mini program (developed by Bodekjan) as an example to demonstrate how to monitor slow requests. The weather() function in map-wx.js calls the interface provided by the Baidu Map applet API to get the weather forecast information.
Access to the monitoring
Due to the use of Baidu’s API, we cannot confirm the stability of the interface, which may be very slow sometimes, resulting in the inability to display the weather information. So, we use Fundebug to monitor for requests that are too slow. Next, let’s demonstrate how to monitor slow requests. After registering an account, remember to select the project type “wechat Mini program” when creating the project.
Follow instructions to complete access process:
Add the following code at the top of app.js (remember to replace the apikey with your own) :
var fundebug = require(". / utils/fundebug. 1.3.1. Min. Js. "");
fundebug.init({
apikey: "YOUR-API-KEY".monitorMethodCall: true.monitorMethodArguments: true.monitorHttpData: true.setSystemInfo: true.setUserInfo: true.setLocation: true.httpTimeout: 200
});
Copy the code
The init() function can be used simply by setting the apikey, but to maximize the power of monitoring, it is useful to set several monitoring options. Wechat mini program plug-in has a lot of configurable items, because it involves data, it is disabled by default. We can monitor function calls (monitor methodcalls), function calls’ parameters (monitorMethodArguments), data in the Body of HTTP requests (monitorHttpData), Obtain system information (setSystemInfo), user information (setUserInfo), and geographical location (setLocation).
Monitoring slow Requests
Finally, and most importantly, configure httpTimeout, of type Number in milliseconds (ms), to monitor requests that exceed a specific time. For demonstration purposes, let’s set the time to 200 milliseconds.
When I run the code in wechat developer tools, Fundebug immediately receives an error. Small program to https://api.map.baidu.com/telematics/v3/weather interface request length for 571 ms, less than 200 ms preset time.
Error details
The request returns code 200, indicating that the data was retrieved normally. Click on the error to see details of the error:
Through the statistics above, we can know the trend of slow conditions in the interface for obtaining weather information, the number of users affected, and the cumulative times of occurrence. This can be used to evaluate whether the interface needs to be optimized or even replaced with another third-party interface to solve the problem.
Additional information
Because monitorHttpData is configured, we can see the details in the request body. When a request fails, it is sometimes necessary to analyze the cause of the failure in combination with parameters.
In addition, user behavior data records the details of the running of small programs, especially the call sequence of functions, which is very helpful for understanding the execution logic of programs before errors:
About Fundebug
Fundebug focuses on real-time BUG monitoring for JavaScript, wechat applets, wechat games, Alipay applets, React Native, Node.js and Java online applications. Since its official launch on November 11, 2016, Fundebug has handled over 1 billion error events in total, and paid customers include Sunshine Insurance, Walnut Programming, Lychee FM, Zhangmen 1-to-1, Weimai, Qingtuanshe and many other brand enterprises. Welcome to try it for free!
Copyright statement
Please indicate the author Fundebug and the address of this article:
Blog.fundebug.com/2019/06/27/…