Skip to content

Commit 8138988

Browse files
committed
always set status code on duration_attrs
1 parent a61739c commit 8138988

File tree

1 file changed

+11
-9
lines changed
  • instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi

1 file changed

+11
-9
lines changed

instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -700,19 +700,21 @@ async def otel_send(message: dict[str, Any]):
700700
) as send_span:
701701
if callable(self.client_response_hook):
702702
self.client_response_hook(send_span, scope, message)
703+
704+
status_code = None
705+
if message["type"] == "http.response.start":
706+
status_code = message["status"]
707+
elif message["type"] == "websocket.send":
708+
status_code = 200
709+
if status_code:
710+
duration_attrs[SpanAttributes.HTTP_STATUS_CODE] = status_code
711+
703712
if send_span.is_recording():
704713
if message["type"] == "http.response.start":
705-
status_code = message["status"]
706-
duration_attrs[SpanAttributes.HTTP_STATUS_CODE] = (
707-
status_code
708-
)
714+
expecting_trailers = message.get("trailers", False)
715+
if status_code:
709716
set_status_code(server_span, status_code)
710717
set_status_code(send_span, status_code)
711-
712-
expecting_trailers = message.get("trailers", False)
713-
elif message["type"] == "websocket.send":
714-
set_status_code(server_span, 200)
715-
set_status_code(send_span, 200)
716718
send_span.set_attribute("asgi.event.type", message["type"])
717719
if (
718720
server_span.is_recording()

0 commit comments

Comments
 (0)