Skip to content

Commit

Permalink
distro: fix auto instrumentation with otlp OTEL_TRACES_EXPORTER env v…
Browse files Browse the repository at this point in the history
…ar (#1657)
  • Loading branch information
seemk authored Mar 6, 2021
1 parent 1af9f87 commit 94e3a4a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1656])(https://github.com/open-telemetry/opentelemetry-python/pull/1656)
- Rename `DefaultSpan` to `NonRecordingSpan`
([#1661])(https://github.com/open-telemetry/opentelemetry-python/pull/1661)
- Fixed distro configuration with `OTEL_TRACES_EXPORTER` env var set to `otlp`
([#1657])(https://github.com/open-telemetry/opentelemetry-python/pull/1657)
- Moving `Getter`, `Setter` and `TextMapPropagator` out of `opentelemetry.trace.propagation` and
into `opentelemetry.propagators`
([#1662])(https://github.com/open-telemetry/opentelemetry-python/pull/1662)
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-distro/src/opentelemetry/distro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions opentelemetry-distro/tests/test_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
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,
)
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
Expand Down Expand Up @@ -143,3 +147,14 @@ 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]:
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):
self.assertEqual(sorted(_get_exporter_names()), ["jaeger", "zipkin"])

0 comments on commit 94e3a4a

Please sign in to comment.