Skip to content

Commit

Permalink
Set OpenTelemetry db.operation attribute (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
pquentin committed Mar 13, 2024
1 parent ce82b57 commit a13bf6b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions elastic_transport/_otel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions tests/test_otel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

0 comments on commit a13bf6b

Please sign in to comment.