From a13bf6bc42e21f225bb796fbbe7c62ae1911dd3a Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Wed, 13 Mar 2024 10:50:52 +0400 Subject: [PATCH] Set OpenTelemetry db.operation attribute (#153) --- elastic_transport/_otel.py | 2 ++ tests/test_otel.py | 1 + 2 files changed, 3 insertions(+) diff --git a/elastic_transport/_otel.py b/elastic_transport/_otel.py index 1591c2c..a413252 100644 --- a/elastic_transport/_otel.py +++ b/elastic_transport/_otel.py @@ -55,6 +55,8 @@ def span( with self.tracer.start_as_current_span(span_name) as span: span.set_attribute("http.request.method", method) span.set_attribute("db.system", "elasticsearch") + if endpoint_id is not None: + span.set_attribute("db.operation", endpoint_id) for key, value in path_parts.items(): span.set_attribute(f"db.elasticsearch.path_parts.{key}", value) yield diff --git a/tests/test_otel.py b/tests/test_otel.py index ed2ba91..f404779 100644 --- a/tests/test_otel.py +++ b/tests/test_otel.py @@ -62,6 +62,7 @@ def test_detailed_span(): assert spans[0].attributes == { "http.request.method": "GET", "db.system": "elasticsearch", + "db.operation": "ml.close_job", "db.elasticsearch.path_parts.job_id": "my-job", "db.elasticsearch.path_parts.foo": "bar", }