mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-30 05:32:30 +08:00
Update redis instrumentation to follow semantic conventions
This commit is contained in:
@ -59,7 +59,6 @@ from opentelemetry.instrumentation.utils import unwrap
|
||||
|
||||
_DEFAULT_SERVICE = "redis"
|
||||
_RAWCMD = "db.statement"
|
||||
_CMD = "redis.command"
|
||||
|
||||
|
||||
def _set_connection_attributes(span, conn):
|
||||
@ -75,7 +74,7 @@ def _traced_execute_command(func, instance, args, kwargs):
|
||||
tracer = getattr(redis, "_opentelemetry_tracer")
|
||||
query = _format_command_args(args)
|
||||
with tracer.start_as_current_span(
|
||||
_CMD, kind=trace.SpanKind.CLIENT
|
||||
args[0], kind=trace.SpanKind.CLIENT
|
||||
) as span:
|
||||
if span.is_recording():
|
||||
span.set_attribute("service", tracer.instrumentation_info.name)
|
||||
@ -91,8 +90,11 @@ def _traced_execute_pipeline(func, instance, args, kwargs):
|
||||
cmds = [_format_command_args(c) for c, _ in instance.command_stack]
|
||||
resource = "\n".join(cmds)
|
||||
|
||||
pipeline_cmnds = " ".join([args[0] for args, _ in instance.command_stack])
|
||||
span_name = "PIPELINE" + " " + pipeline_cmnds
|
||||
|
||||
with tracer.start_as_current_span(
|
||||
_CMD, kind=trace.SpanKind.CLIENT
|
||||
span_name, kind=trace.SpanKind.CLIENT
|
||||
) as span:
|
||||
if span.is_recording():
|
||||
span.set_attribute("service", tracer.instrumentation_info.name)
|
||||
|
@ -20,15 +20,16 @@ Some utils used by the redis integration
|
||||
def _extract_conn_attributes(conn_kwargs):
|
||||
""" Transform redis conn info into dict """
|
||||
attributes = {
|
||||
"db.type": "redis",
|
||||
"db.instance": conn_kwargs.get("db", 0),
|
||||
"db.system": "redis",
|
||||
"db.name": conn_kwargs.get("db", 0),
|
||||
}
|
||||
try:
|
||||
attributes["db.url"] = "redis://{}:{}".format(
|
||||
conn_kwargs["host"], conn_kwargs["port"]
|
||||
)
|
||||
attributes["net.peer.name"] = conn_kwargs["host"]
|
||||
attributes["net.peer.ip"] = conn_kwargs["port"]
|
||||
attributes["net.transport"] = "IP.TCP"
|
||||
except KeyError:
|
||||
pass # don't include url attribute
|
||||
attributes["net.peer.name"] = conn_kwargs["path"]
|
||||
attributes["net.transport"] = "Unix"
|
||||
|
||||
return attributes
|
||||
|
||||
|
@ -31,7 +31,7 @@ class TestRedis(TestBase):
|
||||
spans = self.memory_exporter.get_finished_spans()
|
||||
self.assertEqual(len(spans), 1)
|
||||
span = spans[0]
|
||||
self.assertEqual(span.name, "redis.command")
|
||||
self.assertEqual(span.name, "GET")
|
||||
self.assertEqual(span.kind, SpanKind.CLIENT)
|
||||
|
||||
def test_not_recording(self):
|
||||
|
Reference in New Issue
Block a user