From f398bca911dc5fbe7c17bfc964d84ac5a3dabefa Mon Sep 17 00:00:00 2001 From: TylerHelmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Mon, 28 Feb 2022 10:56:30 -0700 Subject: [PATCH 1/9] modify OTLP HTTP trace exporter to append endpoint --- .../proto/http/trace_exporter/__init__.py | 10 +++++-- .../tests/test_proto_span_exporter.py | 30 +++++++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/__init__.py index b320119aeeb..194df64a197 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/__init__.py @@ -47,7 +47,8 @@ DEFAULT_COMPRESSION = Compression.NoCompression -DEFAULT_ENDPOINT = "http://localhost:4318/v1/traces" +DEFAULT_ENDPOINT = "http://localhost:4318/" +DEFAULT_TRACES_EXPORT_PATH = "v1/traces" DEFAULT_TIMEOUT = 10 # in seconds @@ -65,7 +66,7 @@ def __init__( ): self._endpoint = endpoint or environ.get( OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, - environ.get(OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_ENDPOINT), + _append_trace_path(environ.get(OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_ENDPOINT)), ) self._certificate_file = certificate_file or environ.get( OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE, @@ -172,3 +173,8 @@ def _compression_from_env() -> Compression: .strip() ) return Compression(compression) + +def _append_trace_path(endpoint: str) -> str: + if endpoint.endswith("/"): + return endpoint + DEFAULT_TRACES_EXPORT_PATH + return endpoint + f"/{DEFAULT_TRACES_EXPORT_PATH}" diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py index 7f91e05984f..c3528edd507 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py @@ -19,6 +19,7 @@ from opentelemetry.exporter.otlp.proto.http.trace_exporter import ( DEFAULT_COMPRESSION, DEFAULT_ENDPOINT, + DEFAULT_TRACES_EXPORT_PATH, DEFAULT_TIMEOUT, OTLPSpanExporter, ) @@ -40,6 +41,7 @@ OS_ENV_HEADERS = "envHeader1=val1,envHeader2=val2" OS_ENV_TIMEOUT = "30" +DEFAULT_TRACES_EXPORT_PATH = "v1/traces" # pylint: disable=protected-access class TestOTLPSpanExporter(unittest.TestCase): @@ -47,7 +49,7 @@ def test_constructor_default(self): exporter = OTLPSpanExporter() - self.assertEqual(exporter._endpoint, DEFAULT_ENDPOINT) + self.assertEqual(exporter._endpoint, DEFAULT_ENDPOINT + DEFAULT_TRACES_EXPORT_PATH) self.assertEqual(exporter._certificate_file, True) self.assertEqual(exporter._timeout, DEFAULT_TIMEOUT) self.assertIs(exporter._compression, DEFAULT_COMPRESSION) @@ -117,7 +119,6 @@ def test_exporter_constructor_take_priority(self): { OTEL_EXPORTER_OTLP_CERTIFICATE: OS_ENV_CERTIFICATE, OTEL_EXPORTER_OTLP_COMPRESSION: Compression.Gzip.value, - OTEL_EXPORTER_OTLP_ENDPOINT: OS_ENV_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS: OS_ENV_HEADERS, OTEL_EXPORTER_OTLP_TIMEOUT: OS_ENV_TIMEOUT, }, @@ -126,7 +127,6 @@ def test_exporter_env(self): exporter = OTLPSpanExporter() - self.assertEqual(exporter._endpoint, OS_ENV_ENDPOINT) self.assertEqual(exporter._certificate_file, OS_ENV_CERTIFICATE) self.assertEqual(exporter._timeout, int(OS_ENV_TIMEOUT)) self.assertIs(exporter._compression, Compression.Gzip) @@ -134,6 +134,30 @@ def test_exporter_env(self): exporter._headers, {"envheader1": "val1", "envheader2": "val2"} ) + @patch.dict( + "os.environ", + { + OTEL_EXPORTER_OTLP_ENDPOINT: OS_ENV_ENDPOINT + }, + ) + def test_exporter_env_endpoint_without_slash(self): + + exporter = OTLPSpanExporter() + + self.assertEqual(exporter._endpoint, OS_ENV_ENDPOINT + f"/{DEFAULT_TRACES_EXPORT_PATH}") + + @patch.dict( + "os.environ", + { + OTEL_EXPORTER_OTLP_ENDPOINT: OS_ENV_ENDPOINT + "/" + }, + ) + def test_exporter_env_endpoint_with_slash(self): + + exporter = OTLPSpanExporter() + + self.assertEqual(exporter._endpoint, OS_ENV_ENDPOINT + f"/{DEFAULT_TRACES_EXPORT_PATH}") + @patch.dict( "os.environ", { From 381d4c15b6259cbcbf789a348d2cf298fc3b5a2a Mon Sep 17 00:00:00 2001 From: TylerHelmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Mon, 28 Feb 2022 14:13:10 -0700 Subject: [PATCH 2/9] Added trace endpoint to test to prove priority --- .../tests/test_proto_span_exporter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py index c3528edd507..e7d5f3a1e87 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py @@ -92,6 +92,7 @@ def test_exporter_traces_env_take_priority(self): OTEL_EXPORTER_OTLP_CERTIFICATE: OS_ENV_CERTIFICATE, OTEL_EXPORTER_OTLP_COMPRESSION: Compression.Gzip.value, OTEL_EXPORTER_OTLP_ENDPOINT: OS_ENV_ENDPOINT, + OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: "https://traces.endpoint.env", OTEL_EXPORTER_OTLP_HEADERS: OS_ENV_HEADERS, OTEL_EXPORTER_OTLP_TIMEOUT: OS_ENV_TIMEOUT, }, From e18719500de678401da98e684b301ea1ea2e3e63 Mon Sep 17 00:00:00 2001 From: TylerHelmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Mon, 28 Feb 2022 14:37:13 -0700 Subject: [PATCH 3/9] Fixed linting issues --- .../proto/http/trace_exporter/__init__.py | 5 ++++- .../tests/test_proto_span_exporter.py | 22 +++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/__init__.py index 194df64a197..156afc247d9 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/trace_exporter/__init__.py @@ -66,7 +66,9 @@ def __init__( ): self._endpoint = endpoint or environ.get( OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, - _append_trace_path(environ.get(OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_ENDPOINT)), + _append_trace_path( + environ.get(OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_ENDPOINT) + ), ) self._certificate_file = certificate_file or environ.get( OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE, @@ -174,6 +176,7 @@ def _compression_from_env() -> Compression: ) return Compression(compression) + def _append_trace_path(endpoint: str) -> str: if endpoint.endswith("/"): return endpoint + DEFAULT_TRACES_EXPORT_PATH diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py index e7d5f3a1e87..96a9b949d68 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py @@ -49,7 +49,9 @@ def test_constructor_default(self): exporter = OTLPSpanExporter() - self.assertEqual(exporter._endpoint, DEFAULT_ENDPOINT + DEFAULT_TRACES_EXPORT_PATH) + self.assertEqual( + exporter._endpoint, DEFAULT_ENDPOINT + DEFAULT_TRACES_EXPORT_PATH + ) self.assertEqual(exporter._certificate_file, True) self.assertEqual(exporter._timeout, DEFAULT_TIMEOUT) self.assertIs(exporter._compression, DEFAULT_COMPRESSION) @@ -137,27 +139,29 @@ def test_exporter_env(self): @patch.dict( "os.environ", - { - OTEL_EXPORTER_OTLP_ENDPOINT: OS_ENV_ENDPOINT - }, + {OTEL_EXPORTER_OTLP_ENDPOINT: OS_ENV_ENDPOINT}, ) def test_exporter_env_endpoint_without_slash(self): exporter = OTLPSpanExporter() - self.assertEqual(exporter._endpoint, OS_ENV_ENDPOINT + f"/{DEFAULT_TRACES_EXPORT_PATH}") + self.assertEqual( + exporter._endpoint, + OS_ENV_ENDPOINT + f"/{DEFAULT_TRACES_EXPORT_PATH}", + ) @patch.dict( "os.environ", - { - OTEL_EXPORTER_OTLP_ENDPOINT: OS_ENV_ENDPOINT + "/" - }, + {OTEL_EXPORTER_OTLP_ENDPOINT: OS_ENV_ENDPOINT + "/"}, ) def test_exporter_env_endpoint_with_slash(self): exporter = OTLPSpanExporter() - self.assertEqual(exporter._endpoint, OS_ENV_ENDPOINT + f"/{DEFAULT_TRACES_EXPORT_PATH}") + self.assertEqual( + exporter._endpoint, + OS_ENV_ENDPOINT + f"/{DEFAULT_TRACES_EXPORT_PATH}" + ) @patch.dict( "os.environ", From 12d8e6abd6beeae6e550ed812122e9c68b04669d Mon Sep 17 00:00:00 2001 From: TylerHelmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Mon, 28 Feb 2022 14:41:14 -0700 Subject: [PATCH 4/9] fixed more lint issues --- .../tests/test_proto_span_exporter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py index 96a9b949d68..e74f09e7ed3 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py @@ -146,7 +146,7 @@ def test_exporter_env_endpoint_without_slash(self): exporter = OTLPSpanExporter() self.assertEqual( - exporter._endpoint, + exporter._endpoint, OS_ENV_ENDPOINT + f"/{DEFAULT_TRACES_EXPORT_PATH}", ) @@ -159,8 +159,8 @@ def test_exporter_env_endpoint_with_slash(self): exporter = OTLPSpanExporter() self.assertEqual( - exporter._endpoint, - OS_ENV_ENDPOINT + f"/{DEFAULT_TRACES_EXPORT_PATH}" + exporter._endpoint, + OS_ENV_ENDPOINT + f"/{DEFAULT_TRACES_EXPORT_PATH}", ) @patch.dict( From 67b7e451cac82f9617f1003ada4140a4d7c52781 Mon Sep 17 00:00:00 2001 From: TylerHelmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Mon, 28 Feb 2022 14:46:37 -0700 Subject: [PATCH 5/9] Removed unneeded constant from test file --- .../tests/test_proto_span_exporter.py | 1 - 1 file changed, 1 deletion(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py index e74f09e7ed3..06b90a931d1 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py @@ -41,7 +41,6 @@ OS_ENV_HEADERS = "envHeader1=val1,envHeader2=val2" OS_ENV_TIMEOUT = "30" -DEFAULT_TRACES_EXPORT_PATH = "v1/traces" # pylint: disable=protected-access class TestOTLPSpanExporter(unittest.TestCase): From 8d9eb2e84c010498fe5f8368f2dd30c51caf2d19 Mon Sep 17 00:00:00 2001 From: TylerHelmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Tue, 1 Mar 2022 08:07:02 -0700 Subject: [PATCH 6/9] Updated changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4031880bf78..928c4f73eb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#2461](https://github.com/open-telemetry/opentelemetry-python/pull/2461)) - fix exception handling in get_aggregated_resources ([#2464](https://github.com/open-telemetry/opentelemetry-python/pull/2464)) +- Fix `OTEL_EXPORTER_OTLP_ENDPOINT` usage in OTLP HTTP exporter + ([#2443](https://github.com/open-telemetry/opentelemetry-python/issues/2443)) ## [1.9.1-0.28b1](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.9.1-0.28b1) - 2022-01-29 From b75c45b106264bb6552b6c167240908984976934 Mon Sep 17 00:00:00 2001 From: TylerHelmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Tue, 1 Mar 2022 08:07:10 -0700 Subject: [PATCH 7/9] fix lint issues --- .../tests/test_proto_span_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py index 06b90a931d1..e3cd2046267 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_span_exporter.py @@ -19,8 +19,8 @@ from opentelemetry.exporter.otlp.proto.http.trace_exporter import ( DEFAULT_COMPRESSION, DEFAULT_ENDPOINT, - DEFAULT_TRACES_EXPORT_PATH, DEFAULT_TIMEOUT, + DEFAULT_TRACES_EXPORT_PATH, OTLPSpanExporter, ) from opentelemetry.sdk.environment_variables import ( From c9890f3ee693f8bf37cdbf7eb5ecdfc05d2f12db Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Tue, 1 Mar 2022 11:03:37 -0700 Subject: [PATCH 8/9] Update CHANGELOG.md Co-authored-by: Srikanth Chekuri --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da2e3ec829f..9fad671dea8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - fix exception handling in get_aggregated_resources ([#2464](https://github.com/open-telemetry/opentelemetry-python/pull/2464)) - Fix `OTEL_EXPORTER_OTLP_ENDPOINT` usage in OTLP HTTP exporter - ([#2443](https://github.com/open-telemetry/opentelemetry-python/issues/2443)) + ([#2493](https://github.com/open-telemetry/opentelemetry-python/pull/2493)) ## [1.9.1-0.28b1](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.9.1-0.28b1) - 2022-01-29 From f4686ff40a3939a6e9ba429f048c69905ae79a42 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Tue, 1 Mar 2022 15:18:59 -0700 Subject: [PATCH 9/9] Update CHANGELOG.md Co-authored-by: Leighton Chen --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fad671dea8..d5d58c8293b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#2461](https://github.com/open-telemetry/opentelemetry-python/pull/2461)) - fix exception handling in get_aggregated_resources ([#2464](https://github.com/open-telemetry/opentelemetry-python/pull/2464)) -- Fix `OTEL_EXPORTER_OTLP_ENDPOINT` usage in OTLP HTTP exporter +- Fix `OTEL_EXPORTER_OTLP_ENDPOINT` usage in OTLP HTTP trace exporter ([#2493](https://github.com/open-telemetry/opentelemetry-python/pull/2493)) ## [1.9.1-0.28b1](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.9.1-0.28b1) - 2022-01-29