open-telemetry / open-telemetry/opentelemetry-python-contrib
Add request and response hooks to web framework instrumentations
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 1.1k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 16
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file, test, or specific instrumentation entry point is identified. Start by surveying the existing client and server web-framework instrumentations and their span lifecycle, then compare how hooks could be applied consistently. Done means the supported instrumentations expose documented request and response hook behavior at the stated lifecycle points.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- observability-sre
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100