2222from typing import Iterable , Optional , Sequence
2323from unittest import TestCase , mock
2424from unittest .mock import Mock , patch
25- from requests import Session
26- from grpc import ChannelCredentials
2725
26+ from grpc import ChannelCredentials
2827from pytest import raises
28+ from requests import Session
2929
3030from opentelemetry import trace
3131from opentelemetry .context import Context
32- from opentelemetry .sdk .environment_variables import OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER , OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER
3332from opentelemetry .environment_variables import OTEL_PYTHON_ID_GENERATOR
3433from opentelemetry .sdk ._configuration import (
3534 _EXPORTER_OTLP ,
4241 _import_exporters ,
4342 _import_id_generator ,
4443 _import_sampler ,
45- _init_logging ,
4644 _init_exporter ,
45+ _init_logging ,
4746 _init_metrics ,
4847 _init_tracing ,
49- _load_credential_from_envvar ,
5048 _initialize_components ,
5149 _OTelSDKConfigurator ,
5250)
5351from opentelemetry .sdk ._logs import LoggingHandler
5452from opentelemetry .sdk ._logs ._internal .export import LogExporter
5553from opentelemetry .sdk ._logs .export import ConsoleLogExporter
5654from opentelemetry .sdk .environment_variables import (
55+ OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER ,
56+ OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER ,
5757 OTEL_TRACES_SAMPLER ,
5858 OTEL_TRACES_SAMPLER_ARG ,
5959)
@@ -184,7 +184,13 @@ def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
184184
185185
186186class DummyOTLPMetricExporter :
187- def __init__ (self , compression : str | None = None , session : Session | None = None , * args , ** kwargs ):
187+ def __init__ (
188+ self ,
189+ compression : str | None = None ,
190+ session : Session | None = None ,
191+ * args ,
192+ ** kwargs ,
193+ ):
188194 self .session = session
189195 self .export_called = False
190196 self .compression = compression
@@ -210,7 +216,13 @@ def shutdown(self):
210216
211217
212218class OTLPSpanExporter :
213- def __init__ (self , compression : str | None = None , credentials : ChannelCredentials | None = None , * args , ** kwargs ):
219+ def __init__ (
220+ self ,
221+ compression : str | None = None ,
222+ credentials : ChannelCredentials | None = None ,
223+ * args ,
224+ ** kwargs ,
225+ ):
214226 self .compression = compression
215227 self .credentials = credentials
216228
@@ -415,8 +427,12 @@ def test_trace_init_custom_id_generator(self, mock_entry_points):
415427 provider = self .set_provider_mock .call_args [0 ][0 ]
416428 self .assertIsInstance (provider .id_generator , CustomIdGenerator )
417429
418-
419- @patch .dict (environ , {OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER : "custom_session" })
430+ @patch .dict (
431+ environ ,
432+ {
433+ OTEL_PYTHON_EXPORTER_OTLP_METRICS_CREDENTIAL_PROVIDER : "custom_session"
434+ },
435+ )
420436 @patch ("opentelemetry.sdk._configuration.entry_points" )
421437 def test_that_session_gets_passed_to_exporter (self , mock_entry_points ):
422438 # 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):
427443 IterEntryPoint ("custom_session" , session_for_metrics_only )
428444 ]
429445 )
430- exporter = _init_exporter ('metrics' , {}, DummyOTLPMetricExporter , otlp_credential_param_for_all_signal_types = ("session" , session_for_all_signals ))
446+ exporter = _init_exporter (
447+ "metrics" ,
448+ {},
449+ DummyOTLPMetricExporter ,
450+ otlp_credential_param_for_all_signal_types = (
451+ "session" ,
452+ session_for_all_signals ,
453+ ),
454+ )
431455 assert exporter .session is session_for_metrics_only
432456 assert exporter .session is not session_for_all_signals
433457
434-
435- @patch .dict (environ , {OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER : "custom_credential" })
458+ @patch .dict (
459+ environ ,
460+ {
461+ OTEL_PYTHON_EXPORTER_OTLP_TRACES_CREDENTIAL_PROVIDER : "custom_credential"
462+ },
463+ )
436464 @patch ("opentelemetry.sdk._configuration.entry_points" )
437465 def test_that_credential_gets_passed_to_exporter (self , mock_entry_points ):
438466 # 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):
443471 IterEntryPoint ("custom_credential" , credential_for_trace_only )
444472 ]
445473 )
446- exporter = _init_exporter ('traces' , {}, OTLPSpanExporter , otlp_credential_param_for_all_signal_types = credential_for_all_signals )
474+ exporter = _init_exporter (
475+ "traces" ,
476+ {},
477+ OTLPSpanExporter ,
478+ otlp_credential_param_for_all_signal_types = credential_for_all_signals ,
479+ )
447480 assert exporter .credentials is credential_for_trace_only
448481 assert exporter .credentials is not credential_for_all_signals
449482
@@ -777,7 +810,11 @@ def test_logging_init_disable_default(self, logging_mock, tracing_mock):
777810 _initialize_components (auto_instrumentation_version = "auto-version" )
778811 self .assertEqual (tracing_mock .call_count , 1 )
779812 logging_mock .assert_called_once_with (
780- mock .ANY , mock .ANY , False , otlp_credential_param = None , exporter_args_map = None
813+ mock .ANY ,
814+ mock .ANY ,
815+ False ,
816+ otlp_credential_param = None ,
817+ exporter_args_map = None ,
781818 )
782819
783820 @patch .dict (
@@ -793,7 +830,11 @@ def test_logging_init_enable_env(self, logging_mock, tracing_mock):
793830 with self .assertLogs (level = WARNING ):
794831 _initialize_components (auto_instrumentation_version = "auto-version" )
795832 logging_mock .assert_called_once_with (
796- mock .ANY , mock .ANY , True , otlp_credential_param = None , exporter_args_map = None
833+ mock .ANY ,
834+ mock .ANY ,
835+ True ,
836+ otlp_credential_param = None ,
837+ exporter_args_map = None ,
797838 )
798839 self .assertEqual (tracing_mock .call_count , 1 )
799840
0 commit comments