Skip to content

Commit a13bf6b

Browse files
authored
Set OpenTelemetry db.operation attribute (elastic#153)
1 parent ce82b57 commit a13bf6b

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

elastic_transport/_otel.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def span(
5555
with self.tracer.start_as_current_span(span_name) as span:
5656
span.set_attribute("http.request.method", method)
5757
span.set_attribute("db.system", "elasticsearch")
58+
if endpoint_id is not None:
59+
span.set_attribute("db.operation", endpoint_id)
5860
for key, value in path_parts.items():
5961
span.set_attribute(f"db.elasticsearch.path_parts.{key}", value)
6062
yield

tests/test_otel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def test_detailed_span():
6262
assert spans[0].attributes == {
6363
"http.request.method": "GET",
6464
"db.system": "elasticsearch",
65+
"db.operation": "ml.close_job",
6566
"db.elasticsearch.path_parts.job_id": "my-job",
6667
"db.elasticsearch.path_parts.foo": "bar",
6768
}

0 commit comments

Comments
 (0)