Description
Describe your environment
python: 3.10.6
opentelemetry-api: 1.12.0
opentelemetry-sdk: 1.12.0
Steps to reproduce
from opentelemetry.baggage import _is_valid_pair
_is_valid_pair("sentry-transaction", "GET%20%2Fapi%2F%2Freport") # OK
from opentelemetry.baggage.propagation import W3CBaggagePropagator
W3CBaggagePropagator().extract({"baggage": "sentry-transaction=GET%20%2Fapi%2Freport"})
# Returns empty and raises warning Invalid baggage entry: `sentry-transaction=GET%20%2Fapi%2Freport`
What is the expected behavior?
Opentelemetry should be able to parse baggage values which are percent encoded, as that's indicated by the W3C spec
A value contains a string whose character encoding MUST be UTF-8 [Encoding]. Any characters outside of the baggage-octet range of characters MUST be percent-encoded. Characters which are not required to be percent-encoded MAY be percent-encoded.
What is the actual behavior?
No baggage values were extracted and the following warning was raised:
Invalid baggage entry: `sentry-transaction=GET%20%2Fapi%2Freport`
Additional context
The problem is happening here:
Note also that the indicated code path seems to be not be too optimized, as the call to set_baggage
will validate both the key and values again. And additionally, for each baggage value a new context will be created. Maybe it'd be better to first collect all baggage values and set them only once in the context.