Skip to content

Commit

Permalink
Update redis instrumentation to follow semantic conventions (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthccv committed Apr 5, 2021
1 parent 92004b1 commit 634c2ac
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@


class TestRedisInstrument(TestBase):

test_service = "redis"

def setUp(self):
super().setUp()
self.redis_client = redis.Redis(port=6379)
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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")


Expand Down

0 comments on commit 634c2ac

Please sign in to comment.