Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update redis instrumentation to follow semantic conventions #403

Merged
merged 5 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to db.redis.database_index; DB specific attribute keys should be in the form of db.{identifier}.{}.

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