Trace Configuration¶
Trace Initialization Configuration¶
| Property | Type | Required | Description |
|---|---|---|---|
| sampleRate | int | No | Sampling rate. Range [0,100], 0 means no collection, 100 means full collection, default value is 100 |
| networkTraceType | FTNetworkTraceType | No | Sets the type of trace. Default is DDTrace, currently supports Zipkin, Jaeger, DDTrace, Skywalking (8.0+), TraceParent (W3C). If integrating with OpenTelemetry, please refer to the supported types and agent configurations. |
| enableLinkRumData | BOOL | No | Whether to associate with RUM data. Default is NO |
| enableAutoTrace | BOOL | No | Sets whether to enable automatic HTTP trace. Default is NO, currently only supports NSURLSession |
| traceInterceptor | FTTraceInterceptor | No | Supports custom trace interception based on URLRequest. Returns TraceContext if intercepted, nil otherwise. Supported from SDK 1.5.10 and above. Priority is lower than URLSession Custom Collection |
Sampling Rate Parameter Name
In SDK 1.6.6 and above, samplerate is deprecated but still usable and maps to the same value as sampleRate. New code should use sampleRate; for versions below 1.6.6, continue using samplerate.
Trace Network Tracing¶
You can enable automatic mode through FTTraceConfig configuration, or you can manually add Trace-related data. The APIs for manual addition are as follows:
NSString *key = [[NSUUID UUID]UUIDString];
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
//Manual operation required: get traceHeader before request and add to request headers
NSDictionary *traceHeader = [[FTTraceManager sharedInstance] getTraceHeaderWithKey:key url:url];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
if (traceHeader && traceHeader.allKeys.count>0) {
[traceHeader enumerateKeysAndObjectsUsingBlock:^(id field, id value, BOOL * __unused stop) {
[request setValue:value forHTTPHeaderField:field];
}];
}
NSURLSession *session=[NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]];
NSURLSessionTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
//Your code
}];
[task resume];
let url:URL = NSURL.init(string: "https://www.baidu.com")! as URL
if let traceHeader = FTExternalDataManager.shared().getTraceHeader(withKey: NSUUID().uuidString, url: url) {
let request = NSMutableURLRequest(url: url)
//Manual operation required: get traceHeader before request and add to request headers
for (a,b) in traceHeader {
request.setValue(b as? String, forHTTPHeaderField: a as! String)
}
let task = URLSession.shared.dataTask(with: request as URLRequest) { data, response, error in
//Your code
}
task.resume()
}
URLSession Advanced Collection¶
If you need finer-grained Resource collection, Trace injection, and error filtering for a specific URLSession instance, please refer to URLSession Custom Network Collection.