open-telemetry / open-telemetry/opentelemetry-python-contrib

Starlette instrumentation can have ordering issues

Open
#3,476 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.1k
Forks
1.1k
Avg merge
4d 15h
Merged PRs (30d)
16

Description

Currently, starlette instrumentation uses a class override pattern which can have ordering issues that cause autoinstrumentation to not apply.

https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/__init__.py#L287

In practice, I see most users manually instrument the app because of this, for example here

https://github.com/YunosukeY/otel-and-a2a-sample/blob/main/server.py#L47

I think it should be possible to switch to wrapping the __init__ method without replacement which can usually solve such ordering issues.

/cc @xrmx was interested in this (I hope :) )

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/init.py around line 287 and inspect the current class override pattern. Compare it with the proposed approach of wrapping init without replacement, using the linked server.py example as context. Done means autoinstrumentation applies reliably despite ordering, reducing the need for manual instrumentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.