Trace Configuration¶
Trace Initialization Configuration¶
| Property | Type | Required | Description |
|---|---|---|---|
| samplerate | int | No | Sampling rate. Value range [0,100], 0 means no collection, 100 means full collection, default value is 100 |
| networkTraceType | FTNetworkTraceType | No | Sets the type of link tracing. Default is DDTrace, currently supports Zipkin, Jaeger, DDTrace, Skywalking (8.0+), TraceParent (W3C). If integrating OpenTelemetry and selecting the corresponding link type, please refer to the supported types and agent-related configurations |
| enableLinkRumData | BOOL | No | Whether to associate with RUM data. Default NO |
| enableAutoTrace | BOOL | No | Sets whether to enable automatic HTTP trace. Default NO, currently only supports NSURLSession |
| traceInterceptor | FTTraceInterceptor | No | Supports custom link tracing judgment via URLRequest, returns TraceContext if interception is confirmed, returns nil if not intercepted. SDK version 1.5.10 and above supports this parameter. Priority is lower than URLSession Custom Collection |
Trace Network Link Tracing¶
Automatic mode can be enabled via FTTraceConfig configuration, and custom addition of Trace-related data is also supported. The relevant APIs for custom addition are as follows:
NSString *key = [[NSUUID UUID]UUIDString];
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
//Manual operation required: Obtain traceHeader before request and add it 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: Obtain traceHeader before request and add it 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¶
For more granular Resource collection, Trace injection, and error filtering for a specific URLSession instance, please refer to URLSession Custom Network Collection.