diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f05dd7e832..b9aa9cc2ee6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v0.17b0...HEAD) +### Changed +- Tracer and Meter provider environment variables are now consistent with the rest + ([#1571](https://github.com/open-telemetry/opentelemetry-python/pull/1571)]) + ### Added - Added `end_on_exit` argument to `start_as_current_span` ([#1519](https://github.com/open-telemetry/opentelemetry-python/pull/1519)]) diff --git a/opentelemetry-api/src/opentelemetry/environment_variables/__init__.py b/opentelemetry-api/src/opentelemetry/environment_variables/__init__.py index 1bd5a6f46d2..810b24ca6de 100644 --- a/opentelemetry-api/src/opentelemetry/environment_variables/__init__.py +++ b/opentelemetry-api/src/opentelemetry/environment_variables/__init__.py @@ -19,3 +19,5 @@ OTEL_PYTHON_SERVICE_NAME = "OTEL_PYTHON_SERVICE_NAME" OTEL_TRACE_EXPORTER = "OTEL_TRACE_EXPORTER" OTEL_METRICS_EXPORTER = "OTEL_METRICS_EXPORTER" +OTEL_PYTHON_TRACER_PROVIDER = "OTEL_PYTHON_TRACER_PROVIDER" +OTEL_PYTHON_METER_PROVIDER = "OTEL_PYTHON_METER_PROVIDER" diff --git a/opentelemetry-api/src/opentelemetry/util/__init__.py b/opentelemetry-api/src/opentelemetry/util/__init__.py index c49ba1b353c..bb07b2c515b 100644 --- a/opentelemetry-api/src/opentelemetry/util/__init__.py +++ b/opentelemetry-api/src/opentelemetry/util/__init__.py @@ -19,6 +19,11 @@ from pkg_resources import iter_entry_points +from opentelemetry.environment_variables import ( + OTEL_PYTHON_METER_PROVIDER, + OTEL_PYTHON_TRACER_PROVIDER, +) + if TYPE_CHECKING: from opentelemetry.metrics import MeterProvider from opentelemetry.trace import TracerProvider @@ -39,7 +44,9 @@ def time_ns() -> int: return int(time.time() * 1e9) -def _load_provider(provider: str) -> Provider: +def _load_provider( + provider_environment_variable: str, provider: str +) -> Provider: try: entry_point = next( iter_entry_points( @@ -47,7 +54,8 @@ def _load_provider(provider: str) -> Provider: name=cast( str, environ.get( - provider.upper(), "default_{}".format(provider), + provider_environment_variable, + "default_{}".format(provider), ), ), ) @@ -59,8 +67,13 @@ def _load_provider(provider: str) -> Provider: def _load_meter_provider(provider: str) -> "MeterProvider": - return cast("MeterProvider", _load_provider(provider)) + return cast( + "MeterProvider", _load_provider(OTEL_PYTHON_METER_PROVIDER, provider), + ) def _load_trace_provider(provider: str) -> "TracerProvider": - return cast("TracerProvider", _load_provider(provider)) + return cast( + "TracerProvider", + _load_provider(OTEL_PYTHON_TRACER_PROVIDER, provider), + )