This topic describes how to use the browser monitoring feature of Application Real-Time Monitoring Service (ARMS) to monitor Alipay mini programs and introduces the common SDK configurations, API operations, and advanced scenarios of the browser monitoring feature.
Basic usage
Introduce and initialize the npm package.
In your mini program project, introduce the npm package named
@arms/js-sdk
to facilitate log reporting.npm install @arms/js-sdk
Add the following information to the monitor.js file in the /utils directory to initialize the package.
NoteYou can specify the name and storage path of the JavaScript (JS) file.
import AlipayLogger from '@arms/js-sdk/miniapp'; const Monitor = AlipayLogger.init({ pid: 'xxx', region: 'cn', // The region where the application is deployed. Set region to cn if the application is deployed in China and set region to sg if the application is deployed outside China. }); export default Monitor;
NoteFor more information about parameter settings, see Common parameters of SDK.
Set security domain names.
If region is set to
cn
, add arms-retcode.aliyuncs.com to the HTTP security domain.If region is set to
sg
, add arms-retcode-sg.aliyuncs.com to the HTTP security domain.
Other API methods
Method | Parameter | Description |
setCommonInfo | {[key: string]: string;} | Set basic log fields for the scenarios such as phased release. |
setConfig | {[key: string]: string;} | Set the config field. For more information, see SDK reference. |
pageShow | {} | Instrument PV data. |
pageHide | {} | Instrument health data. |
error | String/Object | Instrument error logs. |
api | For more information, see SDK methods. | Report API logs. |
sum/avg | String | Report custom sum and average logs. |
Advanced scenarios
If the basic usage cannot meet your requirements, refer to the following advanced scenarios:
Manually report the API request results.
Set disableHook to
true
. The logs of my.httpRequest are not automatically reported.Manually call the api() method to report the API operations.
Disable automatic reporting and enable manual instrumentation.
Do not use the hookApp and hookPage methods in the app.js and page.js files.
To send the PV data of the page, call the pageShow() method in the onShow method.
NoteWe recommend that you do not call the pageShow() method together with the hookPage() method. Otherwise, the PV logs are repeatedly reported.
import Monitor from '/util/monitor'; Page({ onShow: function() { Monitor.pageShow(); } })
To send the health data (health and browsing time) of the page, call the pageHide() method in the onHide and onUnload methods.
NoteWe recommend that you do not call the pageHide() method together with the hookPage() method. Otherwise, the logs are repeatedly reported.
import Monitor from '/util/monitor'; Page({ onHide: function() { Monitor.pageHide(); }, onUnload: function() { Monitor.pageHide(); } ... })
Common parameters of SDK
ARMS browser monitoring provides a series of SDK parameters. You can configure the parameters to meet additional requirements. The following table describes the common parameters suitable for the scenarios described in this topic.
|
|
|
|
|
pid | String | The unique ID of the project. It is automatically generated by ARMS when it creates a site. | Yes | None |
uid | String | The ID of the user. The value is an identifier of the user and can be used to search for the user. You can specify a custom value. If you do not specify this parameter, the SDK is automatically generated and updated every six months. | No | Automatically generated by the SDK |
tag | String | The input tag. Each log carries a tag. | No | None |
release | String | The version of the application. We recommend that you configure this parameter to view the report information of different versions. | No |
|
environment | String | The environment field. Valid values: prod, gray, pre, daily, and local.
| No |
|
sample | Integer | The log sampling configuration. The value is an integer from 1 to 100. The performance logs and success API logs are sampled at the | No |
|
behavior | Boolean | Specifies whether to record the user behavior that reports errors for easy troubleshooting. | No |
|
enableLinkTrace | Boolean | For more information about back-to-back Tracing Analysis, see Use the front-to-back tracing feature to diagnose API errors. | No |
|
ARMS browser monitoring also provides other SDK parameters. For more information, see SDK reference.