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", }