Baggage is ignored by W3CBaggagePropagator and erronously causes warning 'Invalid baggage entry'
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- api, distributed-systems
Research direction
Start in opentelemetry-api/src/opentelemetry/baggage/propagation/init.py at W3CBaggagePropagator.extract(), then inspect how _is_valid_pair() is called and how the baggage value is decoded. Run the existing baggage propagation tests or the reproduction, and consider the issue done when whitespace around the equals sign is accepted without the warning and the baggage is returned.
Written by the indexing model from the issue text.
Description
Describe your environment
main branch and branch release/v1.44.x-0.65bx
What happened?
When calling an API method from C# that is instrumented via OpenTelemetry nuget packages, then baggage header values are sent as "name = value", i.e. with a space around the = sign.
This is valid, because according to https://www.w3.org/TR/baggage/ a baggage header property has the form: key OWS "=" OWS value, i.e. there can be optional whitespace around the = sign.
However, the Python instrumentation ignores the baggage and logs the warning "Invalid baggage entry".
Steps to Reproduce
import logging
from opentelemetry.baggage import get_all
from opentelemetry.baggage.propagation import W3CBaggagePropagator
logging.basicConfig(
level=logging.WARNING,
format="%(levelname)s:%(name)s:%(message)s",
)
propagator = W3CBaggagePropagator()
""" print warning and ignore baggage """
carrier = {"baggage": "some_name = some_value"}
context = propagator.extract(carrier)
print(dict(get_all(context)))
""" extract the baggage """
carrier = {"baggage": "some_name_no_space=some_value_no_space"}
context = propagator.extract(carrier)
print(dict(get_all(context)))
Expected Result
Whitespace around the = sign in a baggage header value should be accepted and ignored.
Actual Result
The baggage is ignored and the warning "Invalid baggage entry" is logged.
Additional context
In opentelemetry-api/src/opentelemetry/baggage/propagation/init.py in the extract() method of the W3CBaggagePropagator class, whitespace around the = sign leads to the warning "Invalid baggage entry" and the baggage is ignored.
This is because the property is first split by the = sign into name and value.
Then _is_valid_pair(name, value) fails, because of the trailing whitespace in name or the leading whitespace in value.
Only after this check strip() is applied.
The fix is to apply strip() also before calling _is_valid_pair().
It also should be called after unquote_plus(), because spaces could arise from it. But maybe those spaces are intentional and no strip() should be called.
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.
- Dominant language
- Python
- Stars
- 2.6k
- Forks
- 1k
- Avg merge
- 5d 29m
- Merged PRs (30d)
- 17
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.
More from open-telemetry/opentelemetry-python
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
open-telemetry/opentelemetry-python#5664 · 4 comments ·
-
bug tests
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
All issues in open-telemetry/opentelemetry-python
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100