All Products
Search
Document Center

Application Real-Time Monitoring Service:Integrate a mini program

Last Updated:Aug 12, 2024

The Real User Monitoring (RUM) sub-service of Application Real-Time Monitoring Service (ARMS) allows you to monitor mini programs deployed in mainstream apps, such as Alipay, WeChat, DingTalk, QQ, Douyin, Baidu, and JD.com, and compile mini programs across frameworks such as Taro and uni-app. You can integrate npm packages to collect runtime performance metrics, track exceptions, and improve the user experience of your mini program.

Important

RUM has been available for commercial use since 00:00:00 (UTC +8) on June 24, 2024. For more information, see Billing. To obtain technical support, join the DingTalk group chat (ID: 67370002064).

Procedure

  1. Log on to the ARMS console.
  2. In the left-side navigation pane, choose User Experience Monitoring > Application List. In the top navigation bar, select a region.

  3. On the Applications page, click Add Application.

  4. In the Create Application panel, click Mini Program.

  5. In the Mini Program panel, enter the name and description of the mini program, and click Create.

    Note

    The name must be unique.

    Then, an address to which monitoring data is reported (endpoint) and a mini program ID (pid) are automatically generated for the app.

  6. Initialize the OpenRUM SDK.

    To initialize the OpenRUM SDK, use a npm package.

    1. Introduce the npm package.

      npm install @arms/rum-miniapp
    2. Initialize the SDK.

      Note

      Replace the pid and endpoint parameters in the following code with the address and mini program ID obtained from the ARMS console.

      import ArmsRum from '@arms/rum-miniapp';
      ArmsRum.init({
        pid: "your app id",
        endpoint: "your endpint"
      });
  7. Configure the address.

    Add the address to the domain name whitelist of the server.

    Sample address: https://aokcd*****-default-cn.rum.aliyuncs.com

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:

  • 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 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 EvaluateApi parameters 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

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 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 /list/123, the name field is displayed as /list/$id.

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.

  • 1: The request is successful.

  • 0: The request failed.

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

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.

  • 1: The request is successful.

  • 0: The request failed.

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

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