Skip to content

Commit 6d9f942

Browse files
committed
lint
1 parent 3c4a626 commit 6d9f942

File tree

2 files changed

+57
-28
lines changed

2 files changed

+57
-28
lines changed

opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ class CustomSamplerFactory:
143143
from opentelemetry.trace.span import TraceState
144144
from opentelemetry.util.types import Attributes
145145

146-
147146
_logger = getLogger(__name__)
148147

149148

@@ -432,7 +431,9 @@ def _get_from_env_or_default() -> Sampler:
432431
try:
433432
rate = float(os.getenv(OTEL_TRACES_SAMPLER_ARG))
434433
except ValueError:
435-
_logger.warning("Could not convert TRACES_SAMPLER_ARG to float.")
434+
_logger.warning(
435+
"Could not convert TRACES_SAMPLER_ARG to float."
436+
)
436437
rate = 1.0
437438
return _KNOWN_SAMPLERS[trace_sampler_name](rate)
438439
return _KNOWN_SAMPLERS[trace_sampler_name]
@@ -443,13 +444,18 @@ def _get_from_env_or_default() -> Sampler:
443444
trace_sampler = trace_sampler_factory(sampler_arg)
444445
_logger.warning("JEREVOSS: trace_sampler: %s" % trace_sampler)
445446
if not issubclass(type(trace_sampler), Sampler):
446-
message = "Output of traces sampler factory, %s, was not a Sampler object." % trace_sampler_factory
447+
message = (
448+
"Output of traces sampler factory, %s, was not a Sampler object."
449+
% trace_sampler_factory
450+
)
447451
_logger.warning(message)
448452
raise ValueError(message)
449453
return trace_sampler
450454
except Exception as exc:
451455
_logger.warning(
452-
"Failed to initialize custom sampler, %s: %s", trace_sampler_name, exc
456+
"Failed to initialize custom sampler, %s: %s",
457+
trace_sampler_name,
458+
exc,
453459
)
454460
return _KNOWN_SAMPLERS["parentbased_always_on"]
455461

opentelemetry-sdk/tests/trace/test_trace.py

+47-24
Original file line numberDiff line numberDiff line change
@@ -304,28 +304,34 @@ def test_sampler_with_env_non_existent_entry_point(self):
304304
self.verify_default_sampler(tracer_provider)
305305

306306
@mock.patch("opentelemetry.sdk.trace.util.iter_entry_points")
307-
@mock.patch.dict("os.environ", {OTEL_TRACES_SAMPLER: "custom_sampler_factory"})
308-
def test_custom_sampler_with_env(
309-
self, mock_iter_entry_points
310-
):
307+
@mock.patch.dict(
308+
"os.environ", {OTEL_TRACES_SAMPLER: "custom_sampler_factory"}
309+
)
310+
def test_custom_sampler_with_env(self, mock_iter_entry_points):
311311
# mock_iter_entry_points.return_value = [
312312
# ("custom_sampler_factory", CustomSamplerFactory.get_custom_sampler)
313313
# ]
314-
mock_iter_entry_points.return_value=[
315-
IterEntryPoint("custom_sampler_factory", CustomSamplerFactory.get_custom_sampler)
314+
mock_iter_entry_points.return_value = [
315+
IterEntryPoint(
316+
"custom_sampler_factory",
317+
CustomSamplerFactory.get_custom_sampler,
318+
)
316319
]
317320
# pylint: disable=protected-access
318321
reload(trace)
319322
tracer_provider = trace.TracerProvider()
320323
self.assertIsInstance(tracer_provider.sampler, CustomSampler)
321324

322325
@mock.patch("opentelemetry.sdk.trace.util.iter_entry_points")
323-
@mock.patch.dict("os.environ", {OTEL_TRACES_SAMPLER: "custom_sampler_factory"})
324-
def test_custom_sampler_with_env_bad_factory(
325-
self, mock_iter_entry_points
326-
):
326+
@mock.patch.dict(
327+
"os.environ", {OTEL_TRACES_SAMPLER: "custom_sampler_factory"}
328+
)
329+
def test_custom_sampler_with_env_bad_factory(self, mock_iter_entry_points):
327330
mock_iter_entry_points.return_value = [
328-
IterEntryPoint("custom_sampler_factory", CustomSamplerFactory.empty_get_custom_sampler)
331+
IterEntryPoint(
332+
"custom_sampler_factory",
333+
CustomSamplerFactory.empty_get_custom_sampler,
334+
)
329335
]
330336
# pylint: disable=protected-access
331337
reload(trace)
@@ -340,11 +346,12 @@ def test_custom_sampler_with_env_bad_factory(
340346
OTEL_TRACES_SAMPLER_ARG: "0.5",
341347
},
342348
)
343-
def test_custom_sampler_with_env_unused_arg(
344-
self, mock_iter_entry_points
345-
):
349+
def test_custom_sampler_with_env_unused_arg(self, mock_iter_entry_points):
346350
mock_iter_entry_points.return_value = [
347-
IterEntryPoint("custom_sampler_factory", CustomSamplerFactory.get_custom_sampler)
351+
IterEntryPoint(
352+
"custom_sampler_factory",
353+
CustomSamplerFactory.get_custom_sampler,
354+
)
348355
]
349356
# pylint: disable=protected-access
350357
reload(trace)
@@ -359,11 +366,12 @@ def test_custom_sampler_with_env_unused_arg(
359366
OTEL_TRACES_SAMPLER_ARG: "0.5",
360367
},
361368
)
362-
def test_custom_ratio_sampler_with_env(
363-
self, mock_iter_entry_points
364-
):
369+
def test_custom_ratio_sampler_with_env(self, mock_iter_entry_points):
365370
mock_iter_entry_points.return_value = [
366-
IterEntryPoint("custom_ratio_sampler_factory", CustomSamplerFactory.get_custom_ratio_sampler)
371+
IterEntryPoint(
372+
"custom_ratio_sampler_factory",
373+
CustomSamplerFactory.get_custom_ratio_sampler,
374+
)
367375
]
368376
# pylint: disable=protected-access
369377
reload(trace)
@@ -383,7 +391,10 @@ def test_custom_ratio_sampler_with_env_bad_arg(
383391
self, mock_iter_entry_points
384392
):
385393
mock_iter_entry_points.return_value = [
386-
IterEntryPoint("custom_ratio_sampler_factory", CustomSamplerFactory.get_custom_ratio_sampler)
394+
IterEntryPoint(
395+
"custom_ratio_sampler_factory",
396+
CustomSamplerFactory.get_custom_ratio_sampler,
397+
)
387398
]
388399
# pylint: disable=protected-access
389400
reload(trace)
@@ -401,7 +412,10 @@ def test_custom_ratio_sampler_with_env_no_arg(
401412
self, mock_iter_entry_points
402413
):
403414
mock_iter_entry_points.return_value = [
404-
IterEntryPoint("custom_ratio_sampler_factory", CustomSamplerFactory.get_custom_ratio_sampler)
415+
IterEntryPoint(
416+
"custom_ratio_sampler_factory",
417+
CustomSamplerFactory.get_custom_ratio_sampler,
418+
)
405419
]
406420
# pylint: disable=protected-access
407421
reload(trace)
@@ -420,9 +434,18 @@ def test_custom_ratio_sampler_with_env_multiple_entry_points(
420434
self, mock_iter_entry_points
421435
):
422436
mock_iter_entry_points.return_value = [
423-
IterEntryPoint("custom_ratio_sampler_factory", CustomSamplerFactory.get_custom_ratio_sampler),
424-
IterEntryPoint("custom_sampler_factory", CustomSamplerFactory.get_custom_sampler),
425-
IterEntryPoint("custom_z_sampler_factory", CustomSamplerFactory.empty_get_custom_sampler)
437+
IterEntryPoint(
438+
"custom_ratio_sampler_factory",
439+
CustomSamplerFactory.get_custom_ratio_sampler,
440+
),
441+
IterEntryPoint(
442+
"custom_sampler_factory",
443+
CustomSamplerFactory.get_custom_sampler,
444+
),
445+
IterEntryPoint(
446+
"custom_z_sampler_factory",
447+
CustomSamplerFactory.empty_get_custom_sampler,
448+
),
426449
]
427450
# pylint: disable=protected-access
428451
reload(trace)

0 commit comments

Comments
 (0)