Skip to content

Commit a60f1a7

Browse files
committed
opentelemetry-instrumentation-redis: add default span name for pipeline operations
1 parent bd3c1f2 commit a60f1a7

File tree

2 files changed

+28
-1
lines changed
  • instrumentation/opentelemetry-instrumentation-redis

2 files changed

+28
-1
lines changed

instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,4 @@ def _build_span_meta_data_for_pipeline(
207207
resource = ""
208208
span_name = ""
209209

210-
return command_stack, resource, span_name
210+
return command_stack, resource, span_name or "redis"

instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,17 @@ def redis_operations():
390390
self.assertEqual(span.kind, SpanKind.CLIENT)
391391
self.assertEqual(span.status.status_code, trace.StatusCode.UNSET)
392392

393+
def test_span_name_empty_pipeline(self):
394+
redis_client = fakeredis.FakeStrictRedis()
395+
pipe = redis_client.pipeline()
396+
pipe.execute()
397+
398+
spans = self.memory_exporter.get_finished_spans()
399+
self.assertEqual(len(spans), 1)
400+
self.assertEqual(spans[0].name, "redis")
401+
self.assertEqual(spans[0].kind, SpanKind.CLIENT)
402+
self.assertEqual(spans[0].status.status_code, trace.StatusCode.UNSET)
403+
393404

394405
class TestRedisAsync(TestBase, IsolatedAsyncioTestCase):
395406
def assert_span_count(self, count: int):
@@ -543,6 +554,22 @@ def response_hook(span, conn, args):
543554
await self.client.set("key", "value")
544555
spans = self.assert_span_count(0)
545556

557+
@pytest.mark.asyncio
558+
async def test_span_name_empty_pipeline(self):
559+
redis_client = fakeredis.aioredis.FakeRedis()
560+
self.instrumentor.instrument_client(
561+
client=redis_client, tracer_provider=self.tracer_provider
562+
)
563+
async with redis_client.pipeline() as pipe:
564+
await pipe.execute()
565+
566+
spans = self.memory_exporter.get_finished_spans()
567+
self.assertEqual(len(spans), 1)
568+
self.assertEqual(spans[0].name, "redis")
569+
self.assertEqual(spans[0].kind, SpanKind.CLIENT)
570+
self.assertEqual(spans[0].status.status_code, trace.StatusCode.UNSET)
571+
self.instrumentor.uninstrument_client(client=redis_client)
572+
546573

547574
class TestRedisInstance(TestBase):
548575
def assert_span_count(self, count: int):

0 commit comments

Comments
 (0)