Skip to content

Commit f27856f

Browse files
committed
Run precommit and update variable
1 parent cc89293 commit f27856f

File tree

2 files changed

+65
-19
lines changed

2 files changed

+65
-19
lines changed

opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def _get_exporter_names(
247247

248248
def _init_exporter(
249249
signal_type: Literal["traces", "metrics", "logs"],
250-
exporter_args_map: Mapping[str, Any],
250+
exporter_args: ExporterArgsMap,
251251
exporter_class: Union[
252252
Type[SpanExporter], Type[MetricExporter], Type[LogExporter]
253253
],
@@ -268,9 +268,14 @@ def _init_exporter(
268268
if otlp_credential_param:
269269
credential_key, credential = otlp_credential_param
270270
# We only want to inject credentials into the appropriate OTLP HTTP // GRPC exporters.
271-
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)):
272-
exporter_args_map[credential_key] = credential
273-
return exporter_class(**exporter_args_map)
271+
if credential_key in inspect.signature(
272+
exporter_class.__init__
273+
).parameters and (
274+
"opentelemetry.exporter.otlp.proto.http" in str(exporter_class)
275+
or "opentelemetry.exporter.otlp.proto.grpc" in str(exporter_class)
276+
):
277+
exporter_args[credential_key] = credential
278+
return exporter_class(**exporter_args)
274279

275280

276281
def _init_tracing(

opentelemetry-sdk/tests/test_configurator.py

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222
from typing import Iterable, Optional, Sequence
2323
from unittest import TestCase, mock
2424
from unittest.mock import Mock, patch
25-
from requests import Session
26-
from grpc import ChannelCredentials
2725

26+
from grpc import ChannelCredentials
2827
from pytest import raises
28+
from requests import Session
2929

3030
from opentelemetry import trace
3131
from 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
3332
from opentelemetry.environment_variables import OTEL_PYTHON_ID_GENERATOR
3433
from opentelemetry.sdk._configuration import (
3534
_EXPORTER_OTLP,
@@ -42,18 +41,19 @@
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
)
5351
from opentelemetry.sdk._logs import LoggingHandler
5452
from opentelemetry.sdk._logs._internal.export import LogExporter
5553
from opentelemetry.sdk._logs.export import ConsoleLogExporter
5654
from 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

186186
class 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

212218
class 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

Comments
 (0)