All Products
Search
Document Center

Application Real-Time Monitoring Service:Sample configurations of the RUM SDK for mini programs

Last Updated:Apr 28, 2025

The Real User Monitoring (RUM) SDK for mini programs of Application Real-Time Monitoring Service (ARMS) provides a wide variety of custom configurations to meet your business requirements. This topic describes the common SDK configurations of mini programs for reference purposes.

SDK parameters

Parameter

Type

Description

Required

Default value

pid

String

The mini program ID.

Yes

-

endpoint

String

The address to which monitoring data is reported.

Yes

-

env

-

The environment of the mini program:

  • prod: production environment

  • gray: canary release environment

  • pre: pre-release environment

  • daily: daily environment

  • local: local environment

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 SDK.

No

user.id is generated by the SDK by default

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

}

sessionConfig

Object

The session sampling rate and timeout settings. For more information, see sessionConfig parameters.

No

-

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 evaluateApi parameters.

No

-

filters

Object

The event filtering settings. For more information, see filters parameters.

No

-

properties

Object

The custom properties that take effect for all events. For more information, see properties parameters.

No

-

user parameters

Parameter

Type

Description

Required

Default value

id

String

The user ID, which is generated by the SDK and cannot be modified.

No

Default ID generated by the SDK

tags

String

The tags.

No

-

name

String

The username.

No

-

Example

Note

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

Note

Overwriting the user ID affects the UV data.

ArmsRum.init({
  pid: "your app id",
  endpoint: "your endpoint",
  reportConfig: {
    flushTime: 0, // Specify that data is immediately reported.
    maxEventCount: 50 // Specify the maximum number of data entries reported at a time.
  }
});

sessionConfig parameters

Parameter

Type

Description

Required

Default value

sampleRate

Number

The sampling rate. Valid values: 0 to 1.

The value 0.5 specifies a 50% sampling rate.

No

1

maxDuration

Number

The maximum duration of a session. Unit: milliseconds. Default value: 86400000 (24 hours).

No

86400000

overtime

Number

The timeout duration of a session. Unit: milliseconds. Default value: 1800000 (half an hour).

No

1800000

The user ID and session information is stored in the local cache of the mini program:

  • _arms_uid: the unique user ID (user.id).

  • _arms_session: the semantic session information.

    • sessionId: the unique session ID.

    • sampled: indicates whether sampling was triggered.

    • startTime: the start timestamp of the session.

    • lastTime: the timestamp when the session was last active.

`${sessionId}-${sampled}-${startTime}-${lastTime}`

Example

ArmsRum.init({
  pid: "your app id",
  endpoint: "your endpoint",
  sessionConfig: {
    sampleRate: 0.5, // Specify a 50% sampling rate. 
    maxDuration: 86400000,
    overtime: 3600000,
  },
});

collectors parameters

The 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 API events, including 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.

Parameter

Type

Description

Required

name

String

The API name, which is generally a converged URL and can be up to 1,000 characters in length.

For example, if the URL is /list/123, the converged name parameter is displayed as /list/$id.

Important

This parameter takes precedence over what is returned by the parseResourceName function.

No

message

String

The API information, which is a brief string to describe the API that contains no more than 1,000 characters.

No

success

Number

Indicates whether the request was successful:

  • 1: The request was successful.

  • 0: The request failed.

  • -1: The status of the request is unknown.

No

duration

Number

The total duration of the request.

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 endpoint",
  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.
      })
    }
  }
});

filters parameters

The filters parameters exclude resource and exception events that do not need to be reported.

Parameter

Type

Description

Required

resource

MatchOption | MatchOption[]

Excludes events related to static resources and API (such as XMLHttpRequest or fetch) that do not need to be reported.

No

exception

MatchOption | MatchOption[]

Excludes exception events that do not need to be reported.

No

MatchOption

type MatchOption = string | RegExp | ((value: string) => boolean);
  • string: matches any URL that starts with the specified value. For example, https://api.aliyun.com can match https://api.aliyun.com/v1/resource.

  • RegExp: specifies a regular expression and URL.

  • function: uses a function to determine whether a URL is matched. If true is returned, the URL is matched.

When the input is MatchOption[], the preceding conditions are evaluated in order, and it will be excluded if any condition is met.

Example

ArmsRum.init({
  pid: "your app id",
  endpoint: "your endpoint",
  filters: {
    // Exclude exception events
    exception: [
      'Test error', // Filter error messages starting with 'Test error'.
      /^Script error\.?$/, // Specify a regular expression.
      (msg) => {
        return msg.includes('example-error');
      },
    ],
    // Exclude resource or API events
    resource: [
      'https://example.com/', // Filter resources starting with 'https://example.com/'.
      /localhost/i,
      (url) => {
        return url.includes('example-resource');
      },
    ],
  },
});

properties parameters

Properties provided by RUM can be configured for all events.

Parameter

Type

Description

Required

[key: string]

String | Number

  • The key must be a string that conforms to the JSON specification. The maximum length of a key is 50 characters. The excess part of the key is truncated.

  • If the value is a string, the maximum length is 2,000 characters. If the value is neither a string nor a number, the key-value pair is removed.

No

You can use evaluateApi, sendCustom, sendException, and sendResource to add properties to an event. The properties take effect only for the event.

Global properties and event properties are merged when they are stored. Event properties have a higher priority than global properties. If the keys of event properties are the same as those of global properties, the event properties overwrite the global properties. The number of key-value pairs cannot exceed 20 after merging. If the number exceeds 20, the pairs are sorted based on keys and the excess ones are removed.

Example

Globally configured properties are attached to all reported events.

ArmsRum.init({
  pid: "your app id",
  endpoint: "your endpoint",
  properties: {
    prop_string: 'xx',
    prop_number: 2,
    // If the length of the key or value exceeds the limit, the excess part is truncated.
    more_than_50_key_limit_012345678901234567890123456789: 'yy',
    more_than_2000_value_limit: new Array(2003).join('1'),
    // The following invalid key-value pairs will be removed.
    prop_null: null,
    prop_undefined: undefined,
    prop_bool: true,
  },
});

Other parameters

RUM SDK allows you to configure common properties that are resolved based on IP addresses and UserAgent. Proactively configured parameters have a higher priority than automatically resolved parameters.

Parameter

Type

Description

Required

device

Object

The device information.

No

os

Object

The system and container information.

No

geo

Object

The geolocation information.

No

isp

Object

The ISP information.

No

net

Object

The network information.

No

For more information about configuration items about the preceding parameters, see Common attributes.

Example

ArmsRum.init({
  pid: "your app id",
  endpoint: "your endpoint",
  geo: {
    country: 'your custom country info',
    city: 'your custom city info',
  },
});

SDK API

The 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 a specific key
ArmsRum.setConfig('env', 'pre');

// Overwrite the following settings
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 parameters. The following table describes the parameters related to data reporting. You need to define the business semantics.

Parameter

Type

Description

Required

Default value

type

String

Type

Yes

-

name

String

Name

Yes

-

group

String

Group

No

-

value

Number

Description

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 parameters.

Parameter

Type

Description

Required

Default value

name

String

The exception name.

Yes

-

message

String

The exception information.

Yes

-

file

String

The file where the exception occurred.

No

-

stack

String

The stack information about the exception.

No

-

line

Number

The line where the exception occurred.

No

-

column

Number

The column where the exception occurred.

No

-

ArmsRUM.sendException({
  // 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 parameters.

Parameter

Type

Description

Required

Default value

name

String

The resource name.

Yes

-

type

String

The type of the resource. Examples: script, api, image.

Yes

-

duration

String

The response time.

Yes

-

success

Number

Indicates whether the request was successful:

  • 1: The request was successful.

  • 0: The request failed.

  • -1: The status of the request is unknown.

No

-

method

String

The request method.

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',
});