It'd be really nice for all web server instrumentations to provide request and response hooks so users can customize behavior (update span name, attributes, etc), record additional information from incoming/outgoing requests/responses, allow injecting tracing related data into responses such as trace response headers, etc. This should be implemented for both client and server libraries.
In order to be consistent across all instrumentations, I recommend all instrumentations follow the following guidelines:
- When possible the hook signatures should satisfy:
request_hook(span: trace.Span, request: RequestObject) -> None
response_hook(span: trace.Span, request: RequestObject, response: ResponseObject): -> None
- If it is not possible to pass a reference to the request object to the response hook, only span and response should be passed. Instrumentation should not go out of it's way to satisfy the above proposed interface by holding on to request references, etc.
- The request hook should be called right after the span is created for an incoming/outgoing request.
- The response hook should be called right before span ends.
It'd be really nice for all web server instrumentations to provide request and response hooks so users can customize behavior (update span name, attributes, etc), record additional information from incoming/outgoing requests/responses, allow injecting tracing related data into responses such as trace response headers, etc. This should be implemented for both client and server libraries.
In order to be consistent across all instrumentations, I recommend all instrumentations follow the following guidelines: