Skip to content

Commit 634c2ac

Browse files
authored
Update redis instrumentation to follow semantic conventions (#403)
1 parent 92004b1 commit 634c2ac

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
([#392](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/39))
1414
- Publish `opentelemetry-propagator-ot-trace` package as a part of the release process
1515
([#387](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/387))
16+
- Update redis instrumentation to follow semantic conventions
17+
([#403](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/403))
1618

1719
### Added
1820
- `opentelemetry-instrumentation-urllib3` Add urllib3 instrumentation

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@ def _traced_execute_command(func, instance, args, kwargs):
7979
name, kind=trace.SpanKind.CLIENT
8080
) as span:
8181
if span.is_recording():
82-
span.set_attribute("service", tracer.instrumentation_info.name)
8382
span.set_attribute(_RAWCMD, query)
8483
_set_connection_attributes(span, instance)
85-
span.set_attribute("redis.args_length", len(args))
84+
span.set_attribute("db.redis.args_length", len(args))
8685
return func(*args, **kwargs)
8786

8887

@@ -98,11 +97,10 @@ def _traced_execute_pipeline(func, instance, args, kwargs):
9897
span_name, kind=trace.SpanKind.CLIENT
9998
) as span:
10099
if span.is_recording():
101-
span.set_attribute("service", tracer.instrumentation_info.name)
102100
span.set_attribute(_RAWCMD, resource)
103101
_set_connection_attributes(span, instance)
104102
span.set_attribute(
105-
"redis.pipeline_length", len(instance.command_stack)
103+
"db.redis.pipeline_length", len(instance.command_stack)
106104
)
107105
return func(*args, **kwargs)
108106

tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020

2121

2222
class TestRedisInstrument(TestBase):
23-
24-
test_service = "redis"
25-
2623
def setUp(self):
2724
super().setUp()
2825
self.redis_client = redis.Redis(port=6379)
@@ -34,7 +31,6 @@ def tearDown(self):
3431
RedisInstrumentor().uninstrument()
3532

3633
def _check_span(self, span, name):
37-
self.assertEqual(span.attributes["service"], self.test_service)
3834
self.assertEqual(span.name, name)
3935
self.assertIs(span.status.status_code, trace.StatusCode.UNSET)
4036
self.assertEqual(span.attributes.get("db.name"), 0)
@@ -60,7 +56,7 @@ def test_basics(self):
6056
span = spans[0]
6157
self._check_span(span, "GET")
6258
self.assertEqual(span.attributes.get("db.statement"), "GET cheese")
63-
self.assertEqual(span.attributes.get("redis.args_length"), 2)
59+
self.assertEqual(span.attributes.get("db.redis.args_length"), 2)
6460

6561
def test_pipeline_traced(self):
6662
with self.redis_client.pipeline(transaction=False) as pipeline:
@@ -77,7 +73,7 @@ def test_pipeline_traced(self):
7773
span.attributes.get("db.statement"),
7874
"SET blah 32\nRPUSH foo éé\nHGETALL xxx",
7975
)
80-
self.assertEqual(span.attributes.get("redis.pipeline_length"), 3)
76+
self.assertEqual(span.attributes.get("db.redis.pipeline_length"), 3)
8177

8278
def test_pipeline_immediate(self):
8379
with self.redis_client.pipeline() as pipeline:
@@ -111,9 +107,6 @@ def test_parent(self):
111107
self.assertEqual(parent_span.name, "redis_get")
112108
self.assertEqual(parent_span.instrumentation_info.name, "redis_svc")
113109

114-
self.assertEqual(
115-
child_span.attributes.get("service"), self.test_service
116-
)
117110
self.assertEqual(child_span.name, "GET")
118111

119112

0 commit comments

Comments
 (0)