From de1ebc5447339bb255afb532aea299a4e57faa46 Mon Sep 17 00:00:00 2001 From: "C, Chandru" Date: Fri, 21 Jun 2024 17:57:33 +0530 Subject: [PATCH 1/2] Added testcode For #976 Signed-off-by: C, Chandru --- .../tests/test_logging.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-logging/tests/test_logging.py b/instrumentation/opentelemetry-instrumentation-logging/tests/test_logging.py index a5a0d5adff..b7b086d020 100644 --- a/instrumentation/opentelemetry-instrumentation-logging/tests/test_logging.py +++ b/instrumentation/opentelemetry-instrumentation-logging/tests/test_logging.py @@ -23,7 +23,7 @@ LoggingInstrumentor, ) from opentelemetry.test.test_base import TestBase -from opentelemetry.trace import ProxyTracer, get_tracer +from opentelemetry.trace import ProxyTracer, get_tracer, NoOpTracerProvider class FakeTracerProvider: @@ -207,3 +207,18 @@ def test_uninstrumented(self): self.assertFalse(hasattr(record, "otelTraceID")) self.assertFalse(hasattr(record, "otelServiceName")) self.assertFalse(hasattr(record, "otelTraceSampled")) + + def test_no_op_tracer_provider(self): + LoggingInstrumentor().uninstrument() + LoggingInstrumentor().instrument(tracer_provider=NoOpTracerProvider()) + + with self.caplog.at_level(level=logging.INFO): + logger = logging.getLogger("test logger") + logger.info("hello") + + self.assertEqual(len(self.caplog.records), 1) + record = self.caplog.records[0] + self.assertEqual(record.otelSpanID, "0") + self.assertEqual(record.otelTraceID, "0") + self.assertEqual(record.otelServiceName, "") + self.assertEqual(record.otelTraceSampled, False) From 311d679b7765f7f01071b6ed17aab11bacdf998c Mon Sep 17 00:00:00 2001 From: "C, Chandru" Date: Fri, 19 Jul 2024 17:10:02 +0530 Subject: [PATCH 2/2] Fixing Linting Issues as per the review comments Signed-off-by: C, Chandru --- .../tests/test_logging.py | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-logging/tests/test_logging.py b/instrumentation/opentelemetry-instrumentation-logging/tests/test_logging.py index b7b086d020..c8b8744cf3 100644 --- a/instrumentation/opentelemetry-instrumentation-logging/tests/test_logging.py +++ b/instrumentation/opentelemetry-instrumentation-logging/tests/test_logging.py @@ -23,7 +23,7 @@ LoggingInstrumentor, ) from opentelemetry.test.test_base import TestBase -from opentelemetry.trace import ProxyTracer, get_tracer, NoOpTracerProvider +from opentelemetry.trace import NoOpTracerProvider, ProxyTracer, get_tracer class FakeTracerProvider: @@ -209,16 +209,16 @@ def test_uninstrumented(self): self.assertFalse(hasattr(record, "otelTraceSampled")) def test_no_op_tracer_provider(self): - LoggingInstrumentor().uninstrument() - LoggingInstrumentor().instrument(tracer_provider=NoOpTracerProvider()) - - with self.caplog.at_level(level=logging.INFO): - logger = logging.getLogger("test logger") - logger.info("hello") - - self.assertEqual(len(self.caplog.records), 1) - record = self.caplog.records[0] - self.assertEqual(record.otelSpanID, "0") - self.assertEqual(record.otelTraceID, "0") - self.assertEqual(record.otelServiceName, "") - self.assertEqual(record.otelTraceSampled, False) + LoggingInstrumentor().uninstrument() + LoggingInstrumentor().instrument(tracer_provider=NoOpTracerProvider()) + + with self.caplog.at_level(level=logging.INFO): + logger = logging.getLogger("test logger") + logger.info("hello") + + self.assertEqual(len(self.caplog.records), 1) + record = self.caplog.records[0] + self.assertEqual(record.otelSpanID, "0") + self.assertEqual(record.otelTraceID, "0") + self.assertEqual(record.otelServiceName, "") + self.assertEqual(record.otelTraceSampled, False)