diff --git a/CHANGELOG.md b/CHANGELOG.md index 251720d60e..e68e8d736b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#392](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/39)) - Publish `opentelemetry-propagator-ot-trace` package as a part of the release process ([#387](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/387)) +- Update redis instrumentation to follow semantic conventions + ([#403](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/403)) ### Added - `opentelemetry-instrumentation-urllib3` Add urllib3 instrumentation diff --git a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py index 5bf83242ce..c5b8b70edf 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/__init__.py @@ -79,10 +79,9 @@ def _traced_execute_command(func, instance, args, kwargs): name, kind=trace.SpanKind.CLIENT ) as span: if span.is_recording(): - span.set_attribute("service", tracer.instrumentation_info.name) span.set_attribute(_RAWCMD, query) _set_connection_attributes(span, instance) - span.set_attribute("redis.args_length", len(args)) + span.set_attribute("db.redis.args_length", len(args)) return func(*args, **kwargs) @@ -98,11 +97,10 @@ def _traced_execute_pipeline(func, instance, args, kwargs): span_name, kind=trace.SpanKind.CLIENT ) as span: if span.is_recording(): - span.set_attribute("service", tracer.instrumentation_info.name) span.set_attribute(_RAWCMD, resource) _set_connection_attributes(span, instance) span.set_attribute( - "redis.pipeline_length", len(instance.command_stack) + "db.redis.pipeline_length", len(instance.command_stack) ) return func(*args, **kwargs) diff --git a/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py b/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py index eca14d6317..8cdbb8c4af 100644 --- a/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py +++ b/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py @@ -20,9 +20,6 @@ class TestRedisInstrument(TestBase): - - test_service = "redis" - def setUp(self): super().setUp() self.redis_client = redis.Redis(port=6379) @@ -34,7 +31,6 @@ def tearDown(self): RedisInstrumentor().uninstrument() def _check_span(self, span, name): - self.assertEqual(span.attributes["service"], self.test_service) self.assertEqual(span.name, name) self.assertIs(span.status.status_code, trace.StatusCode.UNSET) self.assertEqual(span.attributes.get("db.name"), 0) @@ -60,7 +56,7 @@ def test_basics(self): span = spans[0] self._check_span(span, "GET") self.assertEqual(span.attributes.get("db.statement"), "GET cheese") - self.assertEqual(span.attributes.get("redis.args_length"), 2) + self.assertEqual(span.attributes.get("db.redis.args_length"), 2) def test_pipeline_traced(self): with self.redis_client.pipeline(transaction=False) as pipeline: @@ -77,7 +73,7 @@ def test_pipeline_traced(self): span.attributes.get("db.statement"), "SET blah 32\nRPUSH foo éé\nHGETALL xxx", ) - self.assertEqual(span.attributes.get("redis.pipeline_length"), 3) + self.assertEqual(span.attributes.get("db.redis.pipeline_length"), 3) def test_pipeline_immediate(self): with self.redis_client.pipeline() as pipeline: @@ -111,9 +107,6 @@ def test_parent(self): self.assertEqual(parent_span.name, "redis_get") self.assertEqual(parent_span.instrumentation_info.name, "redis_svc") - self.assertEqual( - child_span.attributes.get("service"), self.test_service - ) self.assertEqual(child_span.name, "GET")