Skip to content

Commit

Permalink
always set status code on duration_attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhochman committed Jun 20, 2024
1 parent a61739c commit 8138988
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -700,19 +700,21 @@ async def otel_send(message: dict[str, Any]):
) as send_span:
if callable(self.client_response_hook):
self.client_response_hook(send_span, scope, message)

status_code = None
if message["type"] == "http.response.start":
status_code = message["status"]
elif message["type"] == "websocket.send":
status_code = 200
if status_code:
duration_attrs[SpanAttributes.HTTP_STATUS_CODE] = status_code

if send_span.is_recording():
if message["type"] == "http.response.start":
status_code = message["status"]
duration_attrs[SpanAttributes.HTTP_STATUS_CODE] = (
status_code
)
expecting_trailers = message.get("trailers", False)
if status_code:
set_status_code(server_span, status_code)
set_status_code(send_span, status_code)

expecting_trailers = message.get("trailers", False)
elif message["type"] == "websocket.send":
set_status_code(server_span, 200)
set_status_code(send_span, 200)
send_span.set_attribute("asgi.event.type", message["type"])
if (
server_span.is_recording()
Expand Down

0 comments on commit 8138988

Please sign in to comment.