From 494bf0999cd8f62da5a26998fce1f92400c5976e Mon Sep 17 00:00:00 2001 From: avzis <107620508+avzis@users.noreply.github.com> Date: Mon, 9 Jan 2023 11:15:00 +0200 Subject: [PATCH] add a test for redis using NoOpTracerProvider (#1559) --- .../tests/test_redis.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py b/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py index 3d5479e731..3abcb516ff 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py +++ b/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py @@ -15,6 +15,7 @@ import redis +from opentelemetry import trace from opentelemetry.instrumentation.redis import RedisInstrumentor from opentelemetry.test.test_base import TestBase from opentelemetry.trace import SpanKind @@ -146,3 +147,16 @@ def request_hook(span, conn, args, kwargs): span = spans[0] self.assertEqual(span.attributes.get(custom_attribute_name), "GET") + + def test_no_op_tracer_provider(self): + RedisInstrumentor().uninstrument() + tracer_provider = trace.NoOpTracerProvider + RedisInstrumentor().instrument(tracer_provider=tracer_provider) + + redis_client = redis.Redis() + + with mock.patch.object(redis_client, "connection"): + redis_client.get("key") + + spans = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans), 0)