Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9558900

Browse files
authored
instrumentation/redis: Change Redis instrument to use SpanKind.CLIENT (open-telemetry#965)
1 parent eb8b1ea commit 9558900

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

instrumentation/opentelemetry-instrumentation-redis/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
## Unreleased
44

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

89
## 0.7b1
910

1011
Released 2020-05-12
1112

12-
- Initial release
13+
- Initial release

instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ def _set_connection_attributes(span, conn):
7272
def _traced_execute_command(func, instance, args, kwargs):
7373
tracer = getattr(redis, "_opentelemetry_tracer")
7474
query = _format_command_args(args)
75-
with tracer.start_as_current_span(_CMD) as span:
75+
with tracer.start_as_current_span(
76+
_CMD, kind=trace.SpanKind.CLIENT
77+
) as span:
7678
span.set_attribute("service", tracer.instrumentation_info.name)
7779
span.set_attribute(_RAWCMD, query)
7880
_set_connection_attributes(span, instance)
@@ -86,7 +88,9 @@ def _traced_execute_pipeline(func, instance, args, kwargs):
8688
cmds = [_format_command_args(c) for c, _ in instance.command_stack]
8789
resource = "\n".join(cmds)
8890

89-
with tracer.start_as_current_span(_CMD) as span:
91+
with tracer.start_as_current_span(
92+
_CMD, kind=trace.SpanKind.CLIENT
93+
) as span:
9094
span.set_attribute("service", tracer.instrumentation_info.name)
9195
span.set_attribute(_RAWCMD, resource)
9296
_set_connection_attributes(span, instance)

instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,23 @@
1717

1818
from opentelemetry.instrumentation.redis import RedisInstrumentor
1919
from opentelemetry.test.test_base import TestBase
20+
from opentelemetry.trace import SpanKind
2021

2122

2223
class TestRedis(TestBase):
24+
def test_span_properties(self):
25+
redis_client = redis.Redis()
26+
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)
27+
28+
with mock.patch.object(redis_client, "connection"):
29+
redis_client.get("key")
30+
31+
spans = self.memory_exporter.get_finished_spans()
32+
self.assertEqual(len(spans), 1)
33+
span = spans[0]
34+
self.assertEqual(span.name, "redis.command")
35+
self.assertEqual(span.kind, SpanKind.CLIENT)
36+
2337
def test_instrument_uninstrument(self):
2438
redis_client = redis.Redis()
2539
RedisInstrumentor().instrument(tracer_provider=self.tracer_provider)

0 commit comments

Comments
 (0)