onRequest method
Called when the request is about to be sent.
Implementation
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
assert(() {
final context = CausalityZone.currentContext();
final event = CausalEvent(
parentId: context?.eventId,
type: CausalEventType.networkEvent,
description: 'HTTP ${options.method} ${options.uri.path}',
metadata: {
'method': options.method,
'url': options.uri.toString(),
'path': options.uri.path,
'phase': 'request',
'has_body': options.data != null,
'content_type': options.contentType ?? 'unknown',
},
);
TrinityEventBus.instance.emit(event);
// Store the event ID in options.extra so we can link the response
options.extra['_trinity_event_id'] = event.id;
return true;
}());
handler.next(options);
}