From 1d9728297742f5e772e33a70290307685ae0da2c Mon Sep 17 00:00:00 2001 From: Lukas Hering <40302054+herin049@users.noreply.github.com> Date: Tue, 18 Nov 2025 08:57:45 -0500 Subject: [PATCH] opentelemetry-instrumentation-redis: add default span name for pipeline operations (#3941) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * opentelemetry-instrumentation-redis: add default span name for pipeline operations * update CHANGELOG.md --------- Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com> Co-authored-by: Riccardo Magliocchetti --- CHANGELOG.md | 2 ++ .../instrumentation/redis/util.py | 2 +- .../tests/test_redis.py | 27 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 290e67bf5..c124687a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3904](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3904)) - build: bump ruff to 0.14.1 ([#3842](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3842)) +- `opentelemetry-instrumentation-redis`: Add default span name for pipeline operations + ([#3941](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3941)) - `opentelemetry-instrumentation-pymongo`: Fix invalid mongodb collection attribute type ([#3942](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3942)) diff --git a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py index 03cc0a5dc..320758f84 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py +++ b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py @@ -207,4 +207,4 @@ def _build_span_meta_data_for_pipeline( resource = "" span_name = "" - return command_stack, resource, span_name + return command_stack, resource, span_name or "redis" diff --git a/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py b/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py index 7d5a3b3dc..b8a5c8113 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py +++ b/instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py @@ -390,6 +390,17 @@ class TestRedis(TestBase): self.assertEqual(span.kind, SpanKind.CLIENT) self.assertEqual(span.status.status_code, trace.StatusCode.UNSET) + def test_span_name_empty_pipeline(self): + redis_client = fakeredis.FakeStrictRedis() + pipe = redis_client.pipeline() + pipe.execute() + + spans = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans), 1) + self.assertEqual(spans[0].name, "redis") + self.assertEqual(spans[0].kind, SpanKind.CLIENT) + self.assertEqual(spans[0].status.status_code, trace.StatusCode.UNSET) + class TestRedisAsync(TestBase, IsolatedAsyncioTestCase): def assert_span_count(self, count: int): @@ -543,6 +554,22 @@ class TestRedisAsync(TestBase, IsolatedAsyncioTestCase): await self.client.set("key", "value") spans = self.assert_span_count(0) + @pytest.mark.asyncio + async def test_span_name_empty_pipeline(self): + redis_client = fakeredis.aioredis.FakeRedis() + self.instrumentor.instrument_client( + client=redis_client, tracer_provider=self.tracer_provider + ) + async with redis_client.pipeline() as pipe: + await pipe.execute() + + spans = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans), 1) + self.assertEqual(spans[0].name, "redis") + self.assertEqual(spans[0].kind, SpanKind.CLIENT) + self.assertEqual(spans[0].status.status_code, trace.StatusCode.UNSET) + self.instrumentor.uninstrument_client(client=redis_client) + class TestRedisInstance(TestBase): def assert_span_count(self, count: int):