Skip to content

Commit

Permalink
Added testcode For #976
Browse files Browse the repository at this point in the history
Signed-off-by: C, Chandru <[email protected]>
  • Loading branch information
the-chandru committed Jul 23, 2024
1 parent cc52bd2 commit de1ebc5
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

0 comments on commit de1ebc5

Please sign in to comment.