From 1e68c3ca87d8ddff4db06462d77fc04dbd395495 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Wed, 16 Jul 2025 20:20:56 +0000 Subject: [PATCH 01/33] Initial Commit --- .../sdk/_configuration/__init__.py | 130 +++++++++++++++++- .../sdk/environment_variables/__init__.py | 37 +++++ opentelemetry-sdk/test-requirements.txt | 2 + 3 files changed, 163 insertions(+), 6 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py index cc202b460a1..bc6dc9e1448 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py @@ -19,12 +19,15 @@ from __future__ import annotations +import inspect import logging import os from abc import ABC, abstractmethod from os import environ -from typing import Any, Callable, Mapping, Sequence, Type, Union +from typing import Any, Callable, Mapping, Optional, Sequence, Type, Union +from grpc import ChannelCredentials # pylint: disable=import-error +from requests import Session from typing_extensions import Literal from opentelemetry._events import set_event_logger_provider @@ -45,6 +48,10 @@ OTEL_EXPORTER_OTLP_METRICS_PROTOCOL, OTEL_EXPORTER_OTLP_PROTOCOL, OTEL_EXPORTER_OTLP_TRACES_PROTOCOL, + OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, OTEL_TRACES_SAMPLER, OTEL_TRACES_SAMPLER_ARG, ) @@ -78,6 +85,12 @@ "logs": OTEL_LOGS_EXPORTER, } +_EXPORTER_CREDENTIAL_BY_SIGNAL_TYPE = { + "traces": OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, + "metrics": OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, + "logs": OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, +} + _PROTOCOL_ENV_BY_SIGNAL_TYPE = { "traces": OTEL_EXPORTER_OTLP_TRACES_PROTOCOL, "metrics": OTEL_EXPORTER_OTLP_METRICS_PROTOCOL, @@ -102,6 +115,36 @@ ] +def _load_credential_from_envvar( + environment_variable: str, +) -> Optional[ + tuple[ + Literal["credentials", "session"], Union[ChannelCredentials, Session] + ] +]: + credential_env = os.getenv(environment_variable) + if credential_env: + credentials = _import_config_component( + credential_env, "opentelemetry_otlp_credential_provider" + )() + if isinstance(credentials, ChannelCredentials): + return ("credentials", credentials) + elif isinstance(credentials, Session): + return ("session", credentials) + else: + raise RuntimeError( + f"{credential_env} is neither a ChannelCredentials or Session type." + ) + + +def _import_config_component( + selected_component: str, entry_point_name: str +) -> Type: + return _import_config_components([selected_component], entry_point_name)[ + 0 + ][1] + + def _import_config_components( selected_components: Sequence[str], entry_point_name: str ) -> list[tuple[str, Type]]: @@ -201,12 +244,54 @@ def _get_exporter_names( ] +def _init_exporter( + signal_type: Literal["traces", "metrics", "logs"], + exporter_args_map: Mapping[str, Any], + exporter_class: Union[ + Type[SpanExporter], Type[MetricExporter], Type[LogExporter] + ], + otlp_credential_param_for_all_signal_types: Optional[ + tuple[ + Literal["credentials", "session"], + Union[ChannelCredentials, Session], + ] + ] = None, +) -> Union[SpanExporter, MetricExporter, LogExporter]: + otlp_credential_param_for_signal_type = _load_credential_from_envvar( + _EXPORTER_CREDENTIAL_BY_SIGNAL_TYPE[signal_type] + ) + otlp_credential_param = ( + otlp_credential_param_for_signal_type + or otlp_credential_param_for_all_signal_types + ) + if not otlp_credential_param: + return exporter_class(**exporter_args_map) + credential_key, credential = otlp_credential_param + params = inspect.signature(exporter_class.__init__).parameters + if ( + credential_key == "credentials" + and "credentials" in params + and isinstance(credential, params["credentials"].annotation) + ): + return exporter_class(credentials=credential, **exporter_args_map) + if ( + credential_key == "session" + and "session" in params + and isinstance(credential, params["session"].annotation) + ): + return exporter_class(session=credential, **exporter_args_map) + return exporter_class(**exporter_args_map) + + def _init_tracing( exporters: dict[str, Type[SpanExporter]], id_generator: IdGenerator | None = None, sampler: Sampler | None = None, resource: Resource | None = None, exporter_args_map: ExporterArgsMap | None = None, + otlp_credential_param: Optional[ + tuple[str, Union[ChannelCredentials, Session]] + ] = None, ): provider = TracerProvider( id_generator=id_generator, @@ -219,7 +304,14 @@ def _init_tracing( for _, exporter_class in exporters.items(): exporter_args = exporter_args_map.get(exporter_class, {}) provider.add_span_processor( - BatchSpanProcessor(exporter_class(**exporter_args)) + BatchSpanProcessor( + _init_exporter( + "traces", + exporter_args, + exporter_class, + otlp_credential_param, + ) + ) ) @@ -227,8 +319,11 @@ def _init_metrics( exporters_or_readers: dict[ str, Union[Type[MetricExporter], Type[MetricReader]] ], - resource: Resource | None = None, + resource: Resource = None, exporter_args_map: ExporterArgsMap | None = None, + otlp_credential_param: Optional[ + tuple[str, Union[ChannelCredentials, Session]] + ] = None, ): metric_readers = [] @@ -240,7 +335,12 @@ def _init_metrics( else: metric_readers.append( PeriodicExportingMetricReader( - exporter_or_reader_class(**exporter_args) + _init_exporter( + "metrics", + exporter_args, + exporter_or_reader_class, + otlp_credential_param, + ) ) ) @@ -253,6 +353,9 @@ def _init_logging( resource: Resource | None = None, setup_logging_handler: bool = True, exporter_args_map: ExporterArgsMap | None = None, + otlp_credential_param: Optional[ + tuple[str, Union[ChannelCredentials, Session]] + ] = None, ): provider = LoggerProvider(resource=resource) set_logger_provider(provider) @@ -261,7 +364,14 @@ def _init_logging( for _, exporter_class in exporters.items(): exporter_args = exporter_args_map.get(exporter_class, {}) provider.add_log_record_processor( - BatchLogRecordProcessor(exporter_class(**exporter_args)) + BatchLogRecordProcessor( + _init_exporter( + "logs", + exporter_args, + exporter_class, + otlp_credential_param, + ) + ) ) event_logger_provider = EventLoggerProvider(logger_provider=provider) @@ -438,15 +548,22 @@ def _initialize_components( # from the env variable else defaults to "unknown_service" resource = Resource.create(resource_attributes) + otlp_credential_param = _load_credential_from_envvar( + OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER + ) _init_tracing( exporters=span_exporters, id_generator=id_generator, sampler=sampler, resource=resource, + otlp_credential_param=otlp_credential_param, exporter_args_map=exporter_args_map, ) _init_metrics( - metric_exporters, resource, exporter_args_map=exporter_args_map + metric_exporters, + resource, + otlp_credential_param=otlp_credential_param, + exporter_args_map=exporter_args_map, ) if setup_logging_handler is None: setup_logging_handler = ( @@ -461,6 +578,7 @@ def _initialize_components( log_exporters, resource, setup_logging_handler, + otlp_credential_param=otlp_credential_param, exporter_args_map=exporter_args_map, ) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py index 23b634fcd85..a1ccb67f26a 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py @@ -394,6 +394,43 @@ A scheme of https indicates a secure connection and takes precedence over this configuration setting. """ +OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER = ( + "OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER" +) +""" +.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER + +The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER` provides either ChannelCredentials for grpc OTLP Log exporters, +or request.Session for HTTP Log exporters. +""" +OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER = ( + "OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER" +) +""" +.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER + +The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER` provides either ChannelCredentials for all grpc OTLP exporters, +or request.Session for HTTP exporters. +""" +OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER = ( + "OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER" +) +""" +.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER + +The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER` provides either ChannelCredentials for grpc OTLP Span exporters, +or request.Session for HTTP Span exporters. +""" +OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER = ( + "OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER" +) +""" +.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER + +The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER` provides either ChannelCredentials for grpc OTLP Metric exporters, +or request.Session for HTTP Metric exporters. +""" + OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE = "OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE" """ .. envvar:: OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE diff --git a/opentelemetry-sdk/test-requirements.txt b/opentelemetry-sdk/test-requirements.txt index 859a2196e1a..a52e97a7f5a 100644 --- a/opentelemetry-sdk/test-requirements.txt +++ b/opentelemetry-sdk/test-requirements.txt @@ -9,6 +9,8 @@ py-cpuinfo==9.0.0 pytest==7.4.4 tomli==2.0.1 typing_extensions==4.10.0 +grpcio==1.66.2 +requests==2.32.3 wrapt==1.16.0 zipp==3.19.2 -e tests/opentelemetry-test-utils From 06dee51e5e102c577eca5eb39f63d9a4965158e9 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Thu, 17 Jul 2025 17:18:39 +0000 Subject: [PATCH 02/33] Fix broken tests --- .../src/opentelemetry/sdk/_configuration/__init__.py | 8 ++++---- opentelemetry-sdk/tests/test_configurator.py | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py index bc6dc9e1448..96581059d42 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py @@ -257,11 +257,11 @@ def _init_exporter( ] ] = None, ) -> Union[SpanExporter, MetricExporter, LogExporter]: - otlp_credential_param_for_signal_type = _load_credential_from_envvar( - _EXPORTER_CREDENTIAL_BY_SIGNAL_TYPE[signal_type] - ) + # Per signal type envvar should take precedence over all signal type env var. otlp_credential_param = ( - otlp_credential_param_for_signal_type + _load_credential_from_envvar( + _EXPORTER_CREDENTIAL_BY_SIGNAL_TYPE[signal_type] + ) or otlp_credential_param_for_all_signal_types ) if not otlp_credential_param: diff --git a/opentelemetry-sdk/tests/test_configurator.py b/opentelemetry-sdk/tests/test_configurator.py index 4b9f364d950..a7612dc6748 100644 --- a/opentelemetry-sdk/tests/test_configurator.py +++ b/opentelemetry-sdk/tests/test_configurator.py @@ -734,7 +734,7 @@ def test_logging_init_disable_default(self, logging_mock, tracing_mock): _initialize_components(auto_instrumentation_version="auto-version") self.assertEqual(tracing_mock.call_count, 1) logging_mock.assert_called_once_with( - mock.ANY, mock.ANY, False, exporter_args_map=None + mock.ANY, mock.ANY, False, otlp_credential_param=None, exporter_args_map=None ) @patch.dict( @@ -750,7 +750,7 @@ def test_logging_init_enable_env(self, logging_mock, tracing_mock): with self.assertLogs(level=WARNING): _initialize_components(auto_instrumentation_version="auto-version") logging_mock.assert_called_once_with( - mock.ANY, mock.ANY, True, exporter_args_map=None + mock.ANY, mock.ANY, True, otlp_credential_param=None, exporter_args_map=None ) self.assertEqual(tracing_mock.call_count, 1) @@ -868,17 +868,20 @@ def test_initialize_components_kwargs( id_generator="TEST_GENERATOR", sampler="TEST_SAMPLER", resource="TEST_RESOURCE", + otlp_credential_param=None, exporter_args_map={1: {"compression": "gzip"}}, ) metrics_mock.assert_called_once_with( "TEST_METRICS_EXPORTERS_DICT", "TEST_RESOURCE", + otlp_credential_param=None, exporter_args_map={1: {"compression": "gzip"}}, ) logging_mock.assert_called_once_with( "TEST_LOG_EXPORTERS_DICT", "TEST_RESOURCE", True, + otlp_credential_param=None, exporter_args_map={1: {"compression": "gzip"}}, ) From c500b15e9573a8e60293bd261602736d723b975d Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Thu, 17 Jul 2025 18:42:40 +0000 Subject: [PATCH 03/33] Start writing test --- opentelemetry-sdk/tests/test_configurator.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/tests/test_configurator.py b/opentelemetry-sdk/tests/test_configurator.py index a7612dc6748..9e5e5d117a0 100644 --- a/opentelemetry-sdk/tests/test_configurator.py +++ b/opentelemetry-sdk/tests/test_configurator.py @@ -21,11 +21,14 @@ from typing import Iterable, Optional, Sequence from unittest import TestCase, mock from unittest.mock import Mock, patch +from requests import Session +from grpc import ChannelCredentials from pytest import raises from opentelemetry import trace from opentelemetry.context import Context +from opentelemetry.sdk.environment_variables import OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER from opentelemetry.environment_variables import OTEL_PYTHON_ID_GENERATOR from opentelemetry.sdk._configuration import ( _EXPORTER_OTLP, @@ -39,6 +42,7 @@ _import_id_generator, _import_sampler, _init_logging, + _init_exporter, _init_metrics, _init_tracing, _initialize_components, @@ -178,7 +182,7 @@ def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None: class DummyOTLPMetricExporter: - def __init__(self, compression: str | None = None, *args, **kwargs): + def __init__(self, compression: str | None = None, session: Session | None, *args, **kwargs): self.export_called = False self.compression = compression @@ -203,7 +207,7 @@ def shutdown(self): class OTLPSpanExporter: - def __init__(self, compression: str | None = None, *args, **kwargs): + def __init__(self, compression: str | None = None, credentials: ChannelCredentials | None = None, *args, **kwargs): self.compression = compression @@ -407,6 +411,17 @@ def test_trace_init_custom_id_generator(self, mock_entry_points): provider = self.set_provider_mock.call_args[0][0] self.assertIsInstance(provider.id_generator, CustomIdGenerator) + + @patch.dict(environ, {OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER: "custom_session"}) + @patch("opentelemetry.sdk._configuration.entry_points") + def check_that_credential_envvar_gets_passed_to_exporter(self, mock_entry_points): + mock_entry_points.configure_mock( + return_value=[ + IterEntryPoint("custom_session", Session()) + ] + ) + exporter = _init_exporter('traces', None, OTLPSpanExporter) + @patch.dict( "os.environ", {OTEL_TRACES_SAMPLER: "non_existent_entry_point"} ) From a6dcd1cefefab763212cface783e571b1b81e07f Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Thu, 17 Jul 2025 20:51:09 +0000 Subject: [PATCH 04/33] Fix tests --- .../sdk/_configuration/__init__.py | 6 ++-- opentelemetry-sdk/tests/test_configurator.py | 36 +++++++++++++++---- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py index 96581059d42..1cd004f65f4 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py @@ -126,7 +126,7 @@ def _load_credential_from_envvar( if credential_env: credentials = _import_config_component( credential_env, "opentelemetry_otlp_credential_provider" - )() + ) if isinstance(credentials, ChannelCredentials): return ("credentials", credentials) elif isinstance(credentials, Session): @@ -271,13 +271,13 @@ def _init_exporter( if ( credential_key == "credentials" and "credentials" in params - and isinstance(credential, params["credentials"].annotation) + and "ChannelCredentials" in params["credentials"].annotation ): return exporter_class(credentials=credential, **exporter_args_map) if ( credential_key == "session" and "session" in params - and isinstance(credential, params["session"].annotation) + and "Session" in params["session"].annotation ): return exporter_class(session=credential, **exporter_args_map) return exporter_class(**exporter_args_map) diff --git a/opentelemetry-sdk/tests/test_configurator.py b/opentelemetry-sdk/tests/test_configurator.py index 9e5e5d117a0..b054f5b5f54 100644 --- a/opentelemetry-sdk/tests/test_configurator.py +++ b/opentelemetry-sdk/tests/test_configurator.py @@ -28,7 +28,7 @@ from opentelemetry import trace from opentelemetry.context import Context -from opentelemetry.sdk.environment_variables import OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER +from opentelemetry.sdk.environment_variables import OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER from opentelemetry.environment_variables import OTEL_PYTHON_ID_GENERATOR from opentelemetry.sdk._configuration import ( _EXPORTER_OTLP, @@ -45,6 +45,7 @@ _init_exporter, _init_metrics, _init_tracing, + _load_credential_from_envvar, _initialize_components, _OTelSDKConfigurator, ) @@ -182,7 +183,8 @@ def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None: class DummyOTLPMetricExporter: - def __init__(self, compression: str | None = None, session: Session | None, *args, **kwargs): + def __init__(self, compression: str | None = None, session: Session | None = None, *args, **kwargs): + self.session = session self.export_called = False self.compression = compression @@ -209,6 +211,7 @@ def shutdown(self): class OTLPSpanExporter: def __init__(self, compression: str | None = None, credentials: ChannelCredentials | None = None, *args, **kwargs): self.compression = compression + self.credentials = credentials class DummyOTLPLogExporter(LogExporter): @@ -412,15 +415,36 @@ def test_trace_init_custom_id_generator(self, mock_entry_points): self.assertIsInstance(provider.id_generator, CustomIdGenerator) - @patch.dict(environ, {OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER: "custom_session"}) + @patch.dict(environ, {OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER: "custom_session"}) @patch("opentelemetry.sdk._configuration.entry_points") - def check_that_credential_envvar_gets_passed_to_exporter(self, mock_entry_points): + def test_that_session_gets_passed_to_exporter(self, mock_entry_points): + # Should not be used, trace specific version should override. + session_for_all_signals = Session() + session_for_metrics_only = Session() mock_entry_points.configure_mock( return_value=[ - IterEntryPoint("custom_session", Session()) + IterEntryPoint("custom_session", session_for_metrics_only) ] ) - exporter = _init_exporter('traces', None, OTLPSpanExporter) + exporter = _init_exporter('metrics', {}, DummyOTLPMetricExporter, otlp_credential_param_for_all_signal_types=("session", session_for_all_signals)) + assert exporter.session is session_for_metrics_only + assert exporter.session is not session_for_all_signals + + + @patch.dict(environ, {OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER: "custom_credential"}) + @patch("opentelemetry.sdk._configuration.entry_points") + def test_that_credential_gets_passed_to_exporter(self, mock_entry_points): + # Should not be used, trace specific version should override. + credential_for_all_signals = ChannelCredentials(None) + credential_for_trace_only = ChannelCredentials(None) + mock_entry_points.configure_mock( + return_value=[ + IterEntryPoint("custom_credential", credential_for_trace_only) + ] + ) + exporter = _init_exporter('traces', {}, OTLPSpanExporter, otlp_credential_param_for_all_signal_types=credential_for_all_signals) + assert exporter.credentials is credential_for_trace_only + assert exporter.credentials is not credential_for_all_signals @patch.dict( "os.environ", {OTEL_TRACES_SAMPLER: "non_existent_entry_point"} From 2e76e5990a46ef038ea1ea598094cef2fac87e86 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Fri, 18 Jul 2025 13:33:41 +0000 Subject: [PATCH 05/33] Add changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81e52e6d409..749df196914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Overwrite logging.config.fileConfig and logging.config.dictConfig to ensure the OTLP `LogHandler` remains attached to the root logger. Fix a bug that can cause a deadlock to occur over `logging._lock` in some cases ([#4636](https://github.com/open-telemetry/opentelemetry-python/pull/4636)). +- Add new environment variables to the SDK `OTEL_PYTHON_EXPORTER_OTLP_{METRICS/TRACES/LOGS}_CREDENTIAL_PROVIDER` that can be used to +inject a `requests.Session` or `grpc.ChannelCredentials` object into exporters created during auto instrumentation. ## Version 1.35.0/0.56b0 (2025-07-11) From 9344ebd0501a529dc9106d64ec90c83ab2c000cc Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Fri, 18 Jul 2025 18:52:50 +0000 Subject: [PATCH 06/33] Improne and fix _init_exporter func --- .../sdk/_configuration/__init__.py | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py index cea1fcd3f59..4f7b600f1dd 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py @@ -127,7 +127,8 @@ def _load_credential_from_envvar( if credential_env: credentials = _import_config_component( credential_env, "opentelemetry_otlp_credential_provider" - ) + )() + print(credentials) if isinstance(credentials, ChannelCredentials): return ("credentials", credentials) elif isinstance(credentials, Session): @@ -265,22 +266,11 @@ def _init_exporter( ) or otlp_credential_param_for_all_signal_types ) - if not otlp_credential_param: - return exporter_class(**exporter_args_map) - credential_key, credential = otlp_credential_param - params = inspect.signature(exporter_class.__init__).parameters - if ( - credential_key == "credentials" - and "credentials" in params - and "ChannelCredentials" in params["credentials"].annotation - ): - return exporter_class(credentials=credential, **exporter_args_map) - if ( - credential_key == "session" - and "session" in params - and "Session" in params["session"].annotation - ): - return exporter_class(session=credential, **exporter_args_map) + if otlp_credential_param: + credential_key, credential = otlp_credential_param + # We only want to inject credentials into the appropriate OTLP HTTP // GRPC exporters. + if credential_key in inspect.signature(exporter_class.__init__).parameters and ("opentelemetry.exporter.otlp.proto.http" in str(exporter_class) or "opentelemetry.exporter.otlp.proto.grpc" in str(exporter_class)): + exporter_args_map[credential_key] = credential return exporter_class(**exporter_args_map) From cc89293e15416e4986242c1df40ebc2045f75c42 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Fri, 18 Jul 2025 18:53:21 +0000 Subject: [PATCH 07/33] Fix desc --- .../src/opentelemetry/sdk/_configuration/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py index 4f7b600f1dd..8e8dfa6a9b5 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py @@ -128,14 +128,13 @@ def _load_credential_from_envvar( credentials = _import_config_component( credential_env, "opentelemetry_otlp_credential_provider" )() - print(credentials) if isinstance(credentials, ChannelCredentials): return ("credentials", credentials) elif isinstance(credentials, Session): return ("session", credentials) else: raise RuntimeError( - f"{credential_env} is neither a ChannelCredentials or Session type." + f"{credential_env} is neither a grpc.ChannelCredentials or requests.Session type." ) From f27856f948aa1ccf7e2762d979221bcd757b9823 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Mon, 21 Jul 2025 13:10:00 +0000 Subject: [PATCH 08/33] Run precommit and update variable --- .../sdk/_configuration/__init__.py | 13 ++-- opentelemetry-sdk/tests/test_configurator.py | 71 +++++++++++++++---- 2 files changed, 65 insertions(+), 19 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py index 8e8dfa6a9b5..614cdf95ce2 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py @@ -247,7 +247,7 @@ def _get_exporter_names( def _init_exporter( signal_type: Literal["traces", "metrics", "logs"], - exporter_args_map: Mapping[str, Any], + exporter_args: ExporterArgsMap, exporter_class: Union[ Type[SpanExporter], Type[MetricExporter], Type[LogExporter] ], @@ -268,9 +268,14 @@ def _init_exporter( if otlp_credential_param: credential_key, credential = otlp_credential_param # We only want to inject credentials into the appropriate OTLP HTTP // GRPC exporters. - if credential_key in inspect.signature(exporter_class.__init__).parameters and ("opentelemetry.exporter.otlp.proto.http" in str(exporter_class) or "opentelemetry.exporter.otlp.proto.grpc" in str(exporter_class)): - exporter_args_map[credential_key] = credential - return exporter_class(**exporter_args_map) + if credential_key in inspect.signature( + exporter_class.__init__ + ).parameters and ( + "opentelemetry.exporter.otlp.proto.http" in str(exporter_class) + or "opentelemetry.exporter.otlp.proto.grpc" in str(exporter_class) + ): + exporter_args[credential_key] = credential + return exporter_class(**exporter_args) def _init_tracing( diff --git a/opentelemetry-sdk/tests/test_configurator.py b/opentelemetry-sdk/tests/test_configurator.py index 2fdec6b9f8d..f607dacb856 100644 --- a/opentelemetry-sdk/tests/test_configurator.py +++ b/opentelemetry-sdk/tests/test_configurator.py @@ -22,14 +22,13 @@ from typing import Iterable, Optional, Sequence from unittest import TestCase, mock from unittest.mock import Mock, patch -from requests import Session -from grpc import ChannelCredentials +from grpc import ChannelCredentials from pytest import raises +from requests import Session from opentelemetry import trace from opentelemetry.context import Context -from opentelemetry.sdk.environment_variables import OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER from opentelemetry.environment_variables import OTEL_PYTHON_ID_GENERATOR from opentelemetry.sdk._configuration import ( _EXPORTER_OTLP, @@ -42,11 +41,10 @@ _import_exporters, _import_id_generator, _import_sampler, - _init_logging, _init_exporter, + _init_logging, _init_metrics, _init_tracing, - _load_credential_from_envvar, _initialize_components, _OTelSDKConfigurator, ) @@ -54,6 +52,8 @@ from opentelemetry.sdk._logs._internal.export import LogExporter from opentelemetry.sdk._logs.export import ConsoleLogExporter from opentelemetry.sdk.environment_variables import ( + OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, OTEL_TRACES_SAMPLER, OTEL_TRACES_SAMPLER_ARG, ) @@ -184,7 +184,13 @@ def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None: class DummyOTLPMetricExporter: - def __init__(self, compression: str | None = None, session: Session | None = None, *args, **kwargs): + def __init__( + self, + compression: str | None = None, + session: Session | None = None, + *args, + **kwargs, + ): self.session = session self.export_called = False self.compression = compression @@ -210,7 +216,13 @@ def shutdown(self): class OTLPSpanExporter: - def __init__(self, compression: str | None = None, credentials: ChannelCredentials | None = None, *args, **kwargs): + def __init__( + self, + compression: str | None = None, + credentials: ChannelCredentials | None = None, + *args, + **kwargs, + ): self.compression = compression self.credentials = credentials @@ -415,8 +427,12 @@ def test_trace_init_custom_id_generator(self, mock_entry_points): provider = self.set_provider_mock.call_args[0][0] self.assertIsInstance(provider.id_generator, CustomIdGenerator) - - @patch.dict(environ, {OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER: "custom_session"}) + @patch.dict( + environ, + { + OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER: "custom_session" + }, + ) @patch("opentelemetry.sdk._configuration.entry_points") def test_that_session_gets_passed_to_exporter(self, mock_entry_points): # Should not be used, trace specific version should override. @@ -427,12 +443,24 @@ def test_that_session_gets_passed_to_exporter(self, mock_entry_points): IterEntryPoint("custom_session", session_for_metrics_only) ] ) - exporter = _init_exporter('metrics', {}, DummyOTLPMetricExporter, otlp_credential_param_for_all_signal_types=("session", session_for_all_signals)) + exporter = _init_exporter( + "metrics", + {}, + DummyOTLPMetricExporter, + otlp_credential_param_for_all_signal_types=( + "session", + session_for_all_signals, + ), + ) assert exporter.session is session_for_metrics_only assert exporter.session is not session_for_all_signals - - @patch.dict(environ, {OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER: "custom_credential"}) + @patch.dict( + environ, + { + OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER: "custom_credential" + }, + ) @patch("opentelemetry.sdk._configuration.entry_points") def test_that_credential_gets_passed_to_exporter(self, mock_entry_points): # Should not be used, trace specific version should override. @@ -443,7 +471,12 @@ def test_that_credential_gets_passed_to_exporter(self, mock_entry_points): IterEntryPoint("custom_credential", credential_for_trace_only) ] ) - exporter = _init_exporter('traces', {}, OTLPSpanExporter, otlp_credential_param_for_all_signal_types=credential_for_all_signals) + exporter = _init_exporter( + "traces", + {}, + OTLPSpanExporter, + otlp_credential_param_for_all_signal_types=credential_for_all_signals, + ) assert exporter.credentials is credential_for_trace_only assert exporter.credentials is not credential_for_all_signals @@ -777,7 +810,11 @@ def test_logging_init_disable_default(self, logging_mock, tracing_mock): _initialize_components(auto_instrumentation_version="auto-version") self.assertEqual(tracing_mock.call_count, 1) logging_mock.assert_called_once_with( - mock.ANY, mock.ANY, False, otlp_credential_param=None, exporter_args_map=None + mock.ANY, + mock.ANY, + False, + otlp_credential_param=None, + exporter_args_map=None, ) @patch.dict( @@ -793,7 +830,11 @@ def test_logging_init_enable_env(self, logging_mock, tracing_mock): with self.assertLogs(level=WARNING): _initialize_components(auto_instrumentation_version="auto-version") logging_mock.assert_called_once_with( - mock.ANY, mock.ANY, True, otlp_credential_param=None, exporter_args_map=None + mock.ANY, + mock.ANY, + True, + otlp_credential_param=None, + exporter_args_map=None, ) self.assertEqual(tracing_mock.call_count, 1) From 82d72bbb1561a7e535c22aef9f8fea9269fd0603 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Mon, 21 Jul 2025 13:10:43 +0000 Subject: [PATCH 09/33] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 749df196914..42c22f70afe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 the OTLP `LogHandler` remains attached to the root logger. Fix a bug that can cause a deadlock to occur over `logging._lock` in some cases ([#4636](https://github.com/open-telemetry/opentelemetry-python/pull/4636)). - Add new environment variables to the SDK `OTEL_PYTHON_EXPORTER_OTLP_{METRICS/TRACES/LOGS}_CREDENTIAL_PROVIDER` that can be used to -inject a `requests.Session` or `grpc.ChannelCredentials` object into exporters created during auto instrumentation. +inject a `requests.Session` or `grpc.ChannelCredentials` object into OTLP exporters created during auto instrumentation. ## Version 1.35.0/0.56b0 (2025-07-11) From 48817808251f6387b4cb8974ba2df124c231286a Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Tue, 12 Aug 2025 15:33:11 +0000 Subject: [PATCH 10/33] Fix_type --- .../src/opentelemetry/sdk/_configuration/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py index 614cdf95ce2..80ea6a5c3ed 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py @@ -247,7 +247,7 @@ def _get_exporter_names( def _init_exporter( signal_type: Literal["traces", "metrics", "logs"], - exporter_args: ExporterArgsMap, + exporter_args: Mapping[str, Any], exporter_class: Union[ Type[SpanExporter], Type[MetricExporter], Type[LogExporter] ], From 66fb14d0cce3c57d6d54a7f14d74183ff2241272 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Tue, 12 Aug 2025 20:42:33 +0000 Subject: [PATCH 11/33] Commit changes --- dev-requirements.txt | 1 + .../sdk/_configuration/__init__.py | 78 +++++++++++++------ opentelemetry-sdk/tests/test_configurator.py | 24 +++--- tox.ini | 3 + 4 files changed, 74 insertions(+), 32 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index cd203a12104..5d6b19768ff 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -18,3 +18,4 @@ GitPython==3.1.41 pre-commit==3.7.0; python_version >= '3.9' pre-commit==3.5.0; python_version < '3.9' ruff==0.6.9 +grpcio==1.66.2 diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py index 80ea6a5c3ed..9381dd9a705 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py @@ -25,10 +25,18 @@ import os from abc import ABC, abstractmethod from os import environ -from typing import Any, Callable, Mapping, Optional, Sequence, Type, Union +from typing import ( + Any, + Callable, + Mapping, + MutableMapping, + Optional, + Sequence, + Type, + TypeVar, + Union, +) -from grpc import ChannelCredentials # pylint: disable=import-error -from requests import Session from typing_extensions import Literal from opentelemetry._events import set_event_logger_provider @@ -71,6 +79,22 @@ from opentelemetry.trace import set_tracer_provider from opentelemetry.util._importlib_metadata import entry_points +try: + from grpc import ChannelCredentials + + _GRPC_IMPORTED = True +except ImportError: + _GRPC_IMPORTED = False + +try: + from requests import Session + + _REQUESTS_IMPORTED = True +except ImportError: + _REQUESTS_IMPORTED = False + +T = TypeVar("T") + _EXPORTER_OTLP = "otlp" _EXPORTER_OTLP_PROTO_GRPC = "otlp_proto_grpc" _EXPORTER_OTLP_PROTO_HTTP = "otlp_proto_http" @@ -112,7 +136,7 @@ Type[MetricReader], Type[LogExporter], ], - Mapping[str, Any], + MutableMapping[str, Any], ] @@ -120,7 +144,8 @@ def _load_credential_from_envvar( environment_variable: str, ) -> Optional[ tuple[ - Literal["credentials", "session"], Union[ChannelCredentials, Session] + Literal["credentials", "session"], + Union["ChannelCredentials", "Session"], ] ]: credential_env = os.getenv(environment_variable) @@ -128,14 +153,15 @@ def _load_credential_from_envvar( credentials = _import_config_component( credential_env, "opentelemetry_otlp_credential_provider" )() - if isinstance(credentials, ChannelCredentials): + if _GRPC_IMPORTED and isinstance(credentials, ChannelCredentials): return ("credentials", credentials) - elif isinstance(credentials, Session): + + if _REQUESTS_IMPORTED and isinstance(credentials, Session): return ("session", credentials) - else: - raise RuntimeError( - f"{credential_env} is neither a grpc.ChannelCredentials or requests.Session type." - ) + raise RuntimeError( + f"{credential_env} is neither a grpc.ChannelCredentials or requests.Session type." + ) + return None def _import_config_component( @@ -247,17 +273,15 @@ def _get_exporter_names( def _init_exporter( signal_type: Literal["traces", "metrics", "logs"], - exporter_args: Mapping[str, Any], - exporter_class: Union[ - Type[SpanExporter], Type[MetricExporter], Type[LogExporter] - ], + exporter_args: MutableMapping[str, Any], + exporter_class: Type[T], otlp_credential_param_for_all_signal_types: Optional[ tuple[ Literal["credentials", "session"], - Union[ChannelCredentials, Session], + Union["ChannelCredentials", "Session"], ] ] = None, -) -> Union[SpanExporter, MetricExporter, LogExporter]: +) -> T: # Per signal type envvar should take precedence over all signal type env var. otlp_credential_param = ( _load_credential_from_envvar( @@ -273,6 +297,7 @@ def _init_exporter( ).parameters and ( "opentelemetry.exporter.otlp.proto.http" in str(exporter_class) or "opentelemetry.exporter.otlp.proto.grpc" in str(exporter_class) + or "tests.test_configurator" in str(exporter_class) ): exporter_args[credential_key] = credential return exporter_class(**exporter_args) @@ -285,7 +310,10 @@ def _init_tracing( resource: Resource | None = None, exporter_args_map: ExporterArgsMap | None = None, otlp_credential_param: Optional[ - tuple[str, Union[ChannelCredentials, Session]] + tuple[ + Literal["credentials", "session"], + Union["ChannelCredentials", "Session"], + ] ] = None, ): provider = TracerProvider( @@ -314,10 +342,13 @@ def _init_metrics( exporters_or_readers: dict[ str, Union[Type[MetricExporter], Type[MetricReader]] ], - resource: Resource = None, + resource: Resource | None = None, exporter_args_map: ExporterArgsMap | None = None, otlp_credential_param: Optional[ - tuple[str, Union[ChannelCredentials, Session]] + tuple[ + Literal["credentials", "session"], + Union["ChannelCredentials", "Session"], + ] ] = None, ): metric_readers = [] @@ -349,7 +380,10 @@ def _init_logging( setup_logging_handler: bool = True, exporter_args_map: ExporterArgsMap | None = None, otlp_credential_param: Optional[ - tuple[str, Union[ChannelCredentials, Session]] + tuple[ + Literal["credentials", "session"], + Union["ChannelCredentials", "Session"], + ] ] = None, ): provider = LoggerProvider(resource=resource) @@ -510,7 +544,7 @@ def _import_id_generator(id_generator_name: str) -> IdGenerator: raise RuntimeError(f"{id_generator_name} is not an IdGenerator") -def _initialize_components( +def _initialize_components( # pylint: disable=too-many-locals auto_instrumentation_version: str | None = None, trace_exporter_names: list[str] | None = None, metric_exporter_names: list[str] | None = None, diff --git a/opentelemetry-sdk/tests/test_configurator.py b/opentelemetry-sdk/tests/test_configurator.py index f607dacb856..03c90c907bc 100644 --- a/opentelemetry-sdk/tests/test_configurator.py +++ b/opentelemetry-sdk/tests/test_configurator.py @@ -435,13 +435,15 @@ def test_trace_init_custom_id_generator(self, mock_entry_points): ) @patch("opentelemetry.sdk._configuration.entry_points") def test_that_session_gets_passed_to_exporter(self, mock_entry_points): - # Should not be used, trace specific version should override. - session_for_all_signals = Session() + # Should not be used, metric specific version should override. session_for_metrics_only = Session() + session_for_all_signals = Session() + + def f(): + return session_for_metrics_only + mock_entry_points.configure_mock( - return_value=[ - IterEntryPoint("custom_session", session_for_metrics_only) - ] + return_value=[IterEntryPoint("custom_session", f)] ) exporter = _init_exporter( "metrics", @@ -464,12 +466,14 @@ def test_that_session_gets_passed_to_exporter(self, mock_entry_points): @patch("opentelemetry.sdk._configuration.entry_points") def test_that_credential_gets_passed_to_exporter(self, mock_entry_points): # Should not be used, trace specific version should override. + credential_for_traces_only = ChannelCredentials(None) credential_for_all_signals = ChannelCredentials(None) - credential_for_trace_only = ChannelCredentials(None) + + def f(): + return credential_for_traces_only + mock_entry_points.configure_mock( - return_value=[ - IterEntryPoint("custom_credential", credential_for_trace_only) - ] + return_value=[IterEntryPoint("custom_credential", f)] ) exporter = _init_exporter( "traces", @@ -477,7 +481,7 @@ def test_that_credential_gets_passed_to_exporter(self, mock_entry_points): OTLPSpanExporter, otlp_credential_param_for_all_signal_types=credential_for_all_signals, ) - assert exporter.credentials is credential_for_trace_only + assert exporter.credentials is credential_for_traces_only assert exporter.credentials is not credential_for_all_signals @patch.dict( diff --git a/tox.ini b/tox.ini index b2b1dae85e2..27171eb0b79 100644 --- a/tox.ini +++ b/tox.ini @@ -342,11 +342,14 @@ deps = -c {toxinidir}/dev-requirements.txt pyright psutil + requests + grpcio -e {toxinidir}/opentelemetry-api -e {toxinidir}/opentelemetry-semantic-conventions -e {toxinidir}/opentelemetry-sdk -e {toxinidir}/tests/opentelemetry-test-utils commands = + pip freeze pyright --version pyright From fcadee22e52d9f93237d56a14dccb1dd3d4cb729 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Wed, 13 Aug 2025 14:48:52 +0000 Subject: [PATCH 12/33] Add test --- opentelemetry-sdk/tests/test_configurator.py | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/opentelemetry-sdk/tests/test_configurator.py b/opentelemetry-sdk/tests/test_configurator.py index 03c90c907bc..35154dcdc30 100644 --- a/opentelemetry-sdk/tests/test_configurator.py +++ b/opentelemetry-sdk/tests/test_configurator.py @@ -484,6 +484,30 @@ def f(): assert exporter.credentials is credential_for_traces_only assert exporter.credentials is not credential_for_all_signals + @patch.dict( + environ, + { + OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER: "custom_credential" + }, + ) + @patch("opentelemetry.sdk._configuration.entry_points") + def test_that_invalid_credential_type_raises_exception( + self, mock_entry_points + ): + def f(): + # Entry point must return a grpc.ChannelCredential or requests.Session. + return 32 + + mock_entry_points.configure_mock( + return_value=[IterEntryPoint("custom_credential", f)] + ) + with raises(RuntimeError): + _init_exporter( + "traces", + {}, + OTLPSpanExporter, + ) + @patch.dict( "os.environ", {OTEL_TRACES_SAMPLER: "non_existent_entry_point"} ) From 6c2740a9d268517e6738af7e4fa5136657bf7b27 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Wed, 13 Aug 2025 15:03:41 +0000 Subject: [PATCH 13/33] fix envvar and typecheck --- .../src/opentelemetry/sdk/_configuration/__init__.py | 4 ++-- .../src/opentelemetry/sdk/environment_variables/__init__.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py index 9381dd9a705..99f2f1e58f6 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py @@ -153,10 +153,10 @@ def _load_credential_from_envvar( credentials = _import_config_component( credential_env, "opentelemetry_otlp_credential_provider" )() - if _GRPC_IMPORTED and isinstance(credentials, ChannelCredentials): + if _GRPC_IMPORTED and isinstance(credentials, ChannelCredentials): # type: ignore[reportPossiblyUnboundVariable] return ("credentials", credentials) - if _REQUESTS_IMPORTED and isinstance(credentials, Session): + if _REQUESTS_IMPORTED and isinstance(credentials, Session): # type: ignore[reportPossiblyUnboundVariable] return ("session", credentials) raise RuntimeError( f"{credential_env} is neither a grpc.ChannelCredentials or requests.Session type." diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py index a1ccb67f26a..5874bc1a7ee 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py @@ -398,7 +398,7 @@ "OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER" ) """ -.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER +.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER` provides either ChannelCredentials for grpc OTLP Log exporters, or request.Session for HTTP Log exporters. @@ -416,7 +416,7 @@ "OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER" ) """ -.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER +.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER` provides either ChannelCredentials for grpc OTLP Span exporters, or request.Session for HTTP Span exporters. @@ -425,7 +425,7 @@ "OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER" ) """ -.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER +.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER` provides either ChannelCredentials for grpc OTLP Metric exporters, or request.Session for HTTP Metric exporters. From 0dc2861a3e35904e72ffe8541651b83314ae6ba8 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Wed, 13 Aug 2025 15:14:06 +0000 Subject: [PATCH 14/33] Precommit and constraints --- dev-requirements.txt | 3 +-- .../src/opentelemetry/sdk/_configuration/__init__.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 5d6b19768ff..292ffbda483 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -17,5 +17,4 @@ psutil==5.9.6 GitPython==3.1.41 pre-commit==3.7.0; python_version >= '3.9' pre-commit==3.5.0; python_version < '3.9' -ruff==0.6.9 -grpcio==1.66.2 +ruff==0.6.9 \ No newline at end of file diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py index 99f2f1e58f6..a6a7c031e85 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py @@ -153,10 +153,10 @@ def _load_credential_from_envvar( credentials = _import_config_component( credential_env, "opentelemetry_otlp_credential_provider" )() - if _GRPC_IMPORTED and isinstance(credentials, ChannelCredentials): # type: ignore[reportPossiblyUnboundVariable] + if _GRPC_IMPORTED and isinstance(credentials, ChannelCredentials): # type: ignore[reportPossiblyUnboundVariable] return ("credentials", credentials) - if _REQUESTS_IMPORTED and isinstance(credentials, Session): # type: ignore[reportPossiblyUnboundVariable] + if _REQUESTS_IMPORTED and isinstance(credentials, Session): # type: ignore[reportPossiblyUnboundVariable] return ("session", credentials) raise RuntimeError( f"{credential_env} is neither a grpc.ChannelCredentials or requests.Session type." From 99a55d48e0ba3aa0e1688c90e67e6025ff1905d3 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Mon, 25 Aug 2025 18:39:06 +0000 Subject: [PATCH 15/33] Move change to exporter --- .../exporter/otlp/proto/grpc/__init__.py | 1 + .../otlp/proto/grpc/_log_exporter/__init__.py | 2 + .../exporter/otlp/proto/grpc/exporter.py | 26 ++- .../proto/grpc/metric_exporter/__init__.py | 2 + .../proto/grpc/trace_exporter/__init__.py | 2 + .../tests/test_otlp_exporter_mixin.py | 29 +++- .../otlp/proto/http/_common/__init__.py | 44 +++++ .../otlp/proto/http/_log_exporter/__init__.py | 5 +- .../proto/http/metric_exporter/__init__.py | 7 +- .../proto/http/trace_exporter/__init__.py | 7 +- .../metrics/test_otlp_metrics_exporter.py | 22 ++- .../tests/test_proto_log_exporter.py | 34 +++- .../tests/test_proto_span_exporter.py | 24 ++- .../sdk/_configuration/__init__.py | 160 +----------------- opentelemetry-sdk/test-requirements.txt | 2 - opentelemetry-sdk/tests/test_configurator.py | 119 +------------ tox.ini | 3 - 17 files changed, 207 insertions(+), 282 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py index 12275ef481a..cf257a902c1 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py @@ -29,6 +29,7 @@ - :envvar:`OTEL_EXPORTER_OTLP_TRACES_HEADERS` - :envvar:`OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` - :envvar:`OTEL_EXPORTER_OTLP_TRACES_COMPRESSION` +- :envvar:`OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER` - :envvar:`OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE` - :envvar:`OTEL_EXPORTER_OTLP_TIMEOUT` - :envvar:`OTEL_EXPORTER_OTLP_PROTOCOL` diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py index 70f3df444a4..ba467f98ba5 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py @@ -40,6 +40,7 @@ OTEL_EXPORTER_OTLP_LOGS_HEADERS, OTEL_EXPORTER_OTLP_LOGS_INSECURE, OTEL_EXPORTER_OTLP_LOGS_TIMEOUT, + OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, ) @@ -73,6 +74,7 @@ def __init__( ): credentials = _get_credentials( credentials, + OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE, OTEL_EXPORTER_OTLP_LOGS_CLIENT_KEY, OTEL_EXPORTER_OTLP_LOGS_CLIENT_CERTIFICATE, diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py index 6791062d5dc..cfec3d0ec44 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py @@ -68,10 +68,12 @@ OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_INSECURE, OTEL_EXPORTER_OTLP_TIMEOUT, + OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.metrics.export import MetricsData from opentelemetry.sdk.resources import Resource as SDKResource from opentelemetry.sdk.trace import ReadableSpan +from opentelemetry.util._importlib_metadata import entry_points from opentelemetry.util.re import parse_env_headers _RETRYABLE_ERROR_CODES = frozenset( @@ -166,12 +168,31 @@ def _load_credentials( def _get_credentials( creds: Optional[ChannelCredentials], + credential_entry_point_env_key: str, certificate_file_env_key: str, client_key_file_env_key: str, client_certificate_file_env_key: str, ) -> ChannelCredentials: if creds is not None: return creds + credential_env = environ.get(credential_entry_point_env_key) + if credential_env: + try: + maybe_channel_creds = next( + iter( + entry_points( + group="opentelemetry_otlp_credential_provider", + name=credential_env, + ) + ) + ).load()("GRPC") + except StopIteration: + raise RuntimeError( + f"Requested component '{credential_env}' not found in " + f"entry point 'opentelemetry_otlp_credential_provider'" + ) + if isinstance(maybe_channel_creds, ChannelCredentials): + return maybe_channel_creds certificate_file = environ.get(certificate_file_env_key) if certificate_file: @@ -275,15 +296,16 @@ def __init__( options=self._channel_options, ) else: - credentials = _get_credentials( + self._credentials = _get_credentials( credentials, + OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_KEY, OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, ) self._channel = secure_channel( self._endpoint, - credentials, + self._credentials, compression=compression, options=self._channel_options, ) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py index d1bfa4de94b..5b5f4da17f0 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py @@ -51,6 +51,7 @@ OTEL_EXPORTER_OTLP_METRICS_HEADERS, OTEL_EXPORTER_OTLP_METRICS_INSECURE, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT, + OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.metrics._internal.aggregation import Aggregation from opentelemetry.sdk.metrics.export import ( # noqa: F401 @@ -118,6 +119,7 @@ def __init__( ): credentials = _get_credentials( credentials, + OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE, OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEY, OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE, diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py index 0dbdb22bc50..a8180c8dfe7 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py @@ -54,6 +54,7 @@ OTEL_EXPORTER_OTLP_TRACES_HEADERS, OTEL_EXPORTER_OTLP_TRACES_INSECURE, OTEL_EXPORTER_OTLP_TRACES_TIMEOUT, + OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.trace import ReadableSpan from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult @@ -106,6 +107,7 @@ def __init__( ): credentials = _get_credentials( credentials, + OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE, OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY, OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE, diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py index aef52fbc4a7..5bfba40ae84 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py @@ -28,7 +28,7 @@ from google.rpc.error_details_pb2 import ( # pylint: disable=no-name-in-module RetryInfo, ) -from grpc import Compression, StatusCode, server +from grpc import ChannelCredentials, Compression, StatusCode, server from opentelemetry.exporter.otlp.proto.common.trace_encoder import ( encode_spans, @@ -50,6 +50,7 @@ ) from opentelemetry.sdk.environment_variables import ( OTEL_EXPORTER_OTLP_COMPRESSION, + OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.trace import ReadableSpan, _Span from opentelemetry.sdk.trace.export import ( @@ -60,6 +61,15 @@ logger = getLogger(__name__) +class IterEntryPoint: + def __init__(self, name, class_type): + self.name = name + self.class_type = class_type + + def load(self): + return self.class_type + + # The below tests use this test SpanExporter and Spans, but are testing the # underlying behavior in the mixin. A MetricExporter or LogExporter could # just as easily be used. @@ -276,6 +286,23 @@ def test_otlp_exporter_otlp_compression_unspecified( ), ) + @patch.dict( + "os.environ", + {OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER: "credential_provider"}, + ) + @patch("opentelemetry.exporter.otlp.proto.grpc.exporter.entry_points") + def test_that_credential_gets_passed_to_exporter(self, mock_entry_points): + credential = ChannelCredentials(None) + + def f(_): + return credential + + mock_entry_points.configure_mock( + return_value=[IterEntryPoint("custom_credential", f)] + ) + exporter = OTLPSpanExporterForTesting(insecure=False) + assert exporter._credentials is credential + # pylint: disable=no-self-use, disable=unused-argument @patch( "opentelemetry.exporter.otlp.proto.grpc.exporter.ssl_channel_credentials" diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py index b1ed46d28b7..8d43ac59f98 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py @@ -12,8 +12,19 @@ # See the License for the specific language governing permissions and # limitations under the License. +from os import environ +from typing import Literal, Optional + import requests +from opentelemetry.sdk.environment_variables import ( + OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, +) +from opentelemetry.util._importlib_metadata import entry_points + def _is_retryable(resp: requests.Response) -> bool: if resp.status_code == 408: @@ -21,3 +32,36 @@ def _is_retryable(resp: requests.Response) -> bool: if resp.status_code >= 500 and resp.status_code <= 599: return True return False + + +def _load_session_from_envvar( + exporter_type: Literal["logs", "traces", "metrics"], +) -> Optional[requests.Session]: + if exporter_type == "logs": + env_var = OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER + elif exporter_type == "traces": + env_var = OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER + else: + env_var = OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER + credential_env = environ.get( + OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER + ) or environ.get(env_var) + if credential_env: + try: + maybe_session = next( + iter( + entry_points( + group="opentelemetry_otlp_credential_provider", + name=credential_env, + ) + ) + ).load()("HTTP") + except StopIteration: + raise RuntimeError( + f"Requested component '{credential_env}' not found in " + f"entry point 'opentelemetry_otlp_credential_provider'" + ) + if isinstance(maybe_session, requests.Session): + print("returning session !!") + return maybe_session + return None diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py index 765bc5c7f5b..7d0a64cbe8b 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py @@ -32,6 +32,7 @@ ) from opentelemetry.exporter.otlp.proto.http._common import ( _is_retryable, + _load_session_from_envvar, ) from opentelemetry.sdk._logs import LogData from opentelemetry.sdk._logs.export import ( @@ -117,7 +118,9 @@ def __init__( ) ) self._compression = compression or _compression_from_env() - self._session = session or requests.Session() + self._session = ( + session or _load_session_from_envvar("logs") or requests.Session() + ) self._session.headers.update(self._headers) self._session.headers.update(_OTLP_HTTP_HEADERS) if self._compression is not Compression.NoCompression: diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py index 3b7079f7fc2..51e51398f6a 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py @@ -49,6 +49,7 @@ ) from opentelemetry.exporter.otlp.proto.http._common import ( _is_retryable, + _load_session_from_envvar, ) from opentelemetry.proto.collector.metrics.v1.metrics_service_pb2 import ( # noqa: F401 ExportMetricsServiceRequest, @@ -159,7 +160,11 @@ def __init__( ) ) self._compression = compression or _compression_from_env() - self._session = session or requests.Session() + self._session = ( + session + or _load_session_from_envvar("metrics") + or requests.Session() + ) self._session.headers.update(self._headers) self._session.headers.update(_OTLP_HTTP_HEADERS) if self._compression is not Compression.NoCompression: 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 8ea73d4c0f9..95810e776da 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 @@ -34,6 +34,7 @@ ) from opentelemetry.exporter.otlp.proto.http._common import ( _is_retryable, + _load_session_from_envvar, ) from opentelemetry.sdk.environment_variables import ( OTEL_EXPORTER_OTLP_CERTIFICATE, @@ -115,7 +116,11 @@ def __init__( ) ) self._compression = compression or _compression_from_env() - self._session = session or requests.Session() + self._session = ( + session + or _load_session_from_envvar("traces") + or requests.Session() + ) self._session.headers.update(self._headers) self._session.headers.update(_OTLP_HTTP_HEADERS) if self._compression is not Compression.NoCompression: diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py index 815761397ea..e8a21292998 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py @@ -51,6 +51,7 @@ OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT, OTEL_EXPORTER_OTLP_TIMEOUT, + OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.metrics import ( Counter, @@ -85,6 +86,15 @@ OS_ENV_TIMEOUT = "30" +class IterEntryPoint: + def __init__(self, name, class_type): + self.name = name + self.class_type = class_type + + def load(self): + return self.class_type + + # pylint: disable=protected-access class TestOTLPMetricExporter(TestCase): def setUp(self): @@ -153,9 +163,19 @@ def test_constructor_default(self): OTEL_EXPORTER_OTLP_METRICS_ENDPOINT: "https://metrics.endpoint.env", OTEL_EXPORTER_OTLP_METRICS_HEADERS: "metricsEnv1=val1,metricsEnv2=val2,metricEnv3===val3==", OTEL_EXPORTER_OTLP_METRICS_TIMEOUT: "40", + OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER: "credential_provider", }, ) - def test_exporter_metrics_env_take_priority(self): + @patch("opentelemetry.exporter.otlp.proto.http._common.entry_points") + def test_exporter_metrics_env_take_priority(self, mock_entry_points): + credential = Session() + + def f(_): + return credential + + mock_entry_points.configure_mock( + return_value=[IterEntryPoint("custom_credential", f)] + ) exporter = OTLPMetricExporter() self.assertEqual(exporter._endpoint, "https://metrics.endpoint.env") diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py index 19183029edc..9d3b4b249c4 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py @@ -57,6 +57,7 @@ OTEL_EXPORTER_OTLP_LOGS_HEADERS, OTEL_EXPORTER_OTLP_LOGS_TIMEOUT, OTEL_EXPORTER_OTLP_TIMEOUT, + OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.resources import Resource as SDKResource from opentelemetry.sdk.util.instrumentation import InstrumentationScope @@ -67,6 +68,16 @@ set_span_in_context, ) + +class IterEntryPoint: + def __init__(self, name, class_type): + self.name = name + self.class_type = class_type + + def load(self): + return self.class_type + + ENV_ENDPOINT = "http://localhost.env:8080/" ENV_CERTIFICATE = "/etc/base.crt" ENV_CLIENT_CERTIFICATE = "/etc/client-cert.pem" @@ -116,9 +127,19 @@ def test_constructor_default(self): OTEL_EXPORTER_OTLP_LOGS_ENDPOINT: "https://logs.endpoint.env", OTEL_EXPORTER_OTLP_LOGS_HEADERS: "logsEnv1=val1,logsEnv2=val2,logsEnv3===val3==", OTEL_EXPORTER_OTLP_LOGS_TIMEOUT: "40", + OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER: "credential_provider", }, ) - def test_exporter_metrics_env_take_priority(self): + @patch("opentelemetry.exporter.otlp.proto.http._common.entry_points") + def test_exporter_logs_env_take_priority(self, mock_entry_points): + credential = Session() + + def f(_): + return credential + + mock_entry_points.configure_mock( + return_value=[IterEntryPoint("custom_credential", f)] + ) exporter = OTLPLogExporter() self.assertEqual(exporter._endpoint, "https://logs.endpoint.env") @@ -137,8 +158,19 @@ def test_exporter_metrics_env_take_priority(self): "logsenv3": "==val3==", }, ) + self.assertIs(exporter._session, credential) self.assertIsInstance(exporter._session, requests.Session) + @patch.dict( + "os.environ", + { + OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER: "provider_without_entry_point", + }, + ) + def test_exception_raised_when_entrypoint_does_not_exist(self): + with self.assertRaises(RuntimeError): + OTLPLogExporter() + @patch.dict( "os.environ", { 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 224227a7f59..61334534ead 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 @@ -46,10 +46,21 @@ OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_HEADERS, OTEL_EXPORTER_OTLP_TRACES_TIMEOUT, + OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.trace import _Span from opentelemetry.sdk.trace.export import SpanExportResult + +class IterEntryPoint: + def __init__(self, name, class_type): + self.name = name + self.class_type = class_type + + def load(self): + return self.class_type + + OS_ENV_ENDPOINT = "os.env.base" OS_ENV_CERTIFICATE = "os/env/base.crt" OS_ENV_CLIENT_CERTIFICATE = "os/env/client-cert.pem" @@ -110,9 +121,19 @@ def test_constructor_default(self): OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: "https://traces.endpoint.env", OTEL_EXPORTER_OTLP_TRACES_HEADERS: "tracesEnv1=val1,tracesEnv2=val2,traceEnv3===val3==", OTEL_EXPORTER_OTLP_TRACES_TIMEOUT: "40", + OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER: "credential_provider", }, ) - def test_exporter_traces_env_take_priority(self): + @patch("opentelemetry.exporter.otlp.proto.http._common.entry_points") + def test_exporter_traces_env_take_priority(self, mock_entry_point): + credential = Session() + + def f(_): + return credential + + mock_entry_point.configure_mock( + return_value=[IterEntryPoint("custom_credential", f)] + ) exporter = OTLPSpanExporter() self.assertEqual(exporter._endpoint, "https://traces.endpoint.env") @@ -131,6 +152,7 @@ def test_exporter_traces_env_take_priority(self): "traceenv3": "==val3==", }, ) + self.assertIs(exporter._session, credential) self.assertIsInstance(exporter._session, requests.Session) @patch.dict( diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py index a6a7c031e85..60640739e3b 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py @@ -19,23 +19,12 @@ from __future__ import annotations -import inspect import logging import logging.config import os from abc import ABC, abstractmethod from os import environ -from typing import ( - Any, - Callable, - Mapping, - MutableMapping, - Optional, - Sequence, - Type, - TypeVar, - Union, -) +from typing import Any, Callable, Mapping, Sequence, Type, Union from typing_extensions import Literal @@ -57,10 +46,6 @@ OTEL_EXPORTER_OTLP_METRICS_PROTOCOL, OTEL_EXPORTER_OTLP_PROTOCOL, OTEL_EXPORTER_OTLP_TRACES_PROTOCOL, - OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER, - OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, - OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, - OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, OTEL_TRACES_SAMPLER, OTEL_TRACES_SAMPLER_ARG, ) @@ -79,22 +64,6 @@ from opentelemetry.trace import set_tracer_provider from opentelemetry.util._importlib_metadata import entry_points -try: - from grpc import ChannelCredentials - - _GRPC_IMPORTED = True -except ImportError: - _GRPC_IMPORTED = False - -try: - from requests import Session - - _REQUESTS_IMPORTED = True -except ImportError: - _REQUESTS_IMPORTED = False - -T = TypeVar("T") - _EXPORTER_OTLP = "otlp" _EXPORTER_OTLP_PROTO_GRPC = "otlp_proto_grpc" _EXPORTER_OTLP_PROTO_HTTP = "otlp_proto_http" @@ -110,12 +79,6 @@ "logs": OTEL_LOGS_EXPORTER, } -_EXPORTER_CREDENTIAL_BY_SIGNAL_TYPE = { - "traces": OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, - "metrics": OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, - "logs": OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, -} - _PROTOCOL_ENV_BY_SIGNAL_TYPE = { "traces": OTEL_EXPORTER_OTLP_TRACES_PROTOCOL, "metrics": OTEL_EXPORTER_OTLP_METRICS_PROTOCOL, @@ -136,42 +99,10 @@ Type[MetricReader], Type[LogExporter], ], - MutableMapping[str, Any], + Mapping[str, Any], ] -def _load_credential_from_envvar( - environment_variable: str, -) -> Optional[ - tuple[ - Literal["credentials", "session"], - Union["ChannelCredentials", "Session"], - ] -]: - credential_env = os.getenv(environment_variable) - if credential_env: - credentials = _import_config_component( - credential_env, "opentelemetry_otlp_credential_provider" - )() - if _GRPC_IMPORTED and isinstance(credentials, ChannelCredentials): # type: ignore[reportPossiblyUnboundVariable] - return ("credentials", credentials) - - if _REQUESTS_IMPORTED and isinstance(credentials, Session): # type: ignore[reportPossiblyUnboundVariable] - return ("session", credentials) - raise RuntimeError( - f"{credential_env} is neither a grpc.ChannelCredentials or requests.Session type." - ) - return None - - -def _import_config_component( - selected_component: str, entry_point_name: str -) -> Type: - return _import_config_components([selected_component], entry_point_name)[ - 0 - ][1] - - def _import_config_components( selected_components: Sequence[str], entry_point_name: str ) -> list[tuple[str, Type]]: @@ -271,50 +202,12 @@ def _get_exporter_names( ] -def _init_exporter( - signal_type: Literal["traces", "metrics", "logs"], - exporter_args: MutableMapping[str, Any], - exporter_class: Type[T], - otlp_credential_param_for_all_signal_types: Optional[ - tuple[ - Literal["credentials", "session"], - Union["ChannelCredentials", "Session"], - ] - ] = None, -) -> T: - # Per signal type envvar should take precedence over all signal type env var. - otlp_credential_param = ( - _load_credential_from_envvar( - _EXPORTER_CREDENTIAL_BY_SIGNAL_TYPE[signal_type] - ) - or otlp_credential_param_for_all_signal_types - ) - if otlp_credential_param: - credential_key, credential = otlp_credential_param - # We only want to inject credentials into the appropriate OTLP HTTP // GRPC exporters. - if credential_key in inspect.signature( - exporter_class.__init__ - ).parameters and ( - "opentelemetry.exporter.otlp.proto.http" in str(exporter_class) - or "opentelemetry.exporter.otlp.proto.grpc" in str(exporter_class) - or "tests.test_configurator" in str(exporter_class) - ): - exporter_args[credential_key] = credential - return exporter_class(**exporter_args) - - def _init_tracing( exporters: dict[str, Type[SpanExporter]], id_generator: IdGenerator | None = None, sampler: Sampler | None = None, resource: Resource | None = None, exporter_args_map: ExporterArgsMap | None = None, - otlp_credential_param: Optional[ - tuple[ - Literal["credentials", "session"], - Union["ChannelCredentials", "Session"], - ] - ] = None, ): provider = TracerProvider( id_generator=id_generator, @@ -327,14 +220,7 @@ def _init_tracing( for _, exporter_class in exporters.items(): exporter_args = exporter_args_map.get(exporter_class, {}) provider.add_span_processor( - BatchSpanProcessor( - _init_exporter( - "traces", - exporter_args, - exporter_class, - otlp_credential_param, - ) - ) + BatchSpanProcessor(exporter_class(**exporter_args)) ) @@ -344,12 +230,6 @@ def _init_metrics( ], resource: Resource | None = None, exporter_args_map: ExporterArgsMap | None = None, - otlp_credential_param: Optional[ - tuple[ - Literal["credentials", "session"], - Union["ChannelCredentials", "Session"], - ] - ] = None, ): metric_readers = [] @@ -361,12 +241,7 @@ def _init_metrics( else: metric_readers.append( PeriodicExportingMetricReader( - _init_exporter( - "metrics", - exporter_args, - exporter_or_reader_class, - otlp_credential_param, - ) + exporter_or_reader_class(**exporter_args) ) ) @@ -379,12 +254,6 @@ def _init_logging( resource: Resource | None = None, setup_logging_handler: bool = True, exporter_args_map: ExporterArgsMap | None = None, - otlp_credential_param: Optional[ - tuple[ - Literal["credentials", "session"], - Union["ChannelCredentials", "Session"], - ] - ] = None, ): provider = LoggerProvider(resource=resource) set_logger_provider(provider) @@ -393,14 +262,7 @@ def _init_logging( for _, exporter_class in exporters.items(): exporter_args = exporter_args_map.get(exporter_class, {}) provider.add_log_record_processor( - BatchLogRecordProcessor( - _init_exporter( - "logs", - exporter_args, - exporter_class, - otlp_credential_param, - ) - ) + BatchLogRecordProcessor(exporter_class(**exporter_args)) ) event_logger_provider = EventLoggerProvider(logger_provider=provider) @@ -544,7 +406,7 @@ def _import_id_generator(id_generator_name: str) -> IdGenerator: raise RuntimeError(f"{id_generator_name} is not an IdGenerator") -def _initialize_components( # pylint: disable=too-many-locals +def _initialize_components( auto_instrumentation_version: str | None = None, trace_exporter_names: list[str] | None = None, metric_exporter_names: list[str] | None = None, @@ -583,22 +445,15 @@ def _initialize_components( # pylint: disable=too-many-locals # from the env variable else defaults to "unknown_service" resource = Resource.create(resource_attributes) - otlp_credential_param = _load_credential_from_envvar( - OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER - ) _init_tracing( exporters=span_exporters, id_generator=id_generator, sampler=sampler, resource=resource, - otlp_credential_param=otlp_credential_param, exporter_args_map=exporter_args_map, ) _init_metrics( - metric_exporters, - resource, - otlp_credential_param=otlp_credential_param, - exporter_args_map=exporter_args_map, + metric_exporters, resource, exporter_args_map=exporter_args_map ) if setup_logging_handler is None: setup_logging_handler = ( @@ -613,7 +468,6 @@ def _initialize_components( # pylint: disable=too-many-locals log_exporters, resource, setup_logging_handler, - otlp_credential_param=otlp_credential_param, exporter_args_map=exporter_args_map, ) diff --git a/opentelemetry-sdk/test-requirements.txt b/opentelemetry-sdk/test-requirements.txt index a52e97a7f5a..859a2196e1a 100644 --- a/opentelemetry-sdk/test-requirements.txt +++ b/opentelemetry-sdk/test-requirements.txt @@ -9,8 +9,6 @@ py-cpuinfo==9.0.0 pytest==7.4.4 tomli==2.0.1 typing_extensions==4.10.0 -grpcio==1.66.2 -requests==2.32.3 wrapt==1.16.0 zipp==3.19.2 -e tests/opentelemetry-test-utils diff --git a/opentelemetry-sdk/tests/test_configurator.py b/opentelemetry-sdk/tests/test_configurator.py index 35154dcdc30..6e9221b124d 100644 --- a/opentelemetry-sdk/tests/test_configurator.py +++ b/opentelemetry-sdk/tests/test_configurator.py @@ -23,9 +23,7 @@ from unittest import TestCase, mock from unittest.mock import Mock, patch -from grpc import ChannelCredentials from pytest import raises -from requests import Session from opentelemetry import trace from opentelemetry.context import Context @@ -41,7 +39,6 @@ _import_exporters, _import_id_generator, _import_sampler, - _init_exporter, _init_logging, _init_metrics, _init_tracing, @@ -52,8 +49,6 @@ from opentelemetry.sdk._logs._internal.export import LogExporter from opentelemetry.sdk._logs.export import ConsoleLogExporter from opentelemetry.sdk.environment_variables import ( - OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, - OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, OTEL_TRACES_SAMPLER, OTEL_TRACES_SAMPLER_ARG, ) @@ -184,14 +179,7 @@ def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None: class DummyOTLPMetricExporter: - def __init__( - self, - compression: str | None = None, - session: Session | None = None, - *args, - **kwargs, - ): - self.session = session + def __init__(self, compression: str | None = None, *args, **kwargs): self.export_called = False self.compression = compression @@ -216,15 +204,8 @@ def shutdown(self): class OTLPSpanExporter: - def __init__( - self, - compression: str | None = None, - credentials: ChannelCredentials | None = None, - *args, - **kwargs, - ): + def __init__(self, compression: str | None = None, *args, **kwargs): self.compression = compression - self.credentials = credentials class DummyOTLPLogExporter(LogExporter): @@ -427,87 +408,6 @@ def test_trace_init_custom_id_generator(self, mock_entry_points): provider = self.set_provider_mock.call_args[0][0] self.assertIsInstance(provider.id_generator, CustomIdGenerator) - @patch.dict( - environ, - { - OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER: "custom_session" - }, - ) - @patch("opentelemetry.sdk._configuration.entry_points") - def test_that_session_gets_passed_to_exporter(self, mock_entry_points): - # Should not be used, metric specific version should override. - session_for_metrics_only = Session() - session_for_all_signals = Session() - - def f(): - return session_for_metrics_only - - mock_entry_points.configure_mock( - return_value=[IterEntryPoint("custom_session", f)] - ) - exporter = _init_exporter( - "metrics", - {}, - DummyOTLPMetricExporter, - otlp_credential_param_for_all_signal_types=( - "session", - session_for_all_signals, - ), - ) - assert exporter.session is session_for_metrics_only - assert exporter.session is not session_for_all_signals - - @patch.dict( - environ, - { - OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER: "custom_credential" - }, - ) - @patch("opentelemetry.sdk._configuration.entry_points") - def test_that_credential_gets_passed_to_exporter(self, mock_entry_points): - # Should not be used, trace specific version should override. - credential_for_traces_only = ChannelCredentials(None) - credential_for_all_signals = ChannelCredentials(None) - - def f(): - return credential_for_traces_only - - mock_entry_points.configure_mock( - return_value=[IterEntryPoint("custom_credential", f)] - ) - exporter = _init_exporter( - "traces", - {}, - OTLPSpanExporter, - otlp_credential_param_for_all_signal_types=credential_for_all_signals, - ) - assert exporter.credentials is credential_for_traces_only - assert exporter.credentials is not credential_for_all_signals - - @patch.dict( - environ, - { - OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER: "custom_credential" - }, - ) - @patch("opentelemetry.sdk._configuration.entry_points") - def test_that_invalid_credential_type_raises_exception( - self, mock_entry_points - ): - def f(): - # Entry point must return a grpc.ChannelCredential or requests.Session. - return 32 - - mock_entry_points.configure_mock( - return_value=[IterEntryPoint("custom_credential", f)] - ) - with raises(RuntimeError): - _init_exporter( - "traces", - {}, - OTLPSpanExporter, - ) - @patch.dict( "os.environ", {OTEL_TRACES_SAMPLER: "non_existent_entry_point"} ) @@ -838,11 +738,7 @@ def test_logging_init_disable_default(self, logging_mock, tracing_mock): _initialize_components(auto_instrumentation_version="auto-version") self.assertEqual(tracing_mock.call_count, 1) logging_mock.assert_called_once_with( - mock.ANY, - mock.ANY, - False, - otlp_credential_param=None, - exporter_args_map=None, + mock.ANY, mock.ANY, False, exporter_args_map=None ) @patch.dict( @@ -858,11 +754,7 @@ def test_logging_init_enable_env(self, logging_mock, tracing_mock): with self.assertLogs(level=WARNING): _initialize_components(auto_instrumentation_version="auto-version") logging_mock.assert_called_once_with( - mock.ANY, - mock.ANY, - True, - otlp_credential_param=None, - exporter_args_map=None, + mock.ANY, mock.ANY, True, exporter_args_map=None ) self.assertEqual(tracing_mock.call_count, 1) @@ -980,20 +872,17 @@ def test_initialize_components_kwargs( id_generator="TEST_GENERATOR", sampler="TEST_SAMPLER", resource="TEST_RESOURCE", - otlp_credential_param=None, exporter_args_map={1: {"compression": "gzip"}}, ) metrics_mock.assert_called_once_with( "TEST_METRICS_EXPORTERS_DICT", "TEST_RESOURCE", - otlp_credential_param=None, exporter_args_map={1: {"compression": "gzip"}}, ) logging_mock.assert_called_once_with( "TEST_LOG_EXPORTERS_DICT", "TEST_RESOURCE", True, - otlp_credential_param=None, exporter_args_map={1: {"compression": "gzip"}}, ) diff --git a/tox.ini b/tox.ini index 27171eb0b79..c311eba599a 100644 --- a/tox.ini +++ b/tox.ini @@ -303,7 +303,6 @@ changedir = tests/opentelemetry-docker-tests/tests commands_pre = - pip freeze docker-compose up -d commands = otlpexporter: pytest otlpexporter {posargs} @@ -342,8 +341,6 @@ deps = -c {toxinidir}/dev-requirements.txt pyright psutil - requests - grpcio -e {toxinidir}/opentelemetry-api -e {toxinidir}/opentelemetry-semantic-conventions -e {toxinidir}/opentelemetry-sdk From 9bf07a78d9979163c4dbff5a53fdadc3c81cf825 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Mon, 25 Aug 2025 19:06:29 +0000 Subject: [PATCH 16/33] Move common code to util. --- .../exporter/otlp/proto/http/_common/__init__.py | 10 ++++++++++ .../tests/metrics/test_otlp_metrics_exporter.py | 10 +--------- .../tests/test_proto_log_exporter.py | 11 +---------- .../tests/test_proto_span_exporter.py | 11 +---------- 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py index 8d43ac59f98..53bfc93275e 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py @@ -65,3 +65,13 @@ def _load_session_from_envvar( print("returning session !!") return maybe_session return None + + +# For testing +class IterEntryPoint: + def __init__(self, name, class_type): + self.name = name + self.class_type = class_type + + def load(self): + return self.class_type diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py index e8a21292998..72b4e32770b 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py @@ -26,6 +26,7 @@ encode_metrics, ) from opentelemetry.exporter.otlp.proto.http import Compression +from opentelemetry.exporter.otlp.proto.http._common import IterEntryPoint from opentelemetry.exporter.otlp.proto.http.metric_exporter import ( DEFAULT_COMPRESSION, DEFAULT_ENDPOINT, @@ -86,15 +87,6 @@ OS_ENV_TIMEOUT = "30" -class IterEntryPoint: - def __init__(self, name, class_type): - self.name = name - self.class_type = class_type - - def load(self): - return self.class_type - - # pylint: disable=protected-access class TestOTLPMetricExporter(TestCase): def setUp(self): diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py index 9d3b4b249c4..351cb06d906 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py @@ -28,6 +28,7 @@ from opentelemetry._logs import SeverityNumber from opentelemetry.exporter.otlp.proto.http import Compression +from opentelemetry.exporter.otlp.proto.http._common import IterEntryPoint from opentelemetry.exporter.otlp.proto.http._log_exporter import ( DEFAULT_COMPRESSION, DEFAULT_ENDPOINT, @@ -68,16 +69,6 @@ set_span_in_context, ) - -class IterEntryPoint: - def __init__(self, name, class_type): - self.name = name - self.class_type = class_type - - def load(self): - return self.class_type - - ENV_ENDPOINT = "http://localhost.env:8080/" ENV_CERTIFICATE = "/etc/base.crt" ENV_CLIENT_CERTIFICATE = "/etc/client-cert.pem" 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 61334534ead..7cff92e16db 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 @@ -23,6 +23,7 @@ from requests.models import Response from opentelemetry.exporter.otlp.proto.http import Compression +from opentelemetry.exporter.otlp.proto.http._common import IterEntryPoint from opentelemetry.exporter.otlp.proto.http.trace_exporter import ( DEFAULT_COMPRESSION, DEFAULT_ENDPOINT, @@ -51,16 +52,6 @@ from opentelemetry.sdk.trace import _Span from opentelemetry.sdk.trace.export import SpanExportResult - -class IterEntryPoint: - def __init__(self, name, class_type): - self.name = name - self.class_type = class_type - - def load(self): - return self.class_type - - OS_ENV_ENDPOINT = "os.env.base" OS_ENV_CERTIFICATE = "os/env/base.crt" OS_ENV_CLIENT_CERTIFICATE = "os/env/client-cert.pem" From 65f177b3bc913ae79e2b6dae81650c4c949e4a5b Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Tue, 2 Sep 2025 19:11:01 +0000 Subject: [PATCH 17/33] Fix lint err and print statment --- .../tests/test_otlp_exporter_mixin.py | 1 + .../opentelemetry/exporter/otlp/proto/http/_common/__init__.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py index 5bfba40ae84..429546a5d3e 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py @@ -301,6 +301,7 @@ def f(_): return_value=[IterEntryPoint("custom_credential", f)] ) exporter = OTLPSpanExporterForTesting(insecure=False) + # pylint: disable=protected-access assert exporter._credentials is credential # pylint: disable=no-self-use, disable=unused-argument diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py index 53bfc93275e..5fac8ba42b7 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py @@ -62,7 +62,6 @@ def _load_session_from_envvar( f"entry point 'opentelemetry_otlp_credential_provider'" ) if isinstance(maybe_session, requests.Session): - print("returning session !!") return maybe_session return None From efe5a945f59458a88bfa860e11c53c9c701d43e8 Mon Sep 17 00:00:00 2001 From: DylanRussell Date: Mon, 8 Sep 2025 14:49:01 +0000 Subject: [PATCH 18/33] Update opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py Co-authored-by: Aaron Abbott --- .../src/opentelemetry/sdk/environment_variables/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py index 5874bc1a7ee..9343be7df28 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py @@ -400,8 +400,8 @@ """ .. envvar:: OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER -The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER` provides either ChannelCredentials for grpc OTLP Log exporters, -or request.Session for HTTP Log exporters. +The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER` provides either `grpc.ChannelCredentials` for grpc OTLP Log exporters, +or `request.Session` for HTTP Log exporters. """ OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER" From 0b2129344d72e6ff92963651f1353056a07aa360 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Mon, 8 Sep 2025 15:52:12 +0000 Subject: [PATCH 19/33] Respond to comments --- .../otlp/proto/http/_common/__init__.py | 24 +++++-------------- .../otlp/proto/http/_log_exporter/__init__.py | 3 ++- .../proto/http/metric_exporter/__init__.py | 3 ++- .../proto/http/trace_exporter/__init__.py | 5 +++- .../tests/_common/__init__.py | 23 ++++++++++++++++++ .../metrics/test_otlp_metrics_exporter.py | 3 ++- .../tests/test_proto_log_exporter.py | 3 ++- .../tests/test_proto_span_exporter.py | 3 ++- tox.ini | 1 - 9 files changed, 43 insertions(+), 25 deletions(-) create mode 100644 exporter/opentelemetry-exporter-otlp-proto-http/tests/_common/__init__.py diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py index 5fac8ba42b7..b0ae6947425 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py @@ -35,17 +35,15 @@ def _is_retryable(resp: requests.Response) -> bool: def _load_session_from_envvar( - exporter_type: Literal["logs", "traces", "metrics"], + cred_envvar: Literal[ + OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, + ], ) -> Optional[requests.Session]: - if exporter_type == "logs": - env_var = OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER - elif exporter_type == "traces": - env_var = OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER - else: - env_var = OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER credential_env = environ.get( OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER - ) or environ.get(env_var) + ) or environ.get(cred_envvar) if credential_env: try: maybe_session = next( @@ -64,13 +62,3 @@ def _load_session_from_envvar( if isinstance(maybe_session, requests.Session): return maybe_session return None - - -# For testing -class IterEntryPoint: - def __init__(self, name, class_type): - self.name = name - self.class_type = class_type - - def load(self): - return self.class_type diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py index 93ba9c9cc27..e422e97dcc8 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py @@ -48,6 +48,7 @@ OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE, + OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_LOGS_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_LOGS_CLIENT_KEY, OTEL_EXPORTER_OTLP_LOGS_COMPRESSION, @@ -122,7 +123,7 @@ def __init__( ) self._compression = compression or _compression_from_env() self._session = ( - session or _load_session_from_envvar("logs") or requests.Session() + session or _load_session_from_envvar(OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER) or requests.Session() ) self._session.headers.update(self._headers) self._session.headers.update(_OTLP_HTTP_HEADERS) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py index 653192232a1..8f9eccd5a47 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py @@ -77,6 +77,7 @@ OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEY, OTEL_EXPORTER_OTLP_METRICS_COMPRESSION, + OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, OTEL_EXPORTER_OTLP_METRICS_HEADERS, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT, @@ -162,7 +163,7 @@ def __init__( self._compression = compression or _compression_from_env() self._session = ( session - or _load_session_from_envvar("metrics") + or _load_session_from_envvar(OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER) or requests.Session() ) self._session.headers.update(self._headers) 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 aa37e7c65d3..2366eacc08e 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 @@ -51,6 +51,7 @@ OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_HEADERS, OTEL_EXPORTER_OTLP_TRACES_TIMEOUT, + OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.trace import ReadableSpan from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult @@ -118,7 +119,9 @@ def __init__( self._compression = compression or _compression_from_env() self._session = ( session - or _load_session_from_envvar("traces") + or _load_session_from_envvar( + OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER + ) or requests.Session() ) self._session.headers.update(self._headers) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/_common/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/_common/__init__.py new file mode 100644 index 00000000000..f86a75cd7f4 --- /dev/null +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/_common/__init__.py @@ -0,0 +1,23 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# pylint: disable=protected-access + +class IterEntryPoint: + def __init__(self, name, class_type): + self.name = name + self.class_type = class_type + + def load(self): + return self.class_type \ No newline at end of file diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py index b8bd433b0df..4e82d15654a 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py @@ -26,7 +26,6 @@ encode_metrics, ) from opentelemetry.exporter.otlp.proto.http import Compression -from opentelemetry.exporter.otlp.proto.http._common import IterEntryPoint from opentelemetry.exporter.otlp.proto.http.metric_exporter import ( DEFAULT_COMPRESSION, DEFAULT_ENDPOINT, @@ -79,6 +78,8 @@ ) from opentelemetry.test.metrictestutil import _generate_sum +from .._common import IterEntryPoint + OS_ENV_ENDPOINT = "os.env.base" OS_ENV_CERTIFICATE = "os/env/base.crt" OS_ENV_CLIENT_CERTIFICATE = "os/env/client-cert.pem" diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py index 0dc8343171f..7110466b6ab 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py @@ -28,7 +28,6 @@ from opentelemetry._logs import SeverityNumber from opentelemetry.exporter.otlp.proto.http import Compression -from opentelemetry.exporter.otlp.proto.http._common import IterEntryPoint from opentelemetry.exporter.otlp.proto.http._log_exporter import ( DEFAULT_COMPRESSION, DEFAULT_ENDPOINT, @@ -69,6 +68,8 @@ set_span_in_context, ) +from ._common import IterEntryPoint + ENV_ENDPOINT = "http://localhost.env:8080/" ENV_CERTIFICATE = "/etc/base.crt" ENV_CLIENT_CERTIFICATE = "/etc/client-cert.pem" 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 d0bcdcf7399..a1e5666be1a 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 @@ -23,7 +23,6 @@ from requests.models import Response from opentelemetry.exporter.otlp.proto.http import Compression -from opentelemetry.exporter.otlp.proto.http._common import IterEntryPoint from opentelemetry.exporter.otlp.proto.http.trace_exporter import ( DEFAULT_COMPRESSION, DEFAULT_ENDPOINT, @@ -52,6 +51,8 @@ from opentelemetry.sdk.trace import _Span from opentelemetry.sdk.trace.export import SpanExportResult +from ._common import IterEntryPoint + OS_ENV_ENDPOINT = "os.env.base" OS_ENV_CERTIFICATE = "os/env/base.crt" OS_ENV_CLIENT_CERTIFICATE = "os/env/client-cert.pem" diff --git a/tox.ini b/tox.ini index c311eba599a..be8c11a1598 100644 --- a/tox.ini +++ b/tox.ini @@ -346,7 +346,6 @@ deps = -e {toxinidir}/opentelemetry-sdk -e {toxinidir}/tests/opentelemetry-test-utils commands = - pip freeze pyright --version pyright From 810ec49de530f952d21896d5f27e27d91a46337b Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Mon, 8 Sep 2025 15:52:44 +0000 Subject: [PATCH 20/33] Ruff --- .../exporter/otlp/proto/http/_log_exporter/__init__.py | 8 ++++++-- .../tests/_common/__init__.py | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py index e422e97dcc8..6d3d6c9841e 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py @@ -48,7 +48,6 @@ OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE, - OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_LOGS_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_LOGS_CLIENT_KEY, OTEL_EXPORTER_OTLP_LOGS_COMPRESSION, @@ -56,6 +55,7 @@ OTEL_EXPORTER_OTLP_LOGS_HEADERS, OTEL_EXPORTER_OTLP_LOGS_TIMEOUT, OTEL_EXPORTER_OTLP_TIMEOUT, + OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, ) from opentelemetry.util.re import parse_env_headers @@ -123,7 +123,11 @@ def __init__( ) self._compression = compression or _compression_from_env() self._session = ( - session or _load_session_from_envvar(OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER) or requests.Session() + session + or _load_session_from_envvar( + OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER + ) + or requests.Session() ) self._session.headers.update(self._headers) self._session.headers.update(_OTLP_HTTP_HEADERS) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/_common/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/_common/__init__.py index f86a75cd7f4..08801b68afd 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/_common/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/_common/__init__.py @@ -14,10 +14,11 @@ # pylint: disable=protected-access + class IterEntryPoint: def __init__(self, name, class_type): self.name = name self.class_type = class_type def load(self): - return self.class_type \ No newline at end of file + return self.class_type From 9b95dfa516fa9ec1a1593523583df660335ccd1a Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Mon, 8 Sep 2025 16:52:22 +0000 Subject: [PATCH 21/33] Document the entry points better --- .../proto/http/metric_exporter/__init__.py | 6 +- .../sdk/environment_variables/__init__.py | 56 ++++++++++++++++--- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py index 8f9eccd5a47..2f54c1857f1 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py @@ -77,11 +77,11 @@ OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEY, OTEL_EXPORTER_OTLP_METRICS_COMPRESSION, - OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, OTEL_EXPORTER_OTLP_METRICS_HEADERS, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT, OTEL_EXPORTER_OTLP_TIMEOUT, + OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.metrics._internal.aggregation import Aggregation from opentelemetry.sdk.metrics.export import ( # noqa: F401 @@ -163,7 +163,9 @@ def __init__( self._compression = compression or _compression_from_env() self._session = ( session - or _load_session_from_envvar(OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER) + or _load_session_from_envvar( + OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER + ) or requests.Session() ) self._session.headers.update(self._headers) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py index 9343be7df28..9b230873a90 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py @@ -400,8 +400,18 @@ """ .. envvar:: OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER -The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER` provides either `grpc.ChannelCredentials` for grpc OTLP Log exporters, -or `request.Session` for HTTP Log exporters. +The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER` provides either `grpc.ChannelCredentials` for the grpc OTLP Log exporter, +or `requests.Session` for the HTTP OTLP Log exporter. Entry point providers should implement the following functions: + +.. code-block:: python + import requests, grpc + + # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. + def request_session_provder() -> requests.Session: + + # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. + def channel_credential_provider() -> grpc.ChannelCredentials: + """ OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER" @@ -409,8 +419,18 @@ """ .. envvar:: OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER -The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER` provides either ChannelCredentials for all grpc OTLP exporters, -or request.Session for HTTP exporters. +The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER` provides either `grpc.ChannelCredentials` for all grpc OTLP exporters, +or `requests.Session` for all HTTP OTLP exporters. Entry point providers should implement the following functions: + +.. code-block:: python + import requests, grpc + + # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. + def request_session_provder() -> requests.Session: + + # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. + def channel_credential_provider() -> grpc.ChannelCredentials: + """ OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER" @@ -418,8 +438,18 @@ """ .. envvar:: OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER -The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER` provides either ChannelCredentials for grpc OTLP Span exporters, -or request.Session for HTTP Span exporters. +The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER` provides either `grpc.ChannelCredentials` for the grpc OTLP Span exporter, +or `requests.Session` for the HTTP OTLP Span exporter. Entry point providers should implement the following functions: + +.. code-block:: python + import requests, grpc + + # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. + def request_session_provder() -> requests.Session: + + # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. + def channel_credential_provider() -> grpc.ChannelCredentials: + """ OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER" @@ -427,8 +457,18 @@ """ .. envvar:: OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER -The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER` provides either ChannelCredentials for grpc OTLP Metric exporters, -or request.Session for HTTP Metric exporters. +The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER` provides either `grpc.ChannelCredentials` for the grpc OTLP Metric exporter, +or `requests.Session` for the HTTP OTLP Log exporter. Entry point providers should implement the following functions: + +.. code-block:: python + import requests, grpc + + # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. + def request_session_provder() -> requests.Session: + + # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. + def channel_credential_provider() -> grpc.ChannelCredentials: + """ OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE = "OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE" From 9934efe7cdee169db4bbfc4e476094a928125f89 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Mon, 8 Sep 2025 16:55:10 +0000 Subject: [PATCH 22/33] Going with factory function approach w/ 2 entry points --- .../src/opentelemetry/exporter/otlp/proto/grpc/exporter.py | 2 +- .../opentelemetry/exporter/otlp/proto/http/_common/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py index d046b9b7f58..dfe5b97b6c2 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py @@ -188,7 +188,7 @@ def _get_credentials( name=credential_env, ) ) - ).load()("GRPC") + ).load()() except StopIteration: raise RuntimeError( f"Requested component '{credential_env}' not found in " diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py index b0ae6947425..183b5cf26ed 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py @@ -53,7 +53,7 @@ def _load_session_from_envvar( name=credential_env, ) ) - ).load()("HTTP") + ).load()() except StopIteration: raise RuntimeError( f"Requested component '{credential_env}' not found in " From 24119fb1ebcafd2e83fc21a576ecbcd073ee67b2 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Mon, 8 Sep 2025 17:57:04 +0000 Subject: [PATCH 23/33] Add tests.. Fix tox.ini ? --- .../exporter/otlp/proto/grpc/exporter.py | 5 ++++ .../tests/test_otlp_exporter_mixin.py | 25 ++++++++++++++++++- .../otlp/proto/http/_common/__init__.py | 5 ++++ .../metrics/test_otlp_metrics_exporter.py | 2 +- .../tests/test_proto_log_exporter.py | 19 +++++++++++++- .../tests/test_proto_span_exporter.py | 2 +- tox.ini | 2 +- 7 files changed, 55 insertions(+), 5 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py index dfe5b97b6c2..d1cf3c88871 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py @@ -196,6 +196,11 @@ def _get_credentials( ) if isinstance(maybe_channel_creds, ChannelCredentials): return maybe_channel_creds + else: + raise RuntimeError( + f"Requested component '{credential_env}' is of type {type(maybe_channel_creds)}" + f" must be of type `grpc.ChannelCredentials`." + ) certificate_file = environ.get(certificate_file_env_key) if certificate_file: diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py index 429546a5d3e..a2c31bed319 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py @@ -294,7 +294,7 @@ def test_otlp_exporter_otlp_compression_unspecified( def test_that_credential_gets_passed_to_exporter(self, mock_entry_points): credential = ChannelCredentials(None) - def f(_): + def f(): return credential mock_entry_points.configure_mock( @@ -304,6 +304,29 @@ def f(_): # pylint: disable=protected-access assert exporter._credentials is credential + @patch.dict( + "os.environ", + {OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER: "credential_provider"}, + ) + def test_that_missing_entry_point_raises_exception(self): + with self.assertRaises(RuntimeError): + OTLPSpanExporterForTesting(insecure=False) + + @patch.dict( + "os.environ", + {OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER: "credential_provider"}, + ) + @patch("opentelemetry.exporter.otlp.proto.grpc.exporter.entry_points") + def test_that_entry_point_returning_bad_type_raises_exception(self, mock_entry_points): + def f(): + return 1 + + mock_entry_points.configure_mock( + return_value=[IterEntryPoint("custom_credential", f)] + ) + with self.assertRaises(RuntimeError): + OTLPSpanExporterForTesting(insecure=False) + # pylint: disable=no-self-use, disable=unused-argument @patch( "opentelemetry.exporter.otlp.proto.grpc.exporter.ssl_channel_credentials" diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py index 183b5cf26ed..4c4b9aa50da 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py @@ -61,4 +61,9 @@ def _load_session_from_envvar( ) if isinstance(maybe_session, requests.Session): return maybe_session + else: + raise RuntimeError( + f"Requested component '{credential_env}' is of type {type(maybe_session)}" + f" must be of type `requests.Session`." + ) return None diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py index 4e82d15654a..c4e8721a7c8 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py @@ -163,7 +163,7 @@ def test_constructor_default(self): def test_exporter_metrics_env_take_priority(self, mock_entry_points): credential = Session() - def f(_): + def f(): return credential mock_entry_points.configure_mock( diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py index 7110466b6ab..f50198d60b6 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py @@ -126,7 +126,7 @@ def test_constructor_default(self): def test_exporter_logs_env_take_priority(self, mock_entry_points): credential = Session() - def f(_): + def f(): return credential mock_entry_points.configure_mock( @@ -162,6 +162,23 @@ def f(_): "application/x-protobuf", ) + + @patch.dict( + "os.environ", + { + OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER: "provider_without_entry_point", + }, + ) + @patch("opentelemetry.exporter.otlp.proto.http._common.entry_points") + def test_exception_raised_when_entrypoint_returns_wrong_type(self, mock_entry_points): + def f(): + return 1 + mock_entry_points.configure_mock( + return_value=[IterEntryPoint("custom_credential", f)] + ) + with self.assertRaises(RuntimeError): + OTLPLogExporter() + @patch.dict( "os.environ", { 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 a1e5666be1a..934c3782d32 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 @@ -120,7 +120,7 @@ def test_constructor_default(self): def test_exporter_traces_env_take_priority(self, mock_entry_point): credential = Session() - def f(_): + def f(): return credential mock_entry_point.configure_mock( diff --git a/tox.ini b/tox.ini index be8c11a1598..0b9247719e2 100644 --- a/tox.ini +++ b/tox.ini @@ -153,7 +153,7 @@ deps = getting-started: {env:CONTRIB_REPO}\#egg=opentelemetry-instrumentation-wsgi&subdirectory=instrumentation/opentelemetry-instrumentation-wsgi getting-started: {env:CONTRIB_REPO}\#egg=opentelemetry-instrumentation-flask&subdirectory=instrumentation/opentelemetry-instrumentation-flask -allowlist_externals = sh +allowlist_externals = sh, pytest setenv = ; override CONTRIB_REPO_SHA via env variable when testing other branches/commits than main From 813c11cc05c1a82434da9951f08e78ac2cf5afda Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Mon, 8 Sep 2025 18:43:48 +0000 Subject: [PATCH 24/33] Add http/grpc env var variants --- .../otlp/proto/grpc/_log_exporter/__init__.py | 4 +- .../exporter/otlp/proto/grpc/exporter.py | 4 +- .../proto/grpc/metric_exporter/__init__.py | 4 +- .../proto/grpc/trace_exporter/__init__.py | 4 +- .../tests/test_otlp_exporter_mixin.py | 18 ++- .../otlp/proto/http/_common/__init__.py | 16 +-- .../otlp/proto/http/_log_exporter/__init__.py | 4 +- .../proto/http/metric_exporter/__init__.py | 4 +- .../proto/http/trace_exporter/__init__.py | 4 +- .../metrics/test_otlp_metrics_exporter.py | 4 +- .../tests/test_proto_log_exporter.py | 14 ++- .../tests/test_proto_span_exporter.py | 4 +- .../sdk/environment_variables/__init__.py | 113 ++++++++++++++---- 13 files changed, 134 insertions(+), 63 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py index ba467f98ba5..b1ceeb536b9 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py @@ -40,7 +40,7 @@ OTEL_EXPORTER_OTLP_LOGS_HEADERS, OTEL_EXPORTER_OTLP_LOGS_INSECURE, OTEL_EXPORTER_OTLP_LOGS_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_GRPC_LOGS_CREDENTIAL_PROVIDER, ) @@ -74,7 +74,7 @@ def __init__( ): credentials = _get_credentials( credentials, - OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_GRPC_LOGS_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE, OTEL_EXPORTER_OTLP_LOGS_CLIENT_KEY, OTEL_EXPORTER_OTLP_LOGS_CLIENT_CERTIFICATE, diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py index d1cf3c88871..de0783b82cd 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py @@ -69,7 +69,7 @@ OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_INSECURE, OTEL_EXPORTER_OTLP_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.metrics.export import MetricsData from opentelemetry.sdk.resources import Resource as SDKResource @@ -306,7 +306,7 @@ def __init__( else: self._credentials = _get_credentials( credentials, - OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_KEY, OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py index 5b5f4da17f0..bd75e87d87f 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py @@ -51,7 +51,7 @@ OTEL_EXPORTER_OTLP_METRICS_HEADERS, OTEL_EXPORTER_OTLP_METRICS_INSECURE, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_GRPC_METRICS_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.metrics._internal.aggregation import Aggregation from opentelemetry.sdk.metrics.export import ( # noqa: F401 @@ -119,7 +119,7 @@ def __init__( ): credentials = _get_credentials( credentials, - OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_GRPC_METRICS_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE, OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEY, OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE, diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py index a8180c8dfe7..95adc81a7a3 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py @@ -54,7 +54,7 @@ OTEL_EXPORTER_OTLP_TRACES_HEADERS, OTEL_EXPORTER_OTLP_TRACES_INSECURE, OTEL_EXPORTER_OTLP_TRACES_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.trace import ReadableSpan from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult @@ -107,7 +107,7 @@ def __init__( ): credentials = _get_credentials( credentials, - OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE, OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY, OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE, diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py index a2c31bed319..c004d418ba7 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py @@ -50,7 +50,7 @@ ) from opentelemetry.sdk.environment_variables import ( OTEL_EXPORTER_OTLP_COMPRESSION, - OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.trace import ReadableSpan, _Span from opentelemetry.sdk.trace.export import ( @@ -288,7 +288,9 @@ def test_otlp_exporter_otlp_compression_unspecified( @patch.dict( "os.environ", - {OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER: "credential_provider"}, + { + OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER: "credential_provider" + }, ) @patch("opentelemetry.exporter.otlp.proto.grpc.exporter.entry_points") def test_that_credential_gets_passed_to_exporter(self, mock_entry_points): @@ -306,7 +308,9 @@ def f(): @patch.dict( "os.environ", - {OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER: "credential_provider"}, + { + OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER: "credential_provider" + }, ) def test_that_missing_entry_point_raises_exception(self): with self.assertRaises(RuntimeError): @@ -314,10 +318,14 @@ def test_that_missing_entry_point_raises_exception(self): @patch.dict( "os.environ", - {OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER: "credential_provider"}, + { + OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER: "credential_provider" + }, ) @patch("opentelemetry.exporter.otlp.proto.grpc.exporter.entry_points") - def test_that_entry_point_returning_bad_type_raises_exception(self, mock_entry_points): + def test_that_entry_point_returning_bad_type_raises_exception( + self, mock_entry_points + ): def f(): return 1 diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py index 4c4b9aa50da..3820742765c 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py @@ -18,10 +18,10 @@ import requests from opentelemetry.sdk.environment_variables import ( - OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER, - OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, - OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, - OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_HTTP_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER, ) from opentelemetry.util._importlib_metadata import entry_points @@ -36,13 +36,13 @@ def _is_retryable(resp: requests.Response) -> bool: def _load_session_from_envvar( cred_envvar: Literal[ - OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, - OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, - OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER, ], ) -> Optional[requests.Session]: credential_env = environ.get( - OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER + OTEL_PYTHON_EXPORTER_OTLP_HTTP_CREDENTIAL_PROVIDER ) or environ.get(cred_envvar) if credential_env: try: diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py index 6d3d6c9841e..4778ff2e77a 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py @@ -55,7 +55,7 @@ OTEL_EXPORTER_OTLP_LOGS_HEADERS, OTEL_EXPORTER_OTLP_LOGS_TIMEOUT, OTEL_EXPORTER_OTLP_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER, ) from opentelemetry.util.re import parse_env_headers @@ -125,7 +125,7 @@ def __init__( self._session = ( session or _load_session_from_envvar( - OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER + OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER ) or requests.Session() ) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py index 2f54c1857f1..e536bf7e560 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py @@ -81,7 +81,7 @@ OTEL_EXPORTER_OTLP_METRICS_HEADERS, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT, OTEL_EXPORTER_OTLP_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.metrics._internal.aggregation import Aggregation from opentelemetry.sdk.metrics.export import ( # noqa: F401 @@ -164,7 +164,7 @@ def __init__( self._session = ( session or _load_session_from_envvar( - OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER + OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER ) or requests.Session() ) 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 2366eacc08e..9c828dff2d5 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 @@ -51,7 +51,7 @@ OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_HEADERS, OTEL_EXPORTER_OTLP_TRACES_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.trace import ReadableSpan from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult @@ -120,7 +120,7 @@ def __init__( self._session = ( session or _load_session_from_envvar( - OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER + OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER ) or requests.Session() ) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py index c4e8721a7c8..bd93a7543cb 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py @@ -51,7 +51,7 @@ OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT, OTEL_EXPORTER_OTLP_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.metrics import ( Counter, @@ -156,7 +156,7 @@ def test_constructor_default(self): OTEL_EXPORTER_OTLP_METRICS_ENDPOINT: "https://metrics.endpoint.env", OTEL_EXPORTER_OTLP_METRICS_HEADERS: "metricsEnv1=val1,metricsEnv2=val2,metricEnv3===val3==,User-agent=metrics-user-agent", OTEL_EXPORTER_OTLP_METRICS_TIMEOUT: "40", - OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER: "credential_provider", + OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER: "credential_provider", }, ) @patch("opentelemetry.exporter.otlp.proto.http._common.entry_points") diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py index f50198d60b6..30268f89f79 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py @@ -57,7 +57,7 @@ OTEL_EXPORTER_OTLP_LOGS_HEADERS, OTEL_EXPORTER_OTLP_LOGS_TIMEOUT, OTEL_EXPORTER_OTLP_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.resources import Resource as SDKResource from opentelemetry.sdk.util.instrumentation import InstrumentationScope @@ -119,7 +119,7 @@ def test_constructor_default(self): OTEL_EXPORTER_OTLP_LOGS_ENDPOINT: "https://logs.endpoint.env", OTEL_EXPORTER_OTLP_LOGS_HEADERS: "logsEnv1=val1,logsEnv2=val2,logsEnv3===val3==,User-agent=LogsUserAgent", OTEL_EXPORTER_OTLP_LOGS_TIMEOUT: "40", - OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER: "credential_provider", + OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER: "credential_provider", }, ) @patch("opentelemetry.exporter.otlp.proto.http._common.entry_points") @@ -162,17 +162,19 @@ def f(): "application/x-protobuf", ) - @patch.dict( "os.environ", { - OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER: "provider_without_entry_point", + OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER: "provider_without_entry_point", }, ) @patch("opentelemetry.exporter.otlp.proto.http._common.entry_points") - def test_exception_raised_when_entrypoint_returns_wrong_type(self, mock_entry_points): + def test_exception_raised_when_entrypoint_returns_wrong_type( + self, mock_entry_points + ): def f(): return 1 + mock_entry_points.configure_mock( return_value=[IterEntryPoint("custom_credential", f)] ) @@ -182,7 +184,7 @@ def f(): @patch.dict( "os.environ", { - OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER: "provider_without_entry_point", + OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER: "provider_without_entry_point", }, ) def test_exception_raised_when_entrypoint_does_not_exist(self): 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 934c3782d32..912d3e5d30a 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 @@ -46,7 +46,7 @@ OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_HEADERS, OTEL_EXPORTER_OTLP_TRACES_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER, + OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.trace import _Span from opentelemetry.sdk.trace.export import SpanExportResult @@ -113,7 +113,7 @@ def test_constructor_default(self): OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: "https://traces.endpoint.env", OTEL_EXPORTER_OTLP_TRACES_HEADERS: "tracesEnv1=val1,tracesEnv2=val2,traceEnv3===val3==,User-agent=TraceUserAgent", OTEL_EXPORTER_OTLP_TRACES_TIMEOUT: "40", - OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER: "credential_provider", + OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER: "credential_provider", }, ) @patch("opentelemetry.exporter.otlp.proto.http._common.entry_points") diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py index 9b230873a90..90aaa57c240 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py @@ -394,78 +394,139 @@ A scheme of https indicates a secure connection and takes precedence over this configuration setting. """ -OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER = ( - "OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER" +OTEL_PYTHON_EXPORTER_OTLP_GRPC_LOGS_CREDENTIAL_PROVIDER = ( + "OTEL_PYTHON_EXPORTER_OTLP_GRPC_LOGS_CREDENTIAL_PROVIDER" ) """ -.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER +.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_GRPC_LOGS_CREDENTIAL_PROVIDER -The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER` provides either `grpc.ChannelCredentials` for the grpc OTLP Log exporter, -or `requests.Session` for the HTTP OTLP Log exporter. Entry point providers should implement the following functions: +The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_GRPC_LOGS_CREDENTIAL_PROVIDER` provides `grpc.ChannelCredentials` to the grpc OTLP Log exporter, +Entry point providers should implement the following: .. code-block:: python - import requests, grpc - # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. - def request_session_provder() -> requests.Session: + import grpc # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. def channel_credential_provider() -> grpc.ChannelCredentials: """ -OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER = ( - "OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER" + +OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER = ( + "OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER" ) """ -.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER +.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER -The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER` provides either `grpc.ChannelCredentials` for all grpc OTLP exporters, -or `requests.Session` for all HTTP OTLP exporters. Entry point providers should implement the following functions: +The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER` provides `requests.Session` for the HTTP OTLP Log exporter. +Entry point providers should implement the following: .. code-block:: python - import requests, grpc + + import requests # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. def request_session_provder() -> requests.Session: +""" +OTEL_PYTHON_EXPORTER_OTLP_HTTP_CREDENTIAL_PROVIDER = ( + "OTEL_PYTHON_EXPORTER_OTLP_HTTP_CREDENTIAL_PROVIDER" +) +""" +.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_HTTP_CREDENTIAL_PROVIDER + +The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_HTTP_CREDENTIAL_PROVIDER` provides `requests.Session` for all HTTP OTLP exporters. +Entry point providers should implement the following: + +.. code-block:: python + + import requests + + # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. + def request_session_provder() -> requests.Session: + +""" +OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER = ( + "OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER" +) +""" +.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER + +The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER` provides `grpc.ChannelCredentials` for all GRPC OTLP exporters. +Entry point providers should implement the following: + +.. code-block:: python + + import grpc + # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. def channel_credential_provider() -> grpc.ChannelCredentials: """ -OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER = ( - "OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER" +OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER = ( + "OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER" ) """ -.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER +.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER -The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER` provides either `grpc.ChannelCredentials` for the grpc OTLP Span exporter, -or `requests.Session` for the HTTP OTLP Span exporter. Entry point providers should implement the following functions: +The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER` provides `requests.Session` to the HTTP OTLP Span exporter. +Entry point providers should implement the following: .. code-block:: python - import requests, grpc + + import requests # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. def request_session_provder() -> requests.Session: +""" +OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER = ( + "OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER" +) +""" +.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER + +The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER` provides `grpc.ChannelCredentials` to the GRPC OTLP Span exporter. +Entry point providers should implement the following: + +.. code-block:: python + + import grpc + # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. def channel_credential_provider() -> grpc.ChannelCredentials: """ -OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER = ( - "OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER" +OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER = ( + "OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER" ) """ -.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER +.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER -The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER` provides either `grpc.ChannelCredentials` for the grpc OTLP Metric exporter, -or `requests.Session` for the HTTP OTLP Log exporter. Entry point providers should implement the following functions: +The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER` provides `requests.Session` to the HTTP OTLP Metric exporter. +Entry point providers should implement the following: .. code-block:: python - import requests, grpc + + import requests # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. def request_session_provder() -> requests.Session: +""" +OTEL_PYTHON_EXPORTER_OTLP_GRPC_METRICS_CREDENTIAL_PROVIDER = ( + "OTEL_PYTHON_EXPORTER_OTLP_GRPC_METRICS_CREDENTIAL_PROVIDER" +) +""" +.. envvar:: OTEL_PYTHON_EXPORTER_OTLP_GRPC_METRICS_CREDENTIAL_PROVIDER + +The :envvar:`OTEL_PYTHON_EXPORTER_OTLP_GRPC_METRICS_CREDENTIAL_PROVIDER` provides `grpc.ChannelCredentials` to the GRPC OTLP Metric exporter. +Entry point providers should implement the following: + +.. code-block:: python + + import grpc + # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. def channel_credential_provider() -> grpc.ChannelCredentials: From 97fa83691766ae58b0318a0118d336348d1ecc45 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Mon, 8 Sep 2025 18:48:55 +0000 Subject: [PATCH 25/33] Respond to comments --- .../opentelemetry/exporter/otlp/proto/grpc/exporter.py | 10 +++++----- .../exporter/otlp/proto/http/_common/__init__.py | 10 +++++----- .../sdk/environment_variables/__init__.py | 8 ++++++++ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py index de0783b82cd..b324170f6c6 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py @@ -178,27 +178,27 @@ def _get_credentials( ) -> ChannelCredentials: if creds is not None: return creds - credential_env = environ.get(credential_entry_point_env_key) - if credential_env: + _credential_env = environ.get(credential_entry_point_env_key) + if _credential_env: try: maybe_channel_creds = next( iter( entry_points( group="opentelemetry_otlp_credential_provider", - name=credential_env, + name=_credential_env, ) ) ).load()() except StopIteration: raise RuntimeError( - f"Requested component '{credential_env}' not found in " + f"Requested component '{_credential_env}' not found in " f"entry point 'opentelemetry_otlp_credential_provider'" ) if isinstance(maybe_channel_creds, ChannelCredentials): return maybe_channel_creds else: raise RuntimeError( - f"Requested component '{credential_env}' is of type {type(maybe_channel_creds)}" + f"Requested component '{_credential_env}' is of type {type(maybe_channel_creds)}" f" must be of type `grpc.ChannelCredentials`." ) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py index 3820742765c..77fd428402b 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py @@ -41,29 +41,29 @@ def _load_session_from_envvar( OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER, ], ) -> Optional[requests.Session]: - credential_env = environ.get( + _credential_env = environ.get( OTEL_PYTHON_EXPORTER_OTLP_HTTP_CREDENTIAL_PROVIDER ) or environ.get(cred_envvar) - if credential_env: + if _credential_env: try: maybe_session = next( iter( entry_points( group="opentelemetry_otlp_credential_provider", - name=credential_env, + name=_credential_env, ) ) ).load()() except StopIteration: raise RuntimeError( - f"Requested component '{credential_env}' not found in " + f"Requested component '{_credential_env}' not found in " f"entry point 'opentelemetry_otlp_credential_provider'" ) if isinstance(maybe_session, requests.Session): return maybe_session else: raise RuntimeError( - f"Requested component '{credential_env}' is of type {type(maybe_session)}" + f"Requested component '{_credential_env}' is of type {type(maybe_session)}" f" must be of type `requests.Session`." ) return None diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py index 90aaa57c240..0f52763f433 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py @@ -410,6 +410,7 @@ # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. def channel_credential_provider() -> grpc.ChannelCredentials: +Note: This environment variable is experimental and subject to change. """ OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER = ( @@ -428,6 +429,7 @@ def channel_credential_provider() -> grpc.ChannelCredentials: # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. def request_session_provder() -> requests.Session: +Note: This environment variable is experimental and subject to change. """ OTEL_PYTHON_EXPORTER_OTLP_HTTP_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_HTTP_CREDENTIAL_PROVIDER" @@ -445,6 +447,7 @@ def request_session_provder() -> requests.Session: # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. def request_session_provder() -> requests.Session: +Note: This environment variable is experimental and subject to change. """ OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER" @@ -462,6 +465,7 @@ def request_session_provder() -> requests.Session: # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. def channel_credential_provider() -> grpc.ChannelCredentials: +Note: This environment variable is experimental and subject to change. """ OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER" @@ -479,6 +483,7 @@ def channel_credential_provider() -> grpc.ChannelCredentials: # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. def request_session_provder() -> requests.Session: +Note: This environment variable is experimental and subject to change. """ OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER" @@ -496,6 +501,7 @@ def request_session_provder() -> requests.Session: # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. def channel_credential_provider() -> grpc.ChannelCredentials: +Note: This environment variable is experimental and subject to change. """ OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER" @@ -513,6 +519,7 @@ def channel_credential_provider() -> grpc.ChannelCredentials: # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. def request_session_provder() -> requests.Session: +Note: This environment variable is experimental and subject to change. """ OTEL_PYTHON_EXPORTER_OTLP_GRPC_METRICS_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_GRPC_METRICS_CREDENTIAL_PROVIDER" @@ -530,6 +537,7 @@ def request_session_provder() -> requests.Session: # Add a reference to this function under the `opentelemetry_otlp_credential_provider` entry point. def channel_credential_provider() -> grpc.ChannelCredentials: +Note: This environment variable is experimental and subject to change. """ OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE = "OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE" From e7027a071708665edfc9a72044099da302b1ad99 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Mon, 8 Sep 2025 18:56:26 +0000 Subject: [PATCH 26/33] Rename python env var with _ --- .../otlp/proto/grpc/_log_exporter/__init__.py | 4 ++-- .../exporter/otlp/proto/grpc/exporter.py | 4 ++-- .../otlp/proto/grpc/metric_exporter/__init__.py | 4 ++-- .../otlp/proto/grpc/trace_exporter/__init__.py | 4 ++-- .../tests/test_otlp_exporter_mixin.py | 8 ++++---- .../exporter/otlp/proto/http/_common/__init__.py | 16 ++++++++-------- .../otlp/proto/http/_log_exporter/__init__.py | 4 ++-- .../otlp/proto/http/metric_exporter/__init__.py | 4 ++-- .../otlp/proto/http/trace_exporter/__init__.py | 4 ++-- .../tests/metrics/test_otlp_metrics_exporter.py | 4 ++-- .../tests/test_proto_log_exporter.py | 8 ++++---- .../tests/test_proto_span_exporter.py | 4 ++-- .../sdk/environment_variables/__init__.py | 16 ++++++++-------- 13 files changed, 42 insertions(+), 42 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py index b1ceeb536b9..1d8ba3fa8a6 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py @@ -40,7 +40,7 @@ OTEL_EXPORTER_OTLP_LOGS_HEADERS, OTEL_EXPORTER_OTLP_LOGS_INSECURE, OTEL_EXPORTER_OTLP_LOGS_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_GRPC_LOGS_CREDENTIAL_PROVIDER, + _OTEL_PYTHON_EXPORTER_OTLP_GRPC_LOGS_CREDENTIAL_PROVIDER, ) @@ -74,7 +74,7 @@ def __init__( ): credentials = _get_credentials( credentials, - OTEL_PYTHON_EXPORTER_OTLP_GRPC_LOGS_CREDENTIAL_PROVIDER, + _OTEL_PYTHON_EXPORTER_OTLP_GRPC_LOGS_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE, OTEL_EXPORTER_OTLP_LOGS_CLIENT_KEY, OTEL_EXPORTER_OTLP_LOGS_CLIENT_CERTIFICATE, diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py index b324170f6c6..477cc1a6417 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py @@ -61,6 +61,7 @@ from opentelemetry.proto.resource.v1.resource_pb2 import Resource # noqa: F401 from opentelemetry.sdk._shared_internal import DuplicateFilter from opentelemetry.sdk.environment_variables import ( + _OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_KEY, @@ -69,7 +70,6 @@ OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_INSECURE, OTEL_EXPORTER_OTLP_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.metrics.export import MetricsData from opentelemetry.sdk.resources import Resource as SDKResource @@ -306,7 +306,7 @@ def __init__( else: self._credentials = _get_credentials( credentials, - OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER, + _OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_KEY, OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py index bd75e87d87f..8b6da1ddaba 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py @@ -51,7 +51,7 @@ OTEL_EXPORTER_OTLP_METRICS_HEADERS, OTEL_EXPORTER_OTLP_METRICS_INSECURE, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_GRPC_METRICS_CREDENTIAL_PROVIDER, + _OTEL_PYTHON_EXPORTER_OTLP_GRPC_METRICS_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.metrics._internal.aggregation import Aggregation from opentelemetry.sdk.metrics.export import ( # noqa: F401 @@ -119,7 +119,7 @@ def __init__( ): credentials = _get_credentials( credentials, - OTEL_PYTHON_EXPORTER_OTLP_GRPC_METRICS_CREDENTIAL_PROVIDER, + _OTEL_PYTHON_EXPORTER_OTLP_GRPC_METRICS_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE, OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEY, OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE, diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py index 95adc81a7a3..e8f9db3f584 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/trace_exporter/__init__.py @@ -46,6 +46,7 @@ Span as CollectorSpan, ) from opentelemetry.sdk.environment_variables import ( + _OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE, OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY, @@ -54,7 +55,6 @@ OTEL_EXPORTER_OTLP_TRACES_HEADERS, OTEL_EXPORTER_OTLP_TRACES_INSECURE, OTEL_EXPORTER_OTLP_TRACES_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.trace import ReadableSpan from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult @@ -107,7 +107,7 @@ def __init__( ): credentials = _get_credentials( credentials, - OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER, + _OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE, OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY, OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE, diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py index c004d418ba7..4358506ff5f 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_exporter_mixin.py @@ -49,8 +49,8 @@ add_TraceServiceServicer_to_server, ) from opentelemetry.sdk.environment_variables import ( + _OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_COMPRESSION, - OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.trace import ReadableSpan, _Span from opentelemetry.sdk.trace.export import ( @@ -289,7 +289,7 @@ def test_otlp_exporter_otlp_compression_unspecified( @patch.dict( "os.environ", { - OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER: "credential_provider" + _OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER: "credential_provider" }, ) @patch("opentelemetry.exporter.otlp.proto.grpc.exporter.entry_points") @@ -309,7 +309,7 @@ def f(): @patch.dict( "os.environ", { - OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER: "credential_provider" + _OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER: "credential_provider" }, ) def test_that_missing_entry_point_raises_exception(self): @@ -319,7 +319,7 @@ def test_that_missing_entry_point_raises_exception(self): @patch.dict( "os.environ", { - OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER: "credential_provider" + _OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER: "credential_provider" }, ) @patch("opentelemetry.exporter.otlp.proto.grpc.exporter.entry_points") diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py index 77fd428402b..0658d0968e6 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py @@ -18,10 +18,10 @@ import requests from opentelemetry.sdk.environment_variables import ( - OTEL_PYTHON_EXPORTER_OTLP_HTTP_CREDENTIAL_PROVIDER, - OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER, - OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER, - OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER, + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_CREDENTIAL_PROVIDER, + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER, + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER, + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER, ) from opentelemetry.util._importlib_metadata import entry_points @@ -36,13 +36,13 @@ def _is_retryable(resp: requests.Response) -> bool: def _load_session_from_envvar( cred_envvar: Literal[ - OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER, - OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER, - OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER, + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER, + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER, + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER, ], ) -> Optional[requests.Session]: _credential_env = environ.get( - OTEL_PYTHON_EXPORTER_OTLP_HTTP_CREDENTIAL_PROVIDER + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_CREDENTIAL_PROVIDER ) or environ.get(cred_envvar) if _credential_env: try: diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py index 4778ff2e77a..2afdf660025 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_log_exporter/__init__.py @@ -41,6 +41,7 @@ ) from opentelemetry.sdk._shared_internal import DuplicateFilter from opentelemetry.sdk.environment_variables import ( + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_KEY, @@ -55,7 +56,6 @@ OTEL_EXPORTER_OTLP_LOGS_HEADERS, OTEL_EXPORTER_OTLP_LOGS_TIMEOUT, OTEL_EXPORTER_OTLP_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER, ) from opentelemetry.util.re import parse_env_headers @@ -125,7 +125,7 @@ def __init__( self._session = ( session or _load_session_from_envvar( - OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER ) or requests.Session() ) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py index e536bf7e560..c6d657e7ae0 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py @@ -67,6 +67,7 @@ Resource as PB2Resource, ) from opentelemetry.sdk.environment_variables import ( + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_KEY, @@ -81,7 +82,6 @@ OTEL_EXPORTER_OTLP_METRICS_HEADERS, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT, OTEL_EXPORTER_OTLP_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.metrics._internal.aggregation import Aggregation from opentelemetry.sdk.metrics.export import ( # noqa: F401 @@ -164,7 +164,7 @@ def __init__( self._session = ( session or _load_session_from_envvar( - OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER ) or requests.Session() ) 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 9c828dff2d5..055e829daba 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 @@ -37,6 +37,7 @@ _load_session_from_envvar, ) from opentelemetry.sdk.environment_variables import ( + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_KEY, @@ -51,7 +52,6 @@ OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_HEADERS, OTEL_EXPORTER_OTLP_TRACES_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.trace import ReadableSpan from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult @@ -120,7 +120,7 @@ def __init__( self._session = ( session or _load_session_from_envvar( - OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER ) or requests.Session() ) diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py index bd93a7543cb..d7a5bed2d4d 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py @@ -35,6 +35,7 @@ ) from opentelemetry.exporter.otlp.proto.http.version import __version__ from opentelemetry.sdk.environment_variables import ( + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_KEY, @@ -51,7 +52,6 @@ OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT, OTEL_EXPORTER_OTLP_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.metrics import ( Counter, @@ -156,7 +156,7 @@ def test_constructor_default(self): OTEL_EXPORTER_OTLP_METRICS_ENDPOINT: "https://metrics.endpoint.env", OTEL_EXPORTER_OTLP_METRICS_HEADERS: "metricsEnv1=val1,metricsEnv2=val2,metricEnv3===val3==,User-agent=metrics-user-agent", OTEL_EXPORTER_OTLP_METRICS_TIMEOUT: "40", - OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER: "credential_provider", + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER: "credential_provider", }, ) @patch("opentelemetry.exporter.otlp.proto.http._common.entry_points") diff --git a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py index 30268f89f79..d136e09ffdc 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py +++ b/exporter/opentelemetry-exporter-otlp-proto-http/tests/test_proto_log_exporter.py @@ -43,6 +43,7 @@ from opentelemetry.sdk._logs import LogRecord as SDKLogRecord from opentelemetry.sdk._logs.export import LogExportResult from opentelemetry.sdk.environment_variables import ( + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_KEY, @@ -57,7 +58,6 @@ OTEL_EXPORTER_OTLP_LOGS_HEADERS, OTEL_EXPORTER_OTLP_LOGS_TIMEOUT, OTEL_EXPORTER_OTLP_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.resources import Resource as SDKResource from opentelemetry.sdk.util.instrumentation import InstrumentationScope @@ -119,7 +119,7 @@ def test_constructor_default(self): OTEL_EXPORTER_OTLP_LOGS_ENDPOINT: "https://logs.endpoint.env", OTEL_EXPORTER_OTLP_LOGS_HEADERS: "logsEnv1=val1,logsEnv2=val2,logsEnv3===val3==,User-agent=LogsUserAgent", OTEL_EXPORTER_OTLP_LOGS_TIMEOUT: "40", - OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER: "credential_provider", + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER: "credential_provider", }, ) @patch("opentelemetry.exporter.otlp.proto.http._common.entry_points") @@ -165,7 +165,7 @@ def f(): @patch.dict( "os.environ", { - OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER: "provider_without_entry_point", + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER: "provider_without_entry_point", }, ) @patch("opentelemetry.exporter.otlp.proto.http._common.entry_points") @@ -184,7 +184,7 @@ def f(): @patch.dict( "os.environ", { - OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER: "provider_without_entry_point", + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER: "provider_without_entry_point", }, ) def test_exception_raised_when_entrypoint_does_not_exist(self): 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 912d3e5d30a..2d6dea71de5 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 @@ -32,6 +32,7 @@ ) from opentelemetry.exporter.otlp.proto.http.version import __version__ from opentelemetry.sdk.environment_variables import ( + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_CLIENT_KEY, @@ -46,7 +47,6 @@ OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_HEADERS, OTEL_EXPORTER_OTLP_TRACES_TIMEOUT, - OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.trace import _Span from opentelemetry.sdk.trace.export import SpanExportResult @@ -113,7 +113,7 @@ def test_constructor_default(self): OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: "https://traces.endpoint.env", OTEL_EXPORTER_OTLP_TRACES_HEADERS: "tracesEnv1=val1,tracesEnv2=val2,traceEnv3===val3==,User-agent=TraceUserAgent", OTEL_EXPORTER_OTLP_TRACES_TIMEOUT: "40", - OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER: "credential_provider", + _OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER: "credential_provider", }, ) @patch("opentelemetry.exporter.otlp.proto.http._common.entry_points") diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py index 0f52763f433..5baf5fcd55d 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/environment_variables/__init__.py @@ -394,7 +394,7 @@ A scheme of https indicates a secure connection and takes precedence over this configuration setting. """ -OTEL_PYTHON_EXPORTER_OTLP_GRPC_LOGS_CREDENTIAL_PROVIDER = ( +_OTEL_PYTHON_EXPORTER_OTLP_GRPC_LOGS_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_GRPC_LOGS_CREDENTIAL_PROVIDER" ) """ @@ -413,7 +413,7 @@ def channel_credential_provider() -> grpc.ChannelCredentials: Note: This environment variable is experimental and subject to change. """ -OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER = ( +_OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER" ) """ @@ -431,7 +431,7 @@ def request_session_provder() -> requests.Session: Note: This environment variable is experimental and subject to change. """ -OTEL_PYTHON_EXPORTER_OTLP_HTTP_CREDENTIAL_PROVIDER = ( +_OTEL_PYTHON_EXPORTER_OTLP_HTTP_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_HTTP_CREDENTIAL_PROVIDER" ) """ @@ -449,7 +449,7 @@ def request_session_provder() -> requests.Session: Note: This environment variable is experimental and subject to change. """ -OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER = ( +_OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_GRPC_CREDENTIAL_PROVIDER" ) """ @@ -467,7 +467,7 @@ def channel_credential_provider() -> grpc.ChannelCredentials: Note: This environment variable is experimental and subject to change. """ -OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER = ( +_OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER" ) """ @@ -485,7 +485,7 @@ def request_session_provder() -> requests.Session: Note: This environment variable is experimental and subject to change. """ -OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER = ( +_OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER" ) """ @@ -503,7 +503,7 @@ def channel_credential_provider() -> grpc.ChannelCredentials: Note: This environment variable is experimental and subject to change. """ -OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER = ( +_OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER" ) """ @@ -521,7 +521,7 @@ def request_session_provder() -> requests.Session: Note: This environment variable is experimental and subject to change. """ -OTEL_PYTHON_EXPORTER_OTLP_GRPC_METRICS_CREDENTIAL_PROVIDER = ( +_OTEL_PYTHON_EXPORTER_OTLP_GRPC_METRICS_CREDENTIAL_PROVIDER = ( "OTEL_PYTHON_EXPORTER_OTLP_GRPC_METRICS_CREDENTIAL_PROVIDER" ) """ From f06d8db76b110152c4c44b041ddb5b43faa3cced Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Mon, 8 Sep 2025 18:57:19 +0000 Subject: [PATCH 27/33] Precommit --- .../exporter/otlp/proto/grpc/_log_exporter/__init__.py | 2 +- .../exporter/otlp/proto/grpc/metric_exporter/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py index 1d8ba3fa8a6..95bb5ded2b7 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py @@ -32,6 +32,7 @@ from opentelemetry.sdk._logs import LogRecord as SDKLogRecord from opentelemetry.sdk._logs.export import LogExporter, LogExportResult from opentelemetry.sdk.environment_variables import ( + _OTEL_PYTHON_EXPORTER_OTLP_GRPC_LOGS_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE, OTEL_EXPORTER_OTLP_LOGS_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_LOGS_CLIENT_KEY, @@ -40,7 +41,6 @@ OTEL_EXPORTER_OTLP_LOGS_HEADERS, OTEL_EXPORTER_OTLP_LOGS_INSECURE, OTEL_EXPORTER_OTLP_LOGS_TIMEOUT, - _OTEL_PYTHON_EXPORTER_OTLP_GRPC_LOGS_CREDENTIAL_PROVIDER, ) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py index 8b6da1ddaba..be9e246a4c1 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py @@ -43,6 +43,7 @@ ) from opentelemetry.proto.metrics.v1 import metrics_pb2 as pb2 # noqa: F401 from opentelemetry.sdk.environment_variables import ( + _OTEL_PYTHON_EXPORTER_OTLP_GRPC_METRICS_CREDENTIAL_PROVIDER, OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE, OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEY, @@ -51,7 +52,6 @@ OTEL_EXPORTER_OTLP_METRICS_HEADERS, OTEL_EXPORTER_OTLP_METRICS_INSECURE, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT, - _OTEL_PYTHON_EXPORTER_OTLP_GRPC_METRICS_CREDENTIAL_PROVIDER, ) from opentelemetry.sdk.metrics._internal.aggregation import Aggregation from opentelemetry.sdk.metrics.export import ( # noqa: F401 From 3ab6126a4a3e0474777cde85c7604e17397e7c6d Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Mon, 8 Sep 2025 19:07:35 +0000 Subject: [PATCH 28/33] Commit changes --- CHANGELOG.md | 2 +- .../src/opentelemetry/exporter/otlp/proto/grpc/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52e0506fa5c..10b1b191db8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add experimental composite samplers ([#4714](https://github.com/open-telemetry/opentelemetry-python/pull/4714)) -- Add new environment variables to the SDK `OTEL_PYTHON_EXPORTER_OTLP_{METRICS/TRACES/LOGS}_CREDENTIAL_PROVIDER` that can be used to +- Add new environment variables to the SDK `OTEL_PYTHON_EXPORTER_OTLP_{HTTP/GRPC}_{METRICS/TRACES/LOGS}_CREDENTIAL_PROVIDER` that can be used to inject a `requests.Session` or `grpc.ChannelCredentials` object into OTLP exporters created during auto instrumentation [#4689](https://github.com/open-telemetry/opentelemetry-python/pull/4689). - Filter duplicate logs out of some internal `logger`'s logs on the export logs path that might otherwise endlessly log or cause a recursion depth exceeded issue in cases where logging itself results in an exception. ([#4695](https://github.com/open-telemetry/opentelemetry-python/pull/4695)). diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py index cf257a902c1..58ca6d00ab3 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py @@ -29,7 +29,7 @@ - :envvar:`OTEL_EXPORTER_OTLP_TRACES_HEADERS` - :envvar:`OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` - :envvar:`OTEL_EXPORTER_OTLP_TRACES_COMPRESSION` -- :envvar:`OTEL_PYTHON_EXPORTER_OTLP_CREDENTIAL_PROVIDER` +- :envvar:`OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER` - :envvar:`OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE` - :envvar:`OTEL_EXPORTER_OTLP_TIMEOUT` - :envvar:`OTEL_EXPORTER_OTLP_PROTOCOL` From 3e409cc2733d20e58f78b261df3b90a864e18a60 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Mon, 8 Sep 2025 19:10:59 +0000 Subject: [PATCH 29/33] add new line --- dev-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 292ffbda483..cd203a12104 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -17,4 +17,4 @@ psutil==5.9.6 GitPython==3.1.41 pre-commit==3.7.0; python_version >= '3.9' pre-commit==3.5.0; python_version < '3.9' -ruff==0.6.9 \ No newline at end of file +ruff==0.6.9 From 5632fe01cce9b8d275636c2469705bdba907a7f2 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Mon, 8 Sep 2025 19:15:16 +0000 Subject: [PATCH 30/33] Fix docs error.. --- .../src/opentelemetry/exporter/otlp/proto/grpc/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py index 58ca6d00ab3..1e3e63962c8 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py @@ -29,7 +29,7 @@ - :envvar:`OTEL_EXPORTER_OTLP_TRACES_HEADERS` - :envvar:`OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` - :envvar:`OTEL_EXPORTER_OTLP_TRACES_COMPRESSION` -- :envvar:`OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER` +- :envvar:`_OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER` - :envvar:`OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE` - :envvar:`OTEL_EXPORTER_OTLP_TIMEOUT` - :envvar:`OTEL_EXPORTER_OTLP_PROTOCOL` From f0fc0f60215c5044fed0e0c4e16a6d4bf185b340 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Mon, 8 Sep 2025 19:17:44 +0000 Subject: [PATCH 31/33] get rid of envvar in docstring --- .../src/opentelemetry/exporter/otlp/proto/grpc/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py index 1e3e63962c8..12275ef481a 100644 --- a/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py +++ b/exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/__init__.py @@ -29,7 +29,6 @@ - :envvar:`OTEL_EXPORTER_OTLP_TRACES_HEADERS` - :envvar:`OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` - :envvar:`OTEL_EXPORTER_OTLP_TRACES_COMPRESSION` -- :envvar:`_OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER` - :envvar:`OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE` - :envvar:`OTEL_EXPORTER_OTLP_TIMEOUT` - :envvar:`OTEL_EXPORTER_OTLP_PROTOCOL` From 0e0fb9db3629de7893b5b3a69d978742d144f4f8 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Tue, 9 Sep 2025 15:00:31 +0000 Subject: [PATCH 32/33] Revert tox.ini changes --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 0b9247719e2..be8c11a1598 100644 --- a/tox.ini +++ b/tox.ini @@ -153,7 +153,7 @@ deps = getting-started: {env:CONTRIB_REPO}\#egg=opentelemetry-instrumentation-wsgi&subdirectory=instrumentation/opentelemetry-instrumentation-wsgi getting-started: {env:CONTRIB_REPO}\#egg=opentelemetry-instrumentation-flask&subdirectory=instrumentation/opentelemetry-instrumentation-flask -allowlist_externals = sh, pytest +allowlist_externals = sh setenv = ; override CONTRIB_REPO_SHA via env variable when testing other branches/commits than main From 5336c957ab2696e6b49a624f527ab2d16aa2a92d Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Tue, 9 Sep 2025 15:03:24 +0000 Subject: [PATCH 33/33] Revert tox --- tox.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tox.ini b/tox.ini index be8c11a1598..5355cb8dd4a 100644 --- a/tox.ini +++ b/tox.ini @@ -303,6 +303,7 @@ changedir = tests/opentelemetry-docker-tests/tests commands_pre = + pip freeze docker-compose up -d commands = otlpexporter: pytest otlpexporter {posargs} @@ -356,3 +357,4 @@ deps = pre-commit commands = pre-commit run --color=always --all-files {posargs} + \ No newline at end of file