Skip to content

Commit

Permalink
Pass schema_url and version to NoOpMeter and NoOpLogger, implement co…
Browse files Browse the repository at this point in the history
…mments from review
  • Loading branch information
puskardeb committed Mar 14, 2024
1 parent bfd45e1 commit a89034d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,7 @@ def __init__(
self._multi_log_record_processor = (
multi_log_record_processor or SynchronousMultiLogRecordProcessor()
)
disabled = environ.get(OTEL_SDK_DISABLED)
if disabled is None:
disabled = "false"
disabled = environ.get(OTEL_SDK_DISABLED, "")
self._disabled = disabled.lower().strip() == "true"
self._at_exit_handler = None
if shutdown_on_exit:
Expand All @@ -628,7 +626,7 @@ def get_logger(
) -> Logger:
if self._disabled:
_logger.warning("SDK is disabled.")
return NoOpLogger(name)
return NoOpLogger(name, version=version, schema_url=schema_url)
return Logger(
self._resource,
self._multi_log_record_processor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,7 @@ def __init__(
self._measurement_consumer = SynchronousMeasurementConsumer(
sdk_config=self._sdk_config
)
disabled = environ.get(OTEL_SDK_DISABLED)
if disabled is None:
disabled = "false"
disabled = environ.get(OTEL_SDK_DISABLED, "")
self._disabled = disabled.lower().strip() == "true"

if shutdown_on_exit:
Expand Down Expand Up @@ -520,7 +518,7 @@ def get_meter(

if self._disabled:
_logger.warning("SDK is disabled.")
return NoOpMeter(name)
return NoOpMeter(name, version=version, schema_url=schema_url)

if self._shutdown:
_logger.warning(
Expand Down
4 changes: 1 addition & 3 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,9 +1177,7 @@ def __init__(
sampler = sampling._get_from_env_or_default()
self.sampler = sampler
self._span_limits = span_limits or SpanLimits()
disabled = environ.get(OTEL_SDK_DISABLED)
if disabled is None:
disabled = "false"
disabled = environ.get(OTEL_SDK_DISABLED, "")
self._disabled = disabled.lower().strip() == "true"
self._atexit_handler = None

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/tests/metrics/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def test_create_observable_up_down_counter(self):
observable_up_down_counter, ObservableUpDownCounter
)
self.assertEqual(observable_up_down_counter.name, "name")

@patch.dict("os.environ", {OTEL_SDK_DISABLED: "true"})
def test_get_meter_with_sdk_disabled(self):
meter_provider = MeterProvider()
Expand Down
4 changes: 3 additions & 1 deletion opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ def test_tracer_provider_accepts_concurrent_multi_span_processor(self):
@mock.patch.dict("os.environ", {OTEL_SDK_DISABLED: "true"})
def test_get_tracer_with_sdk_disabled(self):
tracer_provider = trace.TracerProvider()
self.assertIsInstance(tracer_provider.get_tracer(Mock()), trace_api.NoOpTracer)
self.assertIsInstance(
tracer_provider.get_tracer(Mock()), trace_api.NoOpTracer
)


class TestTracerSampling(unittest.TestCase):
Expand Down

0 comments on commit a89034d

Please sign in to comment.