open-telemetry / open-telemetry/opentelemetry-python-contrib
Add env variable for suppressing ASGI event spans from Starlette Instrumentor
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 1.1k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 16
Description
What problem do you want to solve?
The OpenTelemetry middleware that Starlette uses internally has a setting to suppress ASGI event spans like receive and send: https://github.com/open-telemetry/opentelemetry-python-contrib/blob/86d26ce1b8d24299bcc17a074744bbe19d812732/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py#L573.
However, the Starlette auto-instrumentation always emits those spans as it never sets that constructor value.:
https://github.com/open-telemetry/opentelemetry-python-contrib/blob/51da0a766e5d3cbc746189e10c9573163198cfcd/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/__init__.py#L246
https://github.com/open-telemetry/opentelemetry-python-contrib/blob/51da0a766e5d3cbc746189e10c9573163198cfcd/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/__init__.py#L322
While these spans are useful, they can sometimes create a lot of noise in the telemetry data.
Describe the solution you'd like
I'd like to propose adding an environment variable configuration: OTEL_PYTHON_STARLETTE_EXCLUDED_SPANS that lets users disable specific spans by passing them to the middleware. For example:
OTEL_PYTHON_STARLETTE_EXCLUDED_SPANS='receive,send'
This would allow users to filter out any ASGI event spans like receive and send if they're not needed.
Describe alternatives you've considered
N/A
Additional Context
N/A
Would you like to implement a fix?
None
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.
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 with the Starlette Instrumentor entry points in instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/init.py at the referenced middleware construction lines, then compare the ASGI middleware setting in instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/init.py. Add support for OTEL_PYTHON_STARLETTE_EXCLUDED_SPANS and verify that values such as receive,send suppress the corresponding ASGI event spans.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- observability-sre
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100