From 4286d63d6f9cd0acbf6fbe3fd35163cec79d7ade Mon Sep 17 00:00:00 2001 From: Mark Jan van Kampen Date: Thu, 2 Feb 2023 19:30:30 +0100 Subject: [PATCH] Fix bagage key lowercasing (#3151) --- CHANGELOG.md | 2 + .../baggage/propagation/__init__.py | 2 +- .../baggage/propagation/test_propagation.py | 39 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 opentelemetry-api/tests/baggage/propagation/test_propagation.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 28650a4b3f3..bb1666d1854 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3128](https://github.com/open-telemetry/opentelemetry-python/pull/3128)) - Fix validation of baggage values ([#3058](https://github.com/open-telemetry/opentelemetry-python/pull/3058)) +- Fix capitalization of baggage keys + ([#3151](https://github.com/open-telemetry/opentelemetry-python/pull/3151)) ## Version 1.15.0/0.36b0 (2022-12-09) diff --git a/opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py b/opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py index ecdc1eab43d..91898d53ae3 100644 --- a/opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py +++ b/opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py @@ -93,7 +93,7 @@ def extract( _logger.warning("Invalid baggage entry: `%s`", entry) continue - name = unquote_plus(name).strip().lower() + name = unquote_plus(name).strip() value = unquote_plus(value).strip() context = set_baggage( diff --git a/opentelemetry-api/tests/baggage/propagation/test_propagation.py b/opentelemetry-api/tests/baggage/propagation/test_propagation.py new file mode 100644 index 00000000000..b9de7f37b30 --- /dev/null +++ b/opentelemetry-api/tests/baggage/propagation/test_propagation.py @@ -0,0 +1,39 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# type: ignore + +from unittest import TestCase + +from opentelemetry.baggage import get_baggage, set_baggage +from opentelemetry.baggage.propagation import W3CBaggagePropagator + + +class TestBaggageManager(TestCase): + def test_propagate_baggage(self): + carrier = {} + propagator = W3CBaggagePropagator() + + ctx = set_baggage("Test1", "value1") + ctx = set_baggage("test2", "value2", context=ctx) + + propagator.inject(carrier, ctx) + ctx_propagated = propagator.extract(carrier) + + self.assertEqual( + get_baggage("Test1", context=ctx_propagated), "value1" + ) + self.assertEqual( + get_baggage("test2", context=ctx_propagated), "value2" + )