Skip to content

Commit

Permalink
Change default redis SpanKind to CLIENT
Browse files Browse the repository at this point in the history
  • Loading branch information
akoumjian committed Aug 2, 2020
1 parent 1112792 commit db9e883
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions ext/opentelemetry-ext-redis/tests/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,23 @@

from opentelemetry.ext.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)
Expand Down

0 comments on commit db9e883

Please sign in to comment.