From 46242b0d02239f7ae5d82d6e38b9c35af382e136 Mon Sep 17 00:00:00 2001 From: Siim Kallas Date: Tue, 2 Mar 2021 12:21:37 +0200 Subject: [PATCH 1/5] Fix instrumentation with otlp exporter --- opentelemetry-distro/src/opentelemetry/distro/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-distro/src/opentelemetry/distro/__init__.py b/opentelemetry-distro/src/opentelemetry/distro/__init__.py index 666ab57bb37..6496be16c5b 100644 --- a/opentelemetry-distro/src/opentelemetry/distro/__init__.py +++ b/opentelemetry-distro/src/opentelemetry/distro/__init__.py @@ -67,7 +67,7 @@ def _get_exporter_names() -> Sequence[str]: ) if EXPORTER_OTLP in exporters: - exporters.pop(EXPORTER_OTLP) + exporters.remove(EXPORTER_OTLP) exporters.add(EXPORTER_OTLP_SPAN) return list(exporters) From 950251975b698335c6acffe9d7e8256d11c21f93 Mon Sep 17 00:00:00 2001 From: Siim Kallas Date: Tue, 2 Mar 2021 14:25:43 +0200 Subject: [PATCH 2/5] Add exporter config tests --- opentelemetry-distro/tests/test_configurator.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/opentelemetry-distro/tests/test_configurator.py b/opentelemetry-distro/tests/test_configurator.py index 91ca82da86f..41726fed9e2 100644 --- a/opentelemetry-distro/tests/test_configurator.py +++ b/opentelemetry-distro/tests/test_configurator.py @@ -18,13 +18,17 @@ from unittest.mock import patch from opentelemetry.distro import ( + _get_exporter_names, _get_id_generator, _import_id_generator, _init_tracing, + EXPORTER_OTLP, + EXPORTER_OTLP_SPAN, ) from opentelemetry.environment_variables import ( OTEL_PYTHON_ID_GENERATOR, OTEL_PYTHON_SERVICE_NAME, + OTEL_TRACES_EXPORTER, ) from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.trace.id_generator import IdGenerator, RandomIdGenerator @@ -143,3 +147,16 @@ def test_trace_init_custom_id_generator(self, mock_iter_entry_points): _init_tracing({}, id_generator) provider = self.set_provider_mock.call_args[0][0] self.assertIsInstance(provider.id_generator, CustomIdGenerator) + + +class TestExporterNames(TestCase): + def test_otlp_exporter_overwrite(self): + for exporter in [EXPORTER_OTLP, EXPORTER_OTLP_SPAN]: + environ[OTEL_TRACES_EXPORTER] = exporter + self.assertEqual(_get_exporter_names(), [EXPORTER_OTLP_SPAN]) + del environ[OTEL_TRACES_EXPORTER] + + def test_multiple_exporters(self): + environ[OTEL_TRACES_EXPORTER] = "jaeger,zipkin" + self.assertEqual(sorted(_get_exporter_names()), ["jaeger", "zipkin"]) + del environ[OTEL_TRACES_EXPORTER] From 2e775326ba56687326ee20428078e9fb10765e86 Mon Sep 17 00:00:00 2001 From: Siim Kallas Date: Tue, 2 Mar 2021 14:29:00 +0200 Subject: [PATCH 3/5] Fix lint --- opentelemetry-distro/tests/test_configurator.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/opentelemetry-distro/tests/test_configurator.py b/opentelemetry-distro/tests/test_configurator.py index 41726fed9e2..ea22bc114d0 100644 --- a/opentelemetry-distro/tests/test_configurator.py +++ b/opentelemetry-distro/tests/test_configurator.py @@ -18,12 +18,12 @@ from unittest.mock import patch from opentelemetry.distro import ( + EXPORTER_OTLP, + EXPORTER_OTLP_SPAN, _get_exporter_names, _get_id_generator, _import_id_generator, _init_tracing, - EXPORTER_OTLP, - EXPORTER_OTLP_SPAN, ) from opentelemetry.environment_variables import ( OTEL_PYTHON_ID_GENERATOR, @@ -152,11 +152,11 @@ def test_trace_init_custom_id_generator(self, mock_iter_entry_points): class TestExporterNames(TestCase): def test_otlp_exporter_overwrite(self): for exporter in [EXPORTER_OTLP, EXPORTER_OTLP_SPAN]: - environ[OTEL_TRACES_EXPORTER] = exporter - self.assertEqual(_get_exporter_names(), [EXPORTER_OTLP_SPAN]) - del environ[OTEL_TRACES_EXPORTER] + environ[OTEL_TRACES_EXPORTER] = exporter + self.assertEqual(_get_exporter_names(), [EXPORTER_OTLP_SPAN]) + del environ[OTEL_TRACES_EXPORTER] def test_multiple_exporters(self): - environ[OTEL_TRACES_EXPORTER] = "jaeger,zipkin" - self.assertEqual(sorted(_get_exporter_names()), ["jaeger", "zipkin"]) - del environ[OTEL_TRACES_EXPORTER] + environ[OTEL_TRACES_EXPORTER] = "jaeger,zipkin" + self.assertEqual(sorted(_get_exporter_names()), ["jaeger", "zipkin"]) + del environ[OTEL_TRACES_EXPORTER] From cdc9d031c05373e62c6835f0e8c02125e3d75eb0 Mon Sep 17 00:00:00 2001 From: Siim Kallas Date: Tue, 2 Mar 2021 14:43:49 +0200 Subject: [PATCH 4/5] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e09bf17a4b8..0aecf157d00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Renamed `BatchExportSpanProcessor` to `BatchSpanProcessor` and `SimpleExportSpanProcessor` to `SimpleSpanProcessor` ([#1656])(https://github.com/open-telemetry/opentelemetry-python/pull/1656) +- Fixed distro configuration with `OTEL_TRACES_EXPORTER` env var set to `otlp` + ([#1657])(https://github.com/open-telemetry/opentelemetry-python/pull/1657) ## [0.18b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v0.18b0) - 2021-02-16 From c6020bc4d40627079f3588f27cb6aa5d2d3f14e0 Mon Sep 17 00:00:00 2001 From: Siim Kallas Date: Tue, 2 Mar 2021 17:43:46 +0200 Subject: [PATCH 5/5] Use patch.dict --- opentelemetry-distro/tests/test_configurator.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/opentelemetry-distro/tests/test_configurator.py b/opentelemetry-distro/tests/test_configurator.py index ea22bc114d0..899e019113c 100644 --- a/opentelemetry-distro/tests/test_configurator.py +++ b/opentelemetry-distro/tests/test_configurator.py @@ -152,11 +152,9 @@ def test_trace_init_custom_id_generator(self, mock_iter_entry_points): class TestExporterNames(TestCase): def test_otlp_exporter_overwrite(self): for exporter in [EXPORTER_OTLP, EXPORTER_OTLP_SPAN]: - environ[OTEL_TRACES_EXPORTER] = exporter - self.assertEqual(_get_exporter_names(), [EXPORTER_OTLP_SPAN]) - del environ[OTEL_TRACES_EXPORTER] + with patch.dict(environ, {OTEL_TRACES_EXPORTER: exporter}): + self.assertEqual(_get_exporter_names(), [EXPORTER_OTLP_SPAN]) + @patch.dict(environ, {OTEL_TRACES_EXPORTER: "jaeger,zipkin"}) def test_multiple_exporters(self): - environ[OTEL_TRACES_EXPORTER] = "jaeger,zipkin" self.assertEqual(sorted(_get_exporter_names()), ["jaeger", "zipkin"]) - del environ[OTEL_TRACES_EXPORTER]