mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-29 21:23:55 +08:00
instrumentation/redis: Change Redis instrument to use SpanKind.CLIENT (#965)
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Update default SpanKind to `SpanKind.CLIENT` ([#965](https://github.com/open-telemetry/opentelemetry-python/pull/965))
|
||||
- Change package name to opentelemetry-instrumentation-redis
|
||||
([#966](https://github.com/open-telemetry/opentelemetry-python/pull/966))
|
||||
|
||||
@ -9,4 +10,4 @@
|
||||
|
||||
Released 2020-05-12
|
||||
|
||||
- Initial release
|
||||
- Initial release
|
||||
|
@ -72,7 +72,9 @@ def _set_connection_attributes(span, conn):
|
||||
def _traced_execute_command(func, instance, args, kwargs):
|
||||
tracer = getattr(redis, "_opentelemetry_tracer")
|
||||
query = _format_command_args(args)
|
||||
with tracer.start_as_current_span(_CMD) as span:
|
||||
with tracer.start_as_current_span(
|
||||
_CMD, kind=trace.SpanKind.CLIENT
|
||||
) as span:
|
||||
span.set_attribute("service", tracer.instrumentation_info.name)
|
||||
span.set_attribute(_RAWCMD, query)
|
||||
_set_connection_attributes(span, instance)
|
||||
@ -86,7 +88,9 @@ def _traced_execute_pipeline(func, instance, args, kwargs):
|
||||
cmds = [_format_command_args(c) for c, _ in instance.command_stack]
|
||||
resource = "\n".join(cmds)
|
||||
|
||||
with tracer.start_as_current_span(_CMD) as span:
|
||||
with tracer.start_as_current_span(
|
||||
_CMD, kind=trace.SpanKind.CLIENT
|
||||
) as span:
|
||||
span.set_attribute("service", tracer.instrumentation_info.name)
|
||||
span.set_attribute(_RAWCMD, resource)
|
||||
_set_connection_attributes(span, instance)
|
||||
|
@ -17,9 +17,23 @@ import redis
|
||||
|
||||
from opentelemetry.instrumentation.redis import RedisInstrumentor
|
||||
from opentelemetry.test.test_base import TestBase
|
||||
from opentelemetry.trace import SpanKind
|
||||
|
||||
|
||||
class TestRedis(TestBase):
|
||||
def test_span_properties(self):
|
||||
redis_client = redis.Redis()
|
||||
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)
|
||||
|
||||
with mock.patch.object(redis_client, "connection"):
|
||||
redis_client.get("key")
|
||||
|
||||
spans = self.memory_exporter.get_finished_spans()
|
||||
self.assertEqual(len(spans), 1)
|
||||
span = spans[0]
|
||||
self.assertEqual(span.name, "redis.command")
|
||||
self.assertEqual(span.kind, SpanKind.CLIENT)
|
||||
|
||||
def test_instrument_uninstrument(self):
|
||||
redis_client = redis.Redis()
|
||||
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)
|
||||
|
Reference in New Issue
Block a user