mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-29 13:12:39 +08:00
Update redis instrumentation to follow semantic conventions (#403)
This commit is contained in:
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -20,9 +20,6 @@ from opentelemetry.test.test_base import TestBase
|
||||
|
||||
|
||||
class TestRedisInstrument(TestBase):
|
||||
|
||||
test_service = "redis"
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.redis_client = redis.Redis(port=6379)
|
||||
@ -34,7 +31,6 @@ class TestRedisInstrument(TestBase):
|
||||
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 @@ class TestRedisInstrument(TestBase):
|
||||
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 @@ class TestRedisInstrument(TestBase):
|
||||
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 @@ class TestRedisInstrument(TestBase):
|
||||
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")
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user