Skip to content

Trace Configuration

Trace Initialization Configuration

let traceConfig: FTTraceConfig = {
  traceSamplingRate: 100,
  enableNativeAutoTrace: true,
};
await FTReactNativeTrace.setConfig(traceConfig);
Field Type Required Description
traceSamplingRate number No Sampling percentage, range [0,100], decimal values supported, default 100. Takes precedence over sampleRate, including when explicitly set to 0. Supported since SDK 0.4.3.
sampleRate number No Deprecated since SDK 0.4.3, retained for compatibility. Range [0,1], default 1; takes effect only when traceSamplingRate is not set. Using traceSamplingRate is recommended.
traceType enum TraceType No Trace type, default TraceType.ddTrace. Supports TraceType.ddTrace, TraceType.zipkinMulti, TraceType.zipkinSingle, TraceType.traceparent, TraceType.skywalking, and TraceType.jaeger.
enableLinkRUMData boolean No Whether to associate with RUM data, default false.
enableNativeAutoTrace boolean No Whether to enable automatic native network tracing for iOS NSURLSession and Android OKhttp. React Native network requests are implemented using system APIs on iOS and Android; once enabled, React Native HTTP(S) requests can also be traced. For iOS WebSocket, FTRUMConfig.enableIOSWebSocketResource must also be enabled. See WebSocket Handshake Collection.

Fractional percentage sampling is supported starting from SDK 0.4.3. traceSamplingRate: 12.5 means 12.5%, 1 means 1%, and 100 means collect all. For migration rules, see Sampling Configuration.

Tracer Network Distributed Tracing

When initializing the SDK with Trace Configuration, you can enable automatic network distributed tracing. User-defined collection is also supported.

Usage

/**
 * Gets trace HTTP request header data.
 * @deprecated Use getTraceHeaderFields() instead.
 */
getTraceHeader(key: String, url: String): Promise<object>;

/**
 * Gets trace HTTP request header data.
 */
getTraceHeaderFields(url: String, key?: String): Promise<object>;

Usage 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);
}

```

Feedback

Is this page helpful?