Skip to content

Commit

Permalink
Add websock to telemetry metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrudel committed Jan 3, 2025
1 parent 2344746 commit 6aa3ec2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/bandit/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ defmodule Bandit.Telemetry do
* `telemetry_span_context`: A unique identifier for this span
* `connection_telemetry_span_context`: The span context of the Thousand Island `:connection`
span which contains this request
* `websock`: The WebSock which is being used to serve this request. Specified as `websock_module`
This span is ended by the following event:
Expand Down Expand Up @@ -146,6 +147,7 @@ defmodule Bandit.Telemetry do
this connection originated
* `connection_telemetry_span_context`: The span context of the Thousand Island `:connection`
span which contains this request
* `websock`: The WebSock which is being used to serve this request. Specified as `websock_module`
* `error`: The error that caused the span to end, if it ended in error
"""

Expand Down
3 changes: 2 additions & 1 deletion lib/bandit/websocket/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ defmodule Bandit.WebSocket.Connection do

span =
Bandit.Telemetry.start_span(:websocket, %{compress: compress}, %{
connection_telemetry_span_context: connection_telemetry_span_context
connection_telemetry_span_context: connection_telemetry_span_context,
websock: websock
})

instance = %__MODULE__{
Expand Down
17 changes: 12 additions & 5 deletions test/bandit/websocket/sock_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,8 @@ defmodule WebSocketWebSockTest do
%{monotonic_time: integer(), compress: maybe(boolean())},
%{
connection_telemetry_span_context: reference(),
telemetry_span_context: reference()
telemetry_span_context: reference(),
websock: TelemetrySock
}}
]
end
Expand Down Expand Up @@ -1351,7 +1352,8 @@ defmodule WebSocketWebSockTest do
},
%{
connection_telemetry_span_context: reference(),
telemetry_span_context: reference()
telemetry_span_context: reference(),
websock: TelemetrySock
}}
]
end
Expand All @@ -1376,7 +1378,8 @@ defmodule WebSocketWebSockTest do
},
%{
connection_telemetry_span_context: reference(),
telemetry_span_context: reference()
telemetry_span_context: reference(),
websock: TelemetrySock
}}
]
end
Expand All @@ -1401,7 +1404,8 @@ defmodule WebSocketWebSockTest do
},
%{
connection_telemetry_span_context: reference(),
telemetry_span_context: reference()
telemetry_span_context: reference(),
websock: TelemetrySock
}}
]
end
Expand All @@ -1420,7 +1424,8 @@ defmodule WebSocketWebSockTest do
{[:bandit, :websocket, :stop], %{monotonic_time: integer(), duration: integer()},
%{
connection_telemetry_span_context: reference(),
telemetry_span_context: reference()
telemetry_span_context: reference(),
websock: TelemetrySock
}}
]
end
Expand Down Expand Up @@ -1448,6 +1453,7 @@ defmodule WebSocketWebSockTest do
%{
connection_telemetry_span_context: reference(),
telemetry_span_context: reference(),
websock: TelemetrySock,
error: :nope
}}
]
Expand All @@ -1472,6 +1478,7 @@ defmodule WebSocketWebSockTest do
%{
connection_telemetry_span_context: reference(),
telemetry_span_context: reference(),
websock: TelemetrySock,
error: :timeout
}}
]
Expand Down

0 comments on commit 6aa3ec2

Please sign in to comment.