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

AsgiSetter should override header values instead of appending

Open
#1,210 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe your environment

Using FastAPI 0.79 and relying on the AsgiSetter. The AsgiSetter has a surprising result to always append values instead of overriding previous keys.

https://github.com/open-telemetry/opentelemetry-python-contrib/blob/fbac4245159e51877efa86581724995bd1415a18/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py#L219-L240

Steps to reproduce

Call AsgiSetter().set() multiple times with the same header name.

What is the expected behavior?

The 2nd call with the same header appends to the previous header value.

What is the actual behavior?
The result will be multiple headers with the same name are added instead of a single header with multiple values.

Additional context

Originally added by me (😬 ) at https://github.com/open-telemetry/opentelemetry-python-contrib/pull/817. It's also not 100% clear what the right behavior should be. Need to investigate the ASGI spec and what happens with multiple tuples with the same header name.

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 instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/init.py around lines 219-240 and review the ASGI specification for repeated header names. Reproduce multiple AsgiSetter().set() calls with the same header name, then define the behavior that matches the specification and verify the implementation follows it.

Written by the indexing model from the issue text.

Assessment

Tech stack
fastapi, python
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.