Mini Program Log Collection¶
Mini programs actively send log data of different levels (corresponding to source:browser_log metric type log data) to Guance.
Feature Introduction¶
- Custom log data collection, integrated into client applications via SDK, collecting different log data for different scenarios.
- Automatically collects error information from the application end (including network errors, console errors, and JS errors) and reports them to DataFlux.
- Custom error levels (
debug,critical,error,info,warn), custom Logger objects, and custom Log fields. - Automatically collects RUM related data, correlating with RUM business scenarios (requires rum and SDK to be updated to the latest version).
Getting Started¶
Prerequisites¶
- Introduce SDK: The SDK can be introduced into the application via
NPMorCDN. After initialization, it can be stored in global variables for easy reference by other pages. - Support for Mini Program Clients: WeChat, Baidu, Alipay, Toutiao, and most other mini program clients.
Integration Methods¶
- Ensure DataKit is installed and configured for public network access, and install the IP geolocation database.
- Obtain parameters such as
applicationId,env,versionfrom the console, and start integrating the application. - When integrating the SDK, set
datakitOriginto the domain name or IP of DataKit.
- Obtain parameters such as
applicationId,clientToken, andsitefrom the console, and start integrating the application. - When integrating the SDK, there is no need to configure
datakitOrigin. Data will be sent to the public network DataWay by default.
NPM Import¶
//#ifndef H5 || APP-PLUS || APP-NVUE || APP-PLUS-NVUE
const { datafluxLogs } = require('@cloudcare/dataflux-rum-miniapp-logs')
// Initialize Rum
datafluxLogs.init({
datakitOrigin: '<DATAKIT ORIGIN>'
site: "http://172.16.212.186:9529", // Domain name of the site corresponding to the public DataWay
clientToken: "a993f53a8ea04bc6b9350e5e670a3a3b", // Client token required for reporting to the public DataWay
service: 'minapp',
env: 'prod',
version: '1.0.0'
})
//#endif
CDN Download File Local Import (Download Link)¶
//#ifndef H5 || APP-PLUS || APP-NVUE || APP-PLUS-NVUE
const { datafluxLogs } = require('@cloudcare/dataflux-rum-miniapp-logs')
// Initialize Rum
datafluxLogs.init({
datakitOrigin: '<DATAKIT ORIGIN>'
service: 'miniapp',
env: 'prod',
version: '1.0.0'
})
//#endif
Configuration¶
Initialization Parameters¶
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
datakitOrigin |
String | Yes | DataKit data reporting Origin Note: Protocol (including ://), domain name (or IP address) [and port number]Example: https://www.datakit.com, http://100.20.34.3:8088 |
|
clientToken |
String | Yes | Token for reporting data via openway, obtained from the Guance console, required (for public openway integration). | |
site |
String | Yes | Address for reporting data via public openway, obtained from the Guance console, required (for public openway integration). | |
service |
String | No | browser |
Log Service name |
env |
String | No | Current environment of the Web application, e.g., Prod: production environment; Gray: grayscale environment; Pre: pre-release environment; Common: daily environment; Local: local environment. | |
version |
String | No | Version number of the Web application | |
sampleRate |
Number | No | 100 |
Percentage of metric data collection: 100 means full collection, 0 means no collection |
forwardErrorsToLogs |
Boolean | No | true |
Set to false to stop collecting console.error, JS, and network errors for reporting to DataFlux log data |
Usage¶
After the SDK is initialized in the application, the exposed SDK API can be used to customize log data configuration.
NPM¶
import { datafluxLogs } from "@cloudcare/dataflux-rum-miniapp-logs"
datafluxLogs.logger.info("Button clicked", { name: "buttonName", id: 123 })
Return Data Structure¶
{
"service": "miniapp",
"session": {
"id": "c549c2b8-4955-4f74-b7f8-a5f42fc6e79b"
},
"type": "logger",
"_dd": {
"sdk_name": "miniapp LOG SDK",
"sdk_version": "1.0.0",
"env": "",
"version": ""
},
"device": {
"platform_version": "8.0.5",
"model": "iPhone 6/7/8 Plus",
"app_framework_version": "2.23.3",
"os": "OS",
"os_version": "10.14.6",
"os_version_major": "10",
"screen_size": "414*736",
"network_type": "3g",
"divice": "devtools"
},
"user": {},
"date": 1621321916756,
"view": {
"referrer": "",
"name": "pages/index/index",
"id": "5dce64f4-8d6d-411a-af84-c41653ccd94a"
},
"application": {
"id": "app_idxxxxxx"
},
"message": "XHR error get http://testing-ft2x-api.cloudcare.cn/api/v1/workspace/xxx",
"status": "error",
"error": {
"source": "network",
"stack": "Failed to load"
},
"resource": {
"method": "get",
"status": 0,
"status_group": 0,
"url": "http://testing-ft2x-api.cloudcare.cn/api/v1/workspace/xxx",
"url_host": "testing-ft2x-api.cloudcare.cn",
"url_path": "/api/v1/workspace/xxx",
"url_path_group": "/api/?/workspace/xxx"
}
}
Status Parameter¶
After initializing the SDK, the provided log API can be used to define different types of statuses.
log (message: string, messageContext: Context, status? = 'debug' | 'info' | 'warning' | 'error' | 'critical')
Usage¶
import { datafluxLogs } from '@cloudcare/dataflux-rum-miniapp-logs'
datafluxLogs.logger.log(<MESSAGE>,<JSON_ATTRIBUTES>,<STATUS>);
Parameter Description¶
| Parameter | Description |
|---|---|
<MESSAGE> |
The Message field in Dataflux logs. |
<JSON_ATTRIBUTES> |
Additional data describing the Message, in JSON object format. |
<STATUS> |
Log level, optional values: debug, info, warning, error, critical. |