From 99889c38b8067da41e09b795e27a1d90c0f8a22b Mon Sep 17 00:00:00 2001 From: Mark Jan van Kampen Date: Tue, 31 Jan 2023 11:00:19 +0100 Subject: [PATCH 1/5] Adds failing test --- .../baggage/propagation/test_propagation.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 opentelemetry-api/tests/baggage/propagation/test_propagation.py 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..2faddf40417 --- /dev/null +++ b/opentelemetry-api/tests/baggage/propagation/test_propagation.py @@ -0,0 +1,33 @@ +# 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. + +from opentelemetry.baggage import ( + get_baggage, + set_baggage, +) +from opentelemetry.baggage.propagation import W3CBaggagePropagator +from unittest import TestCase + + +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") From 0dba185c29253d73aba77e3c6db3f31376722dc8 Mon Sep 17 00:00:00 2001 From: Mark Jan van Kampen Date: Tue, 31 Jan 2023 11:00:33 +0100 Subject: [PATCH 2/5] Fixes failing test --- .../src/opentelemetry/baggage/propagation/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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( From 50a14942e071900a08254dcd22cc60362e98b6f8 Mon Sep 17 00:00:00 2001 From: Mark Jan van Kampen Date: Tue, 31 Jan 2023 12:59:33 +0100 Subject: [PATCH 3/5] Fixes formatting --- .../baggage/propagation/test_propagation.py | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/opentelemetry-api/tests/baggage/propagation/test_propagation.py b/opentelemetry-api/tests/baggage/propagation/test_propagation.py index 2faddf40417..8eb1c4b8c5a 100644 --- a/opentelemetry-api/tests/baggage/propagation/test_propagation.py +++ b/opentelemetry-api/tests/baggage/propagation/test_propagation.py @@ -12,22 +12,26 @@ # See the License for the specific language governing permissions and # limitations under the License. -from opentelemetry.baggage import ( - get_baggage, - set_baggage, -) -from opentelemetry.baggage.propagation import W3CBaggagePropagator 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) + 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") + + self.assertEqual( + get_baggage("Test1", context=ctx_propagated), "value1" + ) + self.assertEqual( + get_baggage("test2", context=ctx_propagated), "value2" + ) From 189e6ccfb7b380ac0ab7a3ae918b44128ec973b6 Mon Sep 17 00:00:00 2001 From: Mark Jan van Kampen Date: Tue, 31 Jan 2023 13:12:20 +0100 Subject: [PATCH 4/5] Updates changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bb6b0c7016..324dcbb72d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,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) From e35033423e28088915513314bbcacc9402e372b0 Mon Sep 17 00:00:00 2001 From: Mark Jan van Kampen Date: Thu, 2 Feb 2023 10:36:57 +0100 Subject: [PATCH 5/5] Adds typeignore to test --- opentelemetry-api/tests/baggage/propagation/test_propagation.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/opentelemetry-api/tests/baggage/propagation/test_propagation.py b/opentelemetry-api/tests/baggage/propagation/test_propagation.py index 8eb1c4b8c5a..b9de7f37b30 100644 --- a/opentelemetry-api/tests/baggage/propagation/test_propagation.py +++ b/opentelemetry-api/tests/baggage/propagation/test_propagation.py @@ -11,6 +11,8 @@ # 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