Skip to content

Commit 9bf694e

Browse files
add response status codes
1 parent 732cd32 commit 9bf694e

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

elastic_transport/_async_transport.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ async def perform_request( # type: ignore[override, return]
366366
# We either got a response we're happy with or
367367
# we've exhausted all of our retries so we return it.
368368
if not retry or attempt >= max_retries:
369+
otel_span.set_db_response(resp.meta.status)
369370
return TransportApiResponse(resp.meta, body)
370371
else:
371372
_logger.warning(

elastic_transport/_otel.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,9 @@ def set_db_statement(self, serialized_body: bytes) -> None:
9292
self.otel_span.set_attribute(
9393
"db.query.text", serialized_body.decode("utf-8")
9494
)
95+
96+
def set_db_response(self, status_code: int) -> None:
97+
if self.otel_span is None:
98+
return
99+
100+
self.otel_span.set_attribute("db.response.status_code", str(status_code))

elastic_transport/_transport.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ def perform_request( # type: ignore[return]
444444
# We either got a response we're happy with or
445445
# we've exhausted all of our retries so we return it.
446446
if not retry or attempt >= max_retries:
447+
otel_span.set_db_response(resp.meta.status)
447448
return TransportApiResponse(resp.meta, body)
448449
else:
449450
_logger.warning(

tests/test_otel.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def test_detailed_span():
7474
"X-Found-Handling-Instance": "instance-0000000001",
7575
}
7676
)
77+
span.set_db_response(202)
7778

7879
spans = memory_exporter.get_finished_spans()
7980
assert len(spans) == 1
@@ -88,6 +89,7 @@ def test_detailed_span():
8889
"http.request.method": "POST",
8990
"db.namespace": "e9106fc68e3044f0b1475b04bf4ffd5f",
9091
"elasticsearch.node.name": "instance-0000000001",
92+
"db.response.status_code": "202",
9193
}
9294

9395

0 commit comments

Comments
 (0)