From 85af83e645540b51e8a41e47c141f2367dd91b0d Mon Sep 17 00:00:00 2001 From: Edward Lin Date: Fri, 14 May 2021 14:31:42 -0400 Subject: [PATCH 01/11] Update OTLP header parsing in exporter --- .../src/opentelemetry/exporter/otlp/proto/grpc/exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f48a473fd00..dd0d30290fd 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 @@ -230,7 +230,7 @@ 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(",") + tuple(subitem.strip() for subitem in item.split("=", maxsplit=1)) for item in self._headers.split(",") ) self._timeout = timeout or int( environ.get(OTEL_EXPORTER_OTLP_TIMEOUT, 10) From 01eb50cb83930ca740a3b7dd9ce78e881eeb8bf2 Mon Sep 17 00:00:00 2001 From: Edward Lin Date: Fri, 14 May 2021 14:31:59 -0400 Subject: [PATCH 02/11] Update CHANGELOG.md --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16610f70b16..8130b493fa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,7 +36,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#1809])(https://github.com/open-telemetry/opentelemetry-python/pull/1809) - Fixed sequence values in OTLP exporter not translating ([#1818](https://github.com/open-telemetry/opentelemetry-python/pull/1818)) - +- Update otel exporter OTLP header parsing to match spec + (TBD) + ### Removed - Moved `opentelemetry-instrumentation` to contrib repository. ([#1797](https://github.com/open-telemetry/opentelemetry-python/pull/1797)) From d421626b6e766a53f036b31255790a965cd2cb58 Mon Sep 17 00:00:00 2001 From: Eddy Lin Date: Tue, 18 May 2021 12:12:57 -0400 Subject: [PATCH 03/11] Updated exporter otlp header parsing - Edited unit tests to test that uppercase keys become lowercase and keys/values are trimmed of optional white spaces (OWS) --- .../exporter/otlp/proto/grpc/exporter.py | 12 +++++++++--- .../tests/test_otlp_trace_exporter.py | 8 ++++---- 2 files changed, 13 insertions(+), 7 deletions(-) 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 dd0d30290fd..a6114ba0bdc 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,15 @@ def __init__( self._headers = headers or environ.get(OTEL_EXPORTER_OTLP_HEADERS) if isinstance(self._headers, str): - self._headers = tuple( - tuple(subitem.strip() for subitem in item.split("=", maxsplit=1)) for item in self._headers.split(",") - ) + temp_headers = [] + for header_pair in self._headers.split(","): + for key, value in header_pair.split("=", maxsplit=1): + key = key.strip().lower() + value = value.strip() + temp_headers.append(tuple(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")) From d6ef97a80ba3ba88faf248f49b4a1d5f35b33e1f Mon Sep 17 00:00:00 2001 From: Eddy Lin Date: Tue, 18 May 2021 12:12:57 -0400 Subject: [PATCH 04/11] Updated exporter otlp header parsing - Edited unit tests to test that uppercase keys become lowercase and keys/values are trimmed of optional white spaces (OWS) --- .../exporter/otlp/proto/grpc/exporter.py | 12 +++++++++--- .../tests/test_otlp_trace_exporter.py | 8 ++++---- 2 files changed, 13 insertions(+), 7 deletions(-) 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 dd0d30290fd..58a182bbdc9 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,15 @@ def __init__( self._headers = headers or environ.get(OTEL_EXPORTER_OTLP_HEADERS) if isinstance(self._headers, str): - self._headers = tuple( - tuple(subitem.strip() for subitem in item.split("=", maxsplit=1)) 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(tuple(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")) From d8e1367ca8ae5023c0d4fd9620f64a36121e1a55 Mon Sep 17 00:00:00 2001 From: Edward Lin Date: Tue, 18 May 2021 12:50:53 -0400 Subject: [PATCH 05/11] Added initial changelog entry stub --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8130b493fa6..2d49f7110e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.2.0-0.21b0...HEAD) +- Fixed exporter OTLP header parsing to match baggage header formatting. + (TBD) ## [1.2.0, 0.21b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.2.0-0.21b0) - 2021-05-11 From ad281f621ee5fb3581c3c2ade9f33687a63ad10d Mon Sep 17 00:00:00 2001 From: Edward Lin Date: Tue, 18 May 2021 12:54:21 -0400 Subject: [PATCH 06/11] Fixed error in appending header tuples --- .../src/opentelemetry/exporter/otlp/proto/grpc/exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 58a182bbdc9..d96b7748737 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 @@ -234,7 +234,7 @@ def __init__( key, value = header_pair.split("=", maxsplit=1) key = key.strip().lower() value = value.strip() - temp_headers.append(tuple(key, value)) + temp_headers.append(tuple([key, value])) self._headers = tuple(temp_headers) From 4f33b06c32a6ab6da36ed604f515bacaa8ba9c74 Mon Sep 17 00:00:00 2001 From: Edward Lin Date: Thu, 20 May 2021 10:35:49 -0400 Subject: [PATCH 07/11] Added Changed header to change log entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a09451727d..9be19c5a9d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.2.0-0.21b0...HEAD) + +### Changed - Fixed exporter OTLP header parsing to match baggage header formatting. (TBD) From cd0fdf4615862db348f5be1e452e324b884733d9 Mon Sep 17 00:00:00 2001 From: Edward Lin Date: Thu, 20 May 2021 10:56:57 -0400 Subject: [PATCH 08/11] Removed extraspacing for pylint --- .../src/opentelemetry/exporter/otlp/proto/grpc/exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6589cc86988..78992ac2f78 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 @@ -235,7 +235,7 @@ def __init__( key = key.strip().lower() value = value.strip() temp_headers.append(tuple([key, value])) - + self._headers = tuple(temp_headers) self._timeout = timeout or int( From daf9d1368dff6883a7ff4fb3195f89e538011a9e Mon Sep 17 00:00:00 2001 From: Eddy Lin Date: Mon, 24 May 2021 10:27:46 -0400 Subject: [PATCH 09/11] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9be19c5a9d4..4b2d755cfe9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Fixed exporter OTLP header parsing to match baggage header formatting. - (TBD) + ([#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 From 578c4a7a918fb5d184a294692d35c15f24ec436f Mon Sep 17 00:00:00 2001 From: Eddy Lin Date: Tue, 25 May 2021 15:41:37 -0400 Subject: [PATCH 10/11] Updated tuple to literal Co-authored-by: Owais Lone --- .../src/opentelemetry/exporter/otlp/proto/grpc/exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 78992ac2f78..fa43177761c 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 @@ -234,7 +234,7 @@ def __init__( key, value = header_pair.split("=", maxsplit=1) key = key.strip().lower() value = value.strip() - temp_headers.append(tuple([key, value])) + temp_headers.append((key, value,)) self._headers = tuple(temp_headers) From 1d81888519aaed4cb2e21c29b462d680d3747bf1 Mon Sep 17 00:00:00 2001 From: Edward Lin Date: Wed, 26 May 2021 12:28:05 -0400 Subject: [PATCH 11/11] Fixed lint error --- .../src/opentelemetry/exporter/otlp/proto/grpc/exporter.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 fa43177761c..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 @@ -234,7 +234,12 @@ def __init__( key, value = header_pair.split("=", maxsplit=1) key = key.strip().lower() value = value.strip() - temp_headers.append((key, value,)) + temp_headers.append( + ( + key, + value, + ) + ) self._headers = tuple(temp_headers)