Configure the Application Real-Time Monitoring Service (ARMS) Real User Monitoring (RUM) SDK for mini programs using the initialization parameters, data collectors, event filters, custom properties, and APIs described in this reference.
Pass all configuration options to ArmsRum.init():
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
// Additional parameters
});Initialization parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
pid | String | Yes | - | The mini program ID. |
endpoint | String | Yes | - | The address to which monitoring data is reported. |
env | String | No | prod | The deployment environment. Valid values: prod (production), gray (canary release), pre (pre-release), daily (daily), local (local). |
version | String | No | - | The mini program version. |
user | Object | No | SDK-generated user.id | User identity settings. See user parameters. |
collectors | Object | No | - | Data collector settings. See collectors parameters. |
beforeReport | Function | No | noop | A callback invoked before each report. Use it to modify or block outgoing data. |
reportConfig | Object | No | { flushTime: 3000, maxEventCount: 20 } | Data reporting settings. See reportConfig parameters. |
sessionConfig | Object | No | - | Session sampling and timeout settings. See sessionConfig parameters. |
parseViewName | Function | No | - | Parses the view name (view.name) from a page URL. |
parseResourceName | Function | No | - | Parses the resource name (resource.name) from a resource URL. |
evaluateApi | Function | No | - | Custom parser for API events. See evaluateApi parameters. |
filters | Object | No | - | Event filtering rules. See filters parameters. |
properties | Object | No | - | Custom properties attached to all events. See properties parameters. |
user parameters
Configure user identity for session tracking.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
id | String | No | SDK-generated | The user ID. Generated by the SDK and cannot be modified. |
tags | String | No | - | User tags for categorization. |
name | String | No | - | The username. |
Do not overwrite user.id. Changing it affects unique visitor (UV) data. To integrate your own account system, set user.name or user.tags instead.
Example
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
user: {
name: getYourUserName(),
tags: getYourTags(),
}
});reportConfig parameters
Control how frequently and in what batch size the SDK reports data.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
flushTime | Number | No | 3000 | The reporting interval in milliseconds. Valid values: 0 to 10000. Set to 0 for immediate reporting. |
maxEventCount | Number | No | 20 | The maximum number of events per report. Valid values: 1 to 100. |
Example
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
reportConfig: {
flushTime: 0, // Report data immediately
maxEventCount: 50 // Send up to 50 events per batch
}
});sessionConfig parameters
Control session sampling rates and timeouts. Use sampling to reduce data volume in high-traffic environments.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
sampleRate | Number | No | 1 | The sampling rate. Valid values: 0 to 1. For example, 0.5 applies a 50% sampling rate. |
maxDuration | Number | No | 86400000 | The maximum session duration in milliseconds. Default: 24 hours. |
overtime | Number | No | 1800000 | The session timeout in milliseconds. A session expires after this period of inactivity. Default: 30 minutes. |
Local cache
The SDK stores user ID and session data in the mini program's local cache:
_arms_uid: the unique user ID (user.id)._arms_session: session metadata in the format${sessionId}-${sampled}-${startTime}-${lastTime}, where:sessionId: the unique session ID.sampled: whether sampling was triggered.startTime: the session start timestamp.lastTime: the last activity timestamp.
Example
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
sessionConfig: {
sampleRate: 0.5, // 50% sampling rate
maxDuration: 86400000, // 24-hour max session
overtime: 3600000, // 1-hour inactivity timeout
},
});collectors parameters
Collectors gather specific types of monitoring data. Each collector can be enabled (true), disabled (false), or configured with an options object.
| Parameter | Type | Required | Default | Description | |
|---|---|---|---|---|---|
api | Boolean \ | Object | No | true | Tracks API requests. |
jsError | Boolean \ | Object | No | true | Tracks JavaScript errors. |
consoleError | Boolean \ | Object | No | true | Tracks errors from console.error. |
action | Boolean \ | Object | No | true | Tracks user interactions. |
Example
Disable user interaction tracking:
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
collectors: {
action: false,
}
});evaluateApi parameters
The evaluateApi function provides custom parsing for API events, including request and httpRequest events. It accepts three arguments and returns a Promise<IApiBaseAttr>.
Function signature:
evaluateApi: async (options, response, error?) => IApiBaseAttrArguments:
| Parameter | Type | Description |
|---|---|---|
options | Object | The request parameters, including url, headers, and data. The exact fields depend on the request method. |
response | Object | The response body. |
error | Error | The error object. Present only when the request fails. |
Return value (IApiBaseAttr):
Returned fields overwrite the SDK defaults. Omitted fields keep their default values.
| Parameter | Type | Required | Description | |
|---|---|---|---|---|
name | String | No | The API name, typically a converged URL. Maximum 1,000 characters. For example, /list/123 becomes /list/$id. This value takes precedence over parseResourceName. | |
message | String | No | A brief description of the API. Maximum 1,000 characters. | |
success | Number | No | The request result: 1 (success), 0 (failure), -1 (unknown). | |
duration | Number | No | The total duration of the request. | |
status_code | Number \ | String | No | The HTTP status code. |
snapshots | String | No | Debugging data such as reqHeaders, params, and resHeaders. Maximum 5,000 characters. Snapshots are not indexed and cannot be used as filter conditions for queries or aggregation. |
Example
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
evaluateApi: async (options, response, error) => {
const respText = JSON.stringify(response);
// Returned fields overwrite defaults. Omitted fields keep default values.
return {
name: 'my-custom-api',
success: error ? 0 : 1,
snapshots: JSON.stringify({
params: 'page=1&size=10',
response: respText.substring(0, 2000),
reqHeaders: '',
resHeaders: ''
})
}
}
});filters parameters
Exclude specific resource and exception events from reporting.
| Parameter | Type | Required | Description | |
|---|---|---|---|---|
resource | MatchOption \ | MatchOption[] | No | Excludes static resource and API events (such as XMLHttpRequest or fetch). |
exception | MatchOption \ | MatchOption[] | No | Excludes exception events. |
MatchOption
type MatchOption = string | RegExp | ((value: string) => boolean);Three matching modes are available:
String: matches any URL that starts with the specified value. For example,
'https://api.aliyun.com'matcheshttps://api.aliyun.com/v1/resource.RegExp: matches URLs against a regular expression.
Function: a custom function that returns
trueto exclude the event.
When MatchOption[] is provided, conditions are evaluated in order. An event is excluded if any condition matches.
Example
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
filters: {
// Exclude exception events
exception: [
'Test error', // Prefix match
/^Script error\.?$/, // Regex match
(msg) => {
return msg.includes('example-error'); // Custom function
},
],
// Exclude resource and API events
resource: [
'https://example.com/', // Prefix match
/localhost/i, // Regex match (case-insensitive)
(url) => {
return url.includes('example-resource');
},
],
},
});properties parameters
Attach custom key-value properties to all events.
| Parameter | Type | Required | Description | |
|---|---|---|---|---|
[key: string] | String \ | Number | No | A custom property. Key: maximum 50 characters (excess is truncated). String value: maximum 2,000 characters. Non-string, non-number values are removed. |
Merge behavior:
Global properties (set in
init()) and event-level properties (set viaevaluateApi,sendCustom,sendException, orsendResource) are merged at storage time.Event-level properties take precedence over global properties with the same key.
After merging, the total number of key-value pairs cannot exceed 20. Excess pairs are sorted by key and removed.
Example
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
properties: {
prop_string: 'xx',
prop_number: 2,
// Keys or values exceeding the length limit are truncated
more_than_50_key_limit_012345678901234567890123456789: 'yy',
more_than_2000_value_limit: new Array(2003).join('1'),
// Invalid values are removed
prop_null: null,
prop_undefined: undefined,
prop_bool: true,
},
});Auto-resolved parameters
The SDK automatically resolves the following properties from IP addresses and UserAgent strings. Manually configured values take precedence over auto-resolved values.
| Parameter | Type | Required | Description |
|---|---|---|---|
device | Object | No | Device information. |
os | Object | No | Operating system and container information. |
geo | Object | No | Geolocation information. |
isp | Object | No | ISP information. |
net | Object | No | Network information. |
For field descriptions, see Common attributes.
Example
ArmsRum.init({
pid: "<your-app-id>",
endpoint: "<your-endpoint>",
geo: {
country: '<your-country>',
city: '<your-city>',
},
});SDK APIs
Use the following APIs to read and modify configurations at runtime and to report custom data.
getConfig
Retrieve the current SDK configuration:
const config = ArmsRum.getConfig();setConfig
Update SDK configuration after initialization:
// Update a single parameter
ArmsRum.setConfig('env', 'pre');
// Update multiple parameters
const config = ArmsRum.getConfig();
ArmsRum.setConfig({
...config,
version: '1.0.0',
env: 'pre',
});sendCustom
Report a custom event. Both type and name are required.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
type | String | Yes | - | The event type. |
name | String | Yes | - | The event name. |
group | String | No | - | The event group. |
value | Number | No | - | A numeric value associated with the event. |
ArmsRum.sendCustom({
type: 'CustomEventType1',
name: 'customEventName2',
group: 'customEventGroup3',
value: 111.11
});sendException
Report a custom exception. Both name and message are required.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
name | String | Yes | - | The exception name. |
message | String | Yes | - | The exception message. |
file | String | No | - | The file where the exception occurred. |
stack | String | No | - | The stack trace. |
line | Number | No | - | The line number. |
column | Number | No | - | The column number. |
ArmsRum.sendException({
// Required
name: 'customErrorName',
message: 'custom error message',
// Optional
file: 'custom exception filename',
stack: 'custom exception error.stack',
line: 1,
column: 2
});sendResource
Report a custom resource event. The name, type, and duration parameters are required.
| Parameter | Type | Required | Default | Description | |
|---|---|---|---|---|---|
name | String | Yes | - | The resource name. | |
type | String | Yes | - | The resource type, such as script, api, or image. | |
duration | String | Yes | - | The response time. | |
success | Number | No | - | The request result: 1 (success), 0 (failure), -1 (unknown). | |
method | String | No | - | The request method. | |
status_code | Number \ | String | No | - | The HTTP status code. |
message | String | No | - | A descriptive message. | |
url | String | No | - | The request URL. | |
trace_id | String | No | - | The trace ID for distributed tracing. |
ArmsRum.sendResource({
// Required
name: 'getListByPage',
message: 'success',
duration: 800,
// Optional
url: 'https://www.example.com/data/getListByPage',
});