onRequest method
Called when the request is about to be sent.
Implementation
@override
void onRequest(
dio.RequestOptions options, dio.RequestInterceptorHandler handler) {
// Monotonic clock: wall time can jump (NTP sync, timezone change) mid-request.
options.extra[_kStopwatchKey] = Stopwatch()..start();
final globalOptions = CxFlutterPlugin.globalOptions;
if (globalOptions != null &&
Utils.shouldAddTraceParent(options.uri.toString(), globalOptions)) {
final spanId = Utils.generateHex(16);
final traceId = Utils.resolveTraceId();
options.headers['traceparent'] = _generateTraceParent(traceId, spanId);
options.extra['_cx_trace_id'] = traceId;
options.extra['_cx_span_id'] = spanId;
}
handler.next(options);
}