Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use environment variables for tracer and meter providers #1571

Merged
merged 1 commit into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
21 changes: 17 additions & 4 deletions opentelemetry-api/src/opentelemetry/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,15 +44,18 @@ 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(
"opentelemetry_{}".format(provider),
name=cast(
str,
environ.get(
provider.upper(), "default_{}".format(provider),
provider_environment_variable,
"default_{}".format(provider),
),
),
)
Expand All @@ -59,8 +67,13 @@ def _load_provider(provider: str) -> Provider:


def _load_meter_provider(provider: str) -> "MeterProvider":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the provider arg altogether? I don't see when it would be anything different, its hardcoded in both spots:

_METER_PROVIDER = _load_meter_provider("meter_provider")

_TRACER_PROVIDER = _load_trace_provider("tracer_provider")

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),
)