onRequest method

  1. @override
void onRequest(
  1. RequestOptions options,
  2. RequestInterceptorHandler handler
)

Called when the request is about to be sent.

Implementation

@override
void onRequest(
    dio.RequestOptions options, dio.RequestInterceptorHandler handler) {
  options.extra[_kStartTimeKey] = DateTime.now().millisecondsSinceEpoch;

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