The Real User Monitoring (RUM) SDK for Application Real-Time Monitoring Service (ARMS) provides a wide variety of custom configurations to meet your business requirements. This topic describes the RUM SDK for mini programs of ARMS.
SDK parameters
Parameter | Type | Description | Required | Default value |
pid | string | The ID of the mini program. | Yes | - |
endpoint | string | The address to which monitoring data is reported. | Yes | - |
env | - | The environment of the mini program. Valid values:
| No | prod |
version | string | The version of the mini program. | No | - |
user | object | The user settings. By default, the user ID (user.id) is generated by the OpenRUM SDK. | No | - |
collectors | object | The Collector settings. | No | - |
beforeReport | function | The function that is called before reporting data to modify or block the reported data. | No | noop |
reportConfig | object | The data reporting settings. | No | { flushTime: 3000, maxEventCount: 20 } |
parseViewName | function | The function used to parse the view name (view.name). The input parameter is the URL of the page. | No | - |
parseResourceName | function | The function used to parse the resource name (resource.name). The input parameter is the URL of the resource. | No | - |
evaluateApi | function | The function used to parse API events. For more information, see the Integrate a mini program section. | No | - |
User parameters
Parameter | Type | Description | Required | Default value |
id | string | The user ID, which is generated by the OpenRUM SDK and cannot be modified. | No | - |
tags | string | The tags. | No | - |
name | string | The username. | No | - |
Example
If you want to use your own account system, we recommend that you change the username (user.name) or tags (user.tags) instead of the user ID (user.id). Overwriting the user ID affects the unique visitor (UV) data.
ArmsRum.init({
pid: "your app id",
endpoint: "your endpoint",
user: {
name: getYourUserName(),
tags: getYourTags(),
}
});
reportConfig parameters
Parameter | Type | Description | Required | Default value |
flushTime | number | The interval at which data is reported. Valid values: 0 to 10000. | No | 3000 |
maxEventCount | number | The maximum number of data entries reported at a time. Valid values: 1 to 100. | No | 20 |
Example
Overwriting the user ID affects the UV data.
ArmsRum.init({
pid: "your app id",
endpoint: "your endpint",
reportConfig: {
flushTime: 0, // Specify that data is immediately reported.
maxEventCount: 50 // Specify the maximum number of data entries reported at a time.
}
});
Collectors parameters
OpenRUM SDK uses Collectors, such as api and static Resource, to collect page monitoring data.
Parameter | Type | Description | Required | Default value |
api | boolean | object | Tracks API requests. | No | true |
jsError | boolean | object | Tracks JavaScript errors. | No | true |
consoleError | boolean | object | Tracks errors thrown by console.error. | No | true |
action | boolean | object | Tracks user behavior. | No | true |
Example
In the following example, the collection of user interaction data is disabled.
ArmsRum.init({
pid: "your app id",
endpoint: "your endpoint",
collectors: {
action: false,
}
});
EvaluateApi parameters
The evaluateApi function provides custom parsing for request and httpRequest events.
Parameter | Type | Description |
options | object | The request parameters, including url, headers, and data. The parameters depend on the request method. |
response | object | The response body of the request. |
error | Error | The error. This parameter is optional and is available only when the request fails. |
This function can be asynchronously called. Promise<IApiBaseAttr> is returned. The following table describes IApiBaseAttr.
Field | Type | Description | Required |
name | string | The API name, which is generally a converged URL and can be up to 1,000 characters in length. Assume that the URL is Important This field takes precedence over what is returned by the parseResourceName function. | No |
message | string | A brief string to describe the API, which can be up to 1,000 characters in length. | No |
success | number | Indicates whether the request is successful.
| No |
duration | number | The total duration of the API. | No |
status_code | number | string | The status code. | No |
snapshots | string | The snapshot. Note A snapshot stores information about reqHeaders, params, and resHeaders. You can customize the fields that a snapshot is composed of. Snapshots are mainly used to troubleshoot exceptions. A snapshot cannot be configured as a filter condition for query or aggregation because it has no index. It can only be a string with up to 5,000 characters. | No |
Example
ArmsRum.init({
pid: "your app id",
endpoint: "your endpint",
evaluateApi: async (options, response, error) => {
const respText = JSON.stringify(response);
// The returned fields will overwrite the default content. If the fields are not returned, the default content is used.
return {
name: 'my-custom-api',
success: error ? 0 : 1,
snapshots: JSON.stringify({
params: 'page=1&size=10', // The input parameter.
response: respText.substring(0, 2000), // The returned value.
reqHeaders: '', // The request header.
resHeaders: ''' // The response header.
})
}
}
});
SDK API
OpenRUM SDK provides APIs for modifying and reporting custom data and dynamically modifying SDK configurations.
getConfig
You can use the function to obtain the SDK configurations.
setConfig
You can use the function to modify the SDK configurations.
// Set the environment type.
ArmsRum.setConfig('env', 'pre');
// The following content may be overwritten.
const config = ArmsRum.getConfig();
ArmsRum.setConfig({
...config,
version: '1.0.0',
env: 'pre',
});
sendCustom
To report custom data, you must specify the type and name fields. The following table describes the parameters related to data reporting. You need to define the business semantics.
Field | Type | Description | Required | Default value |
type | string | The type of the data. | Yes | - |
name | string | The name of the data. | Yes | - |
group | string | The group to which the data belongs. | No | - |
value | number | The value of the data. | No | - |
ArmsRum.sendCustom({
type: 'CustomEvnetType1',
name: 'customEventName2',
group: 'customEventGroup3',
value: 111.11
});
sendException
To report custom exception data, you must specify the name and message fields.
Field | Type | Description | Required | Default value |
name | string | The exception name. | Yes | - |
message | string | The exception information. | Yes | - |
file | string | The file where the occurs. | No | - |
stack | string | The stack information about the exception. | No | - |
line | number | The line where the exception occurs. | No | - |
column | number | The column where the exception occurs. | No | - |
ArmsRum.sendCustom({
// Required.
name: 'customErrorName',
message: 'custom error message',
// Optional.
file: 'custom exception filename',
stack: 'custom exception error.stack',
line: 1,
column: 2
});
sendResource
To report custom resource data, you must specify the name, type, and duration fields.
Field | Type | Description | Required | Default value |
name | string | The name of the resource. | Yes | - |
type | string | The type of the resource. Examples: script, api, and image. | Yes | - |
duration | string | The response time. | Yes | - |
success | number | Indicates whether the request is successful.
| No | - |
method | string | The method of the request. | No | - |
status_code | number | string | The status code. | No | - |
message | string | The message returned. | No | - |
url | string | The request URL. | No | - |
trace_id | string | The trace ID. | No | - |
ArmsRum.sendResource({
// Required.
name: 'getListByPage',
message: 'success',
duration: 800,
// Optional.
url: 'https://www.aliyun.com/data/getListByPage',
});