2828
2929from opentelemetry import trace
3030from opentelemetry .context import Context
31- from opentelemetry .sdk .environment_variables import OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER
31+ from opentelemetry .sdk .environment_variables import OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER , OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER
3232from opentelemetry .environment_variables import OTEL_PYTHON_ID_GENERATOR
3333from opentelemetry .sdk ._configuration import (
3434 _EXPORTER_OTLP ,
4545 _init_exporter ,
4646 _init_metrics ,
4747 _init_tracing ,
48+ _load_credential_from_envvar ,
4849 _initialize_components ,
4950 _OTelSDKConfigurator ,
5051)
@@ -182,7 +183,8 @@ def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
182183
183184
184185class DummyOTLPMetricExporter :
185- def __init__ (self , compression : str | None = None , session : Session | None , * args , ** kwargs ):
186+ def __init__ (self , compression : str | None = None , session : Session | None = None , * args , ** kwargs ):
187+ self .session = session
186188 self .export_called = False
187189 self .compression = compression
188190
@@ -209,6 +211,7 @@ def shutdown(self):
209211class OTLPSpanExporter :
210212 def __init__ (self , compression : str | None = None , credentials : ChannelCredentials | None = None , * args , ** kwargs ):
211213 self .compression = compression
214+ self .credentials = credentials
212215
213216
214217class DummyOTLPLogExporter (LogExporter ):
@@ -412,15 +415,36 @@ def test_trace_init_custom_id_generator(self, mock_entry_points):
412415 self .assertIsInstance (provider .id_generator , CustomIdGenerator )
413416
414417
415- @patch .dict (environ , {OTEL_PYTHON_EXPORTER_OTLP_LOGS_CREDENTIAL_PROVIDER : "custom_session" })
418+ @patch .dict (environ , {OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER : "custom_session" })
416419 @patch ("opentelemetry.sdk._configuration.entry_points" )
417- def check_that_credential_envvar_gets_passed_to_exporter (self , mock_entry_points ):
420+ def test_that_session_gets_passed_to_exporter (self , mock_entry_points ):
421+ # Should not be used, trace specific version should override.
422+ session_for_all_signals = Session ()
423+ session_for_metrics_only = Session ()
418424 mock_entry_points .configure_mock (
419425 return_value = [
420- IterEntryPoint ("custom_session" , Session () )
426+ IterEntryPoint ("custom_session" , session_for_metrics_only )
421427 ]
422428 )
423- exporter = _init_exporter ('traces' , None , OTLPSpanExporter )
429+ exporter = _init_exporter ('metrics' , {}, DummyOTLPMetricExporter , otlp_credential_param_for_all_signal_types = ("session" , session_for_all_signals ))
430+ assert exporter .session is session_for_metrics_only
431+ assert exporter .session is not session_for_all_signals
432+
433+
434+ @patch .dict (environ , {OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER : "custom_credential" })
435+ @patch ("opentelemetry.sdk._configuration.entry_points" )
436+ def test_that_credential_gets_passed_to_exporter (self , mock_entry_points ):
437+ # Should not be used, trace specific version should override.
438+ credential_for_all_signals = ChannelCredentials (None )
439+ credential_for_trace_only = ChannelCredentials (None )
440+ mock_entry_points .configure_mock (
441+ return_value = [
442+ IterEntryPoint ("custom_credential" , credential_for_trace_only )
443+ ]
444+ )
445+ exporter = _init_exporter ('traces' , {}, OTLPSpanExporter , otlp_credential_param_for_all_signal_types = credential_for_all_signals )
446+ assert exporter .credentials is credential_for_trace_only
447+ assert exporter .credentials is not credential_for_all_signals
424448
425449 @patch .dict (
426450 "os.environ" , {OTEL_TRACES_SAMPLER : "non_existent_entry_point" }
0 commit comments