Skip to content

How to Configure RUM Sampling


Introduction

Guance supports collecting data from Web, Android, iOS, and Mini Program applications. By default, user access data is collected in full volume. You can configure sampling to collect user access data, saving data storage and reducing costs.

The following uses a Web application as an example to illustrate how to collect 90% of the Web application's user access data.

Sampling Configuration

Taking synchronous loading as an example, add sessionSampleRate: 90 to the code, then copy and paste it into the first line of the HTML of the page that needs to be integrated. This will collect Web application user access data at a 90% rate.

import { datafluxRum } from '@cloudcare/browser-rum';
datafluxRum.init({
    applicationId: '<Application ID>',
    datakitOrigin: '<DATAKIT ORIGIN>', // Protocol (including ://), domain name (or IP address) [and port number]
    env: 'production',
    version: '1.0.0',
    service: 'browser',
    sessionSampleRate: 100,
    sessionReplaySampleRate: 70,
    trackInteractions: true,
    traceType: 'ddtrace', // Optional, defaults to 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 headers required by the trace collector. Can be the request origin or a regular expression
})

Note: After setting the sampling rate, initialization will randomly generate a number between 0 and 100. If this random number is less than the sampling rate you set, the current user's access data will be reported; otherwise, it will not be reported.

NPM Integration and Asynchronous Loading can be configured using the same method. Please refer to the documentation Web Application Integration.

Sampling for Other Applications

Feedback

Is this page helpful? ×