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

Add env variable for suppressing ASGI event spans from Starlette Instrumentor

Open
#3,725 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.