mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2026-03-13 08:10:39 +08:00
opentelemetry-instrumentation-redis: add default span name for pipeline operations (#3941)
* 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 <riccardo.magliocchetti@gmail.com>
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user