SDK configuration reference

更新时间:
复制 MD 格式

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 Configuration

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

-

Application environment:

  • prod: production environment

  • Gray indicates the grayscale environment.

  • pre: pre-release environment

  • daily: daily environment

  • local: local environment

No

prod

version

String

The version of the mini program.

No

-

user

Object

User configuration. The user.id is generated by the SDK by default.

No

-

collectors

Object

Configuration for each Collector.

No

-

beforeReport

Function

The function that is called before reporting data to modify or block the reported data.

No

-

reportConfig

Object

The reporting configuration. For more information, see reportConfig configuration.

No

{

flushTime: 3000,

maxEventCount: 20

}

sessionConfig

Object

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

No

-

longTaskConfig

Object

Configuration for the maximum number of stuttering reports and the time threshold for determining a stutter. For more information, see longTaskConfig configuration.

No

{

maxEventCount: 5,

renderThreshold: 50

}

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

-

remoteConfig

object

Dynamic configuration. For more information, see Dynamic configuration.

No

-

User configuration

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

-

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.

Example

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.

Unit: milliseconds (ms).

No

3000

maxEventCount

Number

The maximum number of data entries reported at a time.

Valid values: 1 to 100.

No

20

Example

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 configuration

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

longTaskConfig configuration

Parameter

Type

Description

Required

Default value

maxEventCount

Number

The maximum number of times stuttering data can be reported for a single page view (PV).

Valid values: [1, 5].

No

5

renderThreshold

Number

The time threshold for determining a setData stutter. The minimum value is 50. Unit: milliseconds.

No

50

Example

ArmsRum.init({
  pid: "your app id",
  endpoint: "your endpoint",
  longTaskConfig: {
    maxEventCount: 4, // Report stuttering data up to 4 times within a single PV.
    renderThreshold: 100, // A setData operation that takes more than 100 milliseconds is considered a stutter.
  },
});

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

longTask

Boolean | Object

Listens for page stuttering.

No

true

Example

Shut down the listener for the user Click behavior.

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: Succeeded.

  • 0: Failed

  • -1: Unknown

No

duration

Number

Total API response time.

No

status_code

Number | String

The status code.

No

snapshots

String

API 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[]

Filters the collected resource events, including static resources and APIs (XMLHttpRequest/fetch).

No

exception

MatchOption | MatchOption[]

You can filter the collected anomalous events.

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: Tests a URL against a specified regular expression.

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

Dynamic configuration

RUM supports dynamic delivery of data collection and reporting configurations for the SDK. The SDK dynamically loads these configurations when the application starts. These configurations then overwrite the static configurations set during SDK initialization on an item-by-item basis. This feature is implemented in two parts: the console and the SDK.

Console configuration

First, you must configure the settings in the console. Navigate to Application Settings > SDK Configuration. After you complete and test the configuration, click Confirm and Update Dynamic Configuration. This pushes the configuration to a remote OSS endpoint for storage.

SDK configuration

To support dynamic configuration delivery, add the remoteConfig field to the SDK initialization configuration. During initialization, the SDK uses this field to retrieve the remote configuration from OSS and updates features, such as probes and reporting, based on the retrieved configuration.

import ArmsRum from '@arms/rum-miniapp';

ArmsRum.init({
  pid: "your app id",
  endpoint: "your endpoint",
  remoteConfig: {
    // The region where the web application is located, for example, ap-southeast-1 for Singapore.
    region: "cn-hangzhou"
  }
});

After the SDK retrieves the remote configuration, it immediately updates the features and stores the configuration in the local cache. This allows the SDK to prioritize the locally cached configuration during the next initialization.

Note that the SDK version must be 0.0.37 or later.

Other configurations

RUM SDK lets you 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

Administrative Areas

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 modify the SDK configuration.

// 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

type

String

The type.

Yes

name

String

The name.

Yes

group

String

The group.

No

value

Number

The value.

No

properties

object

Custom properties.

No

ArmsRum.sendCustom({
  // Required
  type: 'CustomEvnetType1',
  name: 'customEventName2',
  // Optional
  group: 'customEventGroup3',
  value: 111.11,
  properties: {
    prop_msg: 'custom msg',
    prop_num: 1,
  },
});

sendException

To report custom exception data, you must specify the name and message parameters.

Parameter

Type

Description

Required

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

properties

object

Custom properties.

No

ArmsRUM.sendException({
  // Required
  name: 'customErrorName',
  message: 'custom error message',
  // Optional
  file: 'custom exception filename',
  stack: 'custom exception error.stack',
  line: 1,
  column: 2,
  properties: {
    prop_msg: 'custom msg',
    prop_num: 1,
  },
});

sendResource

To report custom resource data, you must specify the name, type, and duration parameters.

Parameter

Type

Description

Required

name

String

The resource name.

Yes

type

String

The resource type, for example, script, api, image, or other.

Yes

duration

String

The time consumed by the request.

Yes

success

Number

Indicates whether the request was successful:

  • 1: Success

  • 0: failed

  • -1: Unknown

No

method

String

The request method.

No

status_code

Number | String

The request status code.

No

message

String

The request message.

No

url

String

The request address.

No

trace_id

String

The trace ID.

No

properties

object

Custom properties.

No

ArmsRum.sendResource({

  // The following are required.
  name: 'getListByPage',
  message: 'success',
  duration: 800,
  // The following are optional.
  url: 'https://www.aliyun.com/data/getListByPage',
  properties: {
    prop_msg: 'custom msg',
    prop_num: 1,
  },
});