diff --git a/CHANGELOG.md b/CHANGELOG.md index 5477ae7940d..587ca0a61b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#1854](https://github.com/open-telemetry/opentelemetry-python/pull/1854)) - Changed AttributeValue sequences to warn mypy users on adding None values to array ([#1855](https://github.com/open-telemetry/opentelemetry-python/pull/1855)) +- Fixed exporter OTLP header parsing to match baggage header formatting. + ([#1869](https://github.com/open-telemetry/opentelemetry-python/pull/1869)) ## [1.2.0, 0.21b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.2.0-0.21b0) - 2021-05-11 diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py index be58cd82586..7b9227fd07f 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py @@ -229,9 +229,20 @@ def __init__( self._headers = headers or environ.get(OTEL_EXPORTER_OTLP_HEADERS) if isinstance(self._headers, str): - self._headers = tuple( - tuple(item.split("=")) for item in self._headers.split(",") - ) + temp_headers = [] + for header_pair in self._headers.split(","): + key, value = header_pair.split("=", maxsplit=1) + key = key.strip().lower() + value = value.strip() + temp_headers.append( + ( + key, + value, + ) + ) + + self._headers = tuple(temp_headers) + self._timeout = timeout or int( environ.get(OTEL_EXPORTER_OTLP_TIMEOUT, 10) ) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py index 3f43f1a8ccc..521c9e6e827 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py @@ -180,7 +180,7 @@ def tearDown(self): OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: "collector:4317", OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE: THIS_DIR + "/fixtures/test.cert", - OTEL_EXPORTER_OTLP_TRACES_HEADERS: "key1=value1,key2=value2", + OTEL_EXPORTER_OTLP_TRACES_HEADERS: " key1=value1,KEY2 = value=2", OTEL_EXPORTER_OTLP_TRACES_TIMEOUT: "10", OTEL_EXPORTER_OTLP_TRACES_COMPRESSION: "gzip", }, @@ -195,7 +195,7 @@ def test_env_variables(self, mock_exporter_mixin): _, kwargs = mock_exporter_mixin.call_args_list[0] self.assertEqual(kwargs["endpoint"], "collector:4317") - self.assertEqual(kwargs["headers"], "key1=value1,key2=value2") + self.assertEqual(kwargs["headers"], " key1=value1,KEY2 = value=2") self.assertEqual(kwargs["timeout"], 10) self.assertEqual(kwargs["compression"], Compression.Gzip) self.assertIsNotNone(kwargs["credentials"]) @@ -217,7 +217,7 @@ def test_no_credentials_error( @patch.dict( "os.environ", - {OTEL_EXPORTER_OTLP_TRACES_HEADERS: "key1=value1,key2=value2"}, + {OTEL_EXPORTER_OTLP_TRACES_HEADERS: " key1=value1,KEY2 = VALUE=2 "}, ) @patch( "opentelemetry.exporter.otlp.proto.grpc.exporter.ssl_channel_credentials" @@ -228,7 +228,7 @@ def test_otlp_headers_from_env(self, mock_ssl_channel, mock_secure): exporter = OTLPSpanExporter() # pylint: disable=protected-access self.assertEqual( - exporter._headers, (("key1", "value1"), ("key2", "value2")) + exporter._headers, (("key1", "value1"), ("key2", "VALUE=2")) ) exporter = OTLPSpanExporter( headers=(("key3", "value3"), ("key4", "value4"))