Trace Configuration¶
Trace Initialization Configuration¶
let traceConfig: FTTraceConfig = {
enableNativeAutoTrace: true,
};
await FTReactNativeTrace.setConfig(traceConfig);
| Field | Type | Required | Description |
|---|---|---|---|
| sampleRate | number | No | Sampling rate, value range [0,1]. 0 means no collection, 1 means full collection. Default value is 1. |
| traceType | enum TraceType | No | Trace type, default is TraceType.ddTrace. Supports TraceType.ddTrace, TraceType.zipkinMulti, TraceType.zipkinSingle, TraceType.traceparent, TraceType.skywalking, TraceType.jaeger. |
| enableLinkRUMData | boolean | No | Whether to correlate with RUM data, default is false. |
| enableNativeAutoTrace | boolean | No | Whether to enable native network auto-tracing for iOS NSURLSession and Android OKhttp. Since React Native network requests are implemented using system APIs on iOS and Android, enabling this allows all React Native request data to be traced together. |
Tracer Network Trace¶
When initializing the SDK with Trace Configuration, automatic network tracing can be enabled. It also supports custom collection by users.
Usage¶
/**
* Get trace HTTP request header data.
* @deprecated use getTraceHeaderFields() replace.
*/
getTraceHeader(key: String, url: String): Promise<object>;
/**
* Get trace HTTP request header data.
*/
getTraceHeaderFields(url: String, key?: String): Promise<object>;
Example¶
import { FTReactNativeTrace } from '@cloudcare/react-native-mobile';
async function getHttp(url: string) {
const key = Utils.getUUID();
const traceHeader = await FTReactNativeTrace.getTraceHeaderFields(url);
const fetchOptions = {
method: 'GET',
headers: Object.assign(
{
Accept: 'application/json',
'Content-Type': 'application/json',
},
traceHeader,
),
};
fetch(url, fetchOptions);
}