Skip to content

Commit

Permalink
Change Redis instrument to use SpanKind.CLIENT
Browse files Browse the repository at this point in the history
  • Loading branch information
akoumjian committed Aug 4, 2020
1 parent 57ca703 commit b3801b1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

## Unreleased

- Update default SpanKind to `SpanKind.CLIENT` ([#965](https://github.com/open-telemetry/opentelemetry-python/pull/965))
- Change package name to opentelemetry-instrumentation-redis
([#999](https://github.com/open-telemetry/opentelemetry-python/pull/999))

## 0.7b1

Released 2020-05-12

- Initial release
- Initial release
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@


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 b3801b1

Please sign in to comment.