open-telemetry / open-telemetry/opentelemetry-python-contrib
User provided callbacks should have exceptions checked
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 1.1k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 16
Description
When updating httpx instrumentation, I found there was a (likely unintended) breaking change.
https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2020#discussion_r1505190185
I found it because my app broke when it crashed on trying to read url.host in a request hook. AFAIK, this is incompliant with the spec which expects instrumentation to never cause app crashes, even in the face of broken user callbacks. Probably any user callback needs to be wrapped in a exception handler that optionally logs the error without failing completely.
The code that crashed, looks like
async def _httpx_span_name_hook(span: Span, request: RequestInfo):
span.update_name(f"{request.method.decode()} {request.url.host}")
def _httpx_span_name_hook_sync(span: Span, request: RequestInfo):
span.update_name(f"{request.method.decode()} {request.url.host}")
HTTPXClientInstrumentor().instrument(
async_request_hook=_httpx_span_name_hook,
request_hook=_httpx_span_name_hook_sync,
)
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
Start at HTTPXClientInstrumentor.instrument and the request_hook and async_request_hook call sites, then compare their behavior with the linked OpenTelemetry error-handling specification. Done means exceptions from user-provided callbacks no longer propagate into the application, with the intended logging behavior covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- observability-sre
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100