Trace Configuration¶
Getting the Tracer¶
Standard uni-app:
uni-app mini-program:
For uni-app mini-programs, the host app completes Trace initialization. Only runtime APIs such as getTraceHeader() are called.
Trace Initialization Configuration¶
| Parameter | Type | Required | Description |
|---|---|---|---|
| sampleRate | number | No | Sampling rate, range [0,1], default 1 |
| traceType | string | No | Trace type: ddTrace (default), zipkinMultiHeader, zipkinSingleHeader, traceparent, skywalking, jaeger |
| enableLinkRUMData | boolean | No | Whether to link with RUM data, default false |
| enableAutoTrace | boolean | No | Whether to enable native network auto-tracing. iOS supports NSURLSession, Android supports OKhttp, default false; Android cloud packaging is not supported. Since uni-app initiates network requests through system APIs on iOS, enabling this will automatically trace those requests. In that case, disable manual Trace collection on the iOS side to avoid incorrect linkage between traces and RUM data |
Tracer Network Trace¶
Automatic Collection¶
After enabling gcResourceTracking, standard uni.request automatically obtains and merges the Trace Header, without replacing the request method. For details, see Resource Automatic Collection.
Manual Collection¶
const requestUrl = 'https://example.com/api';
const key = 'YOUR_REQUEST_ID';
const traceHeader = tracer.getTraceHeader({
key,
url: requestUrl
}) || {};
uni.request({
url: requestUrl,
header: traceHeader
});
API - getTraceHeader¶
Retrieves the Trace request header and adds it to the HTTP request header.
| Field | Type | Required | Description |
|---|---|---|---|
| url | string | Yes | Request URL |
| key | string | No | Request unique identifier; pass the same key when linking with a RUM Resource |
Return type: object | null. May return null if the host module is unavailable or the request does not satisfy the Trace configuration.