Mini Program Application Access¶
By introducing the SDK files, collect the performance metrics, error logs, and resource request data of mini program applications, and report them to the Guance platform to visually analyze the performance of mini program applications.
Prerequisites (DataKit Access)¶
- Install DataKit;
- Configure RUM Collector;
- Configure DataKit to be publicly accessible, and install the IP geolocation database.
Getting Started with Access¶
- Go to User Access Monitoring > Create Application > Mini Program;
- Enter the application name;
- Enter the application ID;
-
Select the application access method:
-
Public DataWay: Directly receives RUM data, no need to install the DataKit collector.
- Local Deployment: Receives RUM data after meeting the prerequisites.
Access Methods¶
- Ensure DataKit is installed and configured to be publicly accessible, and install the IP geolocation database;
- Obtain parameters such as
applicationId,env,versionfrom the console, and start accessing the application; - When integrating the SDK, set
datakitOriginto the domain or IP of DataKit.
- Obtain parameters such as
applicationId,clientToken, andsitefrom the console, and start accessing the application; - When integrating the SDK, there is no need to configure
datakitOrigin, the data will be sent to the public DataWay by default.
Usage¶
Import the code in the app.js file of the mini program as follows:
Note: The import location must be before the App() initialization.
For the NPM package import method, refer to the official WeChat npm import method
const { datafluxRum } = require('@cloudcare/rum-miniapp')
// Initialize Rum
datafluxRum.init({
datakitOrigin: '<DATAKIT ORIGIN>',// Required, DataKit domain address. Need to add the domain to the whitelist in the WeChat mini program management backend.
site: "http://172.16.212.186:9529", // The domain of the site corresponding to the public DataWay
clientToken: "a993f53a8ea04bc6b9350e5e670a3a3b", // The client token required for reporting via the public DataWay, generated when creating an application in the Guance console.
applicationId: '<Application ID>', // Required, the application ID generated by the dataflux platform
env: 'testing', // Optional, the environment of the mini program
version: '1.0.0', // Optional, the version of the mini program
service: 'miniapp', // The service name of the current application
trackInteractions: true,
traceType: 'ddtrace', // Optional, default is ddtrace. Currently supports 6 types: ddtrace, zipkin, skywalking_v3, jaeger, zipkin_single_header, w3c_traceparent
allowedTracingOrigins: ['https://api.example.com',/https:\/\/.*\.my-api-domain\.com/], // Optional, a list of all requests allowed to inject the header required by the trace collector. Can be the origin of the request or a regular expression.
})
Download the file and import it locally
const { datafluxRum } = require('./lib/dataflux-rum-miniapp.js')
// Initialize Rum
datafluxRum.init({
datakitOrigin: '<DATAKIT ORIGIN>',// Required, DataKit domain address. Need to add the domain to the whitelist in the WeChat mini program management backend.
site: "http://172.16.212.186:9529", // The domain of the site corresponding to the public DataWay
clientToken: "a993f53a8ea04bc6b9350e5e670a3a3b", // The client token required for reporting via the public DataWay, generated when creating an application in the Guance console.
applicationId: '<Application ID>', // Required, the application ID generated by the dataflux platform
env: 'testing', // Optional, the environment of the mini program
version: '1.0.0', // Optional, the version of the mini program
service: 'miniapp', // The service name of the current application
trackInteractions: true,
traceType: 'ddtrace', // Optional, default is ddtrace. Currently supports 6 types: ddtrace, zipkin, skywalking_v3, jaeger, zipkin_single_header, w3c_traceparent
allowedTracingOrigins: ['https://api.example.com',/https:\/\/.*\.my-api-domain\.com/], // Optional, a list of all requests allowed to inject the header required by the trace collector. Can be the origin of the request or a regular expression.
})
Configuration¶
Initialization Parameters¶
| Parameter | Type | Required | Default Value | Description |
|---|---|---|---|---|
applicationId |
String | Yes | The application ID created from Guance. | |
datakitOrigin |
String | Yes | DataKit data reporting Origin; ❗️ Need to add the request whitelist in the mini program management backend. |
|
site |
String | Yes (Required for public dataway reporting method) |
The domain of the site corresponding to the public DataWay. Note: Protocol (including ://), domain (or IP address) [and port number] For example: https://www.dataway.com, http://100.20.34.3:8088 |
|
clientToken |
String | Yes (Required for public dataway) |
The client token required for reporting via the public DataWay, generated when creating an application in the Guance console. | |
env |
String | No | The current environment of the mini program application, such as prod: production environment; gray: canary environment; pre: pre-release environment; common: daily environment; local: local environment. | |
version |
String | No | The version number of the mini program application. | |
service |
String | No | The service name of the current application, defaults to miniapp, supports custom configuration. |
|
sampleRate |
Number | No | 100 |
The percentage of metric data collection: 100 means collect all, 0 means collect nothing. |
sessionSampleRate |
Number | No | 100 |
A compatible alias for sampleRate. When both are set, sampleRate takes precedence. |
remoteConfiguration |
Boolean | No | false |
Whether to enable remote configuration. The SDK will start with the local configuration first, then asynchronously pull and apply the supported configuration items. |
remoteConfigration |
Boolean | No | false |
A legacy spelling compatibility item for remoteConfiguration, not recommended for new projects. |
remoteConfigurationFetchTimeout |
Number | No | 3000 |
The timeout for remote configuration requests, in milliseconds. If the request fails or times out, the local configuration will continue to be used. |
trackInteractions |
Boolean | No | false |
Whether to enable user behavior collection. |
trackResourceQueryString |
Boolean | No | false |
Whether to collect the query string of the request URL. The query string may contain tokens or user IDs, enable only after confirming security. |
trackRequestErrorResponseBody |
Boolean | No | false |
Whether to write the response body of failed requests into the error stack. The response body may contain sensitive data. |
requestErrorResponseLengthLimit |
Number | No | 32768 |
The maximum number of characters allowed for the failed request response body to be written into the error stack, only effective when trackRequestErrorResponseBody is enabled. |
trackLaunchOptions |
Boolean | No | false |
Whether to collect the query and referrerInfo from the mini program launch parameters. |
beforeSend |
Function | No | A callback before the data enters the send queue, can modify the event; returning false can discard non-View events. Exceptions in the callback will not interrupt the business or SDK. |
|
userId / user_id |
String | No | Set the logged-in user ID during initialization; can also be set by calling setUser({ id }) after initialization. |
|
traceType |
Enum | No | ddtrace |
Configure the type of trace tool. If not configured, the default is ddtrace. Currently supports 6 data types: ddtrace, zipkin, skywalking_v3, jaeger, zipkin_single_header, w3c_traceparent.❗️ 1. opentelemetry supports zipkin_single_header, w3c_traceparent, zipkin, jaeger 4 types.2. Configuring the corresponding traceType requires setting different Access-Control-Allow-Headers for the corresponding API services. Refer to How APM Relates to RUM. |
traceId128Bit |
Boolean | No | false |
Whether to generate traceID in 128-bit format, corresponding to traceType. Currently supports types: zipkin, jaeger. |
allowedTracingOrigins |
Array | No | [] |
[New] A list of all requests allowed to inject the header required by the ddtrace collector. Can be the origin of the request or a regular expression. Origin: Protocol (including ://), domain (or IP address) [and port number]. _For example: ["https://api.example.com", /https:\\/\\/._\\.my-api-domain\\.com/]* |
isIntakeUrl |
Function | No | function(url) {return false} |
Custom method to determine whether to collect resource data for a given request resource URL. Default is to collect all. Returns: false means collect, true means do not collect.❗️ 1. The return value of this parameter method must be of Boolean type, otherwise it is considered invalid. 2. Version requirement is 2.1.10 or above. |
Notes¶
- The DataKit domain corresponding to
datakitOriginmust be added to the request whitelist in the mini program management backend. - Due to the fact that the current WeChat mini program resource request APIs
wx.requestandwx.downloadFiledo not return theprofilefield on iOS systems, the collected resource information will be missing timing-related data. There is currently no solution: request, downloadFile, API Support Status. - When
trackInteractionsuser behavior collection is enabled, due to the limitations of WeChat mini programs, the content and structure data of controls cannot be collected. Therefore, in the mini program SDK, we adopt a declarative programming approach by setting thedata-nameattribute in the wxml file to add names to interactive elements, making it easier to locate operation records during subsequent statistics. For example: