From c5ec903534cd8cb74ed6b147967939e6ba2ca094 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Thu, 3 Jul 2025 17:27:19 +0100 Subject: [PATCH] Update opentelemetry conventions --- elasticsearch/_otel.py | 8 ++++---- test_elasticsearch/test_otel.py | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/elasticsearch/_otel.py b/elasticsearch/_otel.py index f37ca24cd..69509a80e 100644 --- a/elasticsearch/_otel.py +++ b/elasticsearch/_otel.py @@ -77,9 +77,9 @@ def span( otel_span.set_attribute("http.request.method", method) otel_span.set_attribute("db.system", "elasticsearch") if endpoint_id is not None: - otel_span.set_attribute("db.operation", endpoint_id) + otel_span.set_attribute("db.operation.name", endpoint_id) for key, value in path_parts.items(): - otel_span.set_attribute(f"db.elasticsearch.path_parts.{key}", value) + otel_span.set_attribute(f"db.operation.parameter.{key}", value) yield OpenTelemetrySpan( otel_span, @@ -94,8 +94,8 @@ def helpers_span(self, span_name: str) -> Generator[OpenTelemetrySpan, None, Non return with self.tracer.start_as_current_span(span_name) as otel_span: - otel_span.set_attribute("db.system", "elasticsearch") - otel_span.set_attribute("db.operation", span_name) + otel_span.set_attribute("db.system.name", "elasticsearch") + otel_span.set_attribute("db.operation.name", span_name) # Without a request method, Elastic APM does not display the traces otel_span.set_attribute("http.request.method", "null") yield OpenTelemetrySpan(otel_span) diff --git a/test_elasticsearch/test_otel.py b/test_elasticsearch/test_otel.py index 48eb9ea58..39edf5869 100644 --- a/test_elasticsearch/test_otel.py +++ b/test_elasticsearch/test_otel.py @@ -68,7 +68,7 @@ def test_minimal_span(): assert spans[0].name == "GET" assert spans[0].attributes == { "http.request.method": "GET", - "db.system": "elasticsearch", + "db.system.name": "elasticsearch", } @@ -92,11 +92,11 @@ def test_detailed_span(): assert spans[0].name == "ml.open_job" assert spans[0].attributes == { "http.request.method": "GET", - "db.system": "elasticsearch", - "db.operation": "ml.open_job", - "db.elasticsearch.path_parts.job_id": "my-job", - "db.elasticsearch.cluster.name": "e9106fc68e3044f0b1475b04bf4ffd5f", - "db.elasticsearch.node.name": "instance-0000000001", + "db.system.name": "elasticsearch", + "db.operation.name": "ml.open_job", + "db.operation.parameter.job_id": "my-job", + "db.namespace": "e9106fc68e3044f0b1475b04bf4ffd5f", + "elasticsearch.node.name": "instance-0000000001", }