Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/transports/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,20 +289,25 @@ export class WebSocketTransport<

// Called when the WS connection closes for any reason
close: (event: WebSocket.CloseEvent) => {
// If the connection closed with 1000, it's a usual closure
const level = event.code === 1000 ? 'debug' : 'info'
logger[level](
`Closed websocket connection. Code: ${event.code} ; reason: ${event.reason?.toString()}`,
)
const filteredUrl = this.currentUrl.split('?')[0]
const isAbnormal = event.code !== 1000
Comment thread
cawthorne marked this conversation as resolved.

// Record active ws connections by decrementing count on close
// Using URL in label since connection_key is removed from v3
metrics.get('wsConnectionActive').dec()
if (isAbnormal) {
this.streamHandlerInvocationsWithNoConnection += 1
logger.warn(
`WebSocket closed abnormally (code: ${event.code}, reason: ${event.reason?.toString() || 'none'}). ` +
`Failover counter incremented to ${this.streamHandlerInvocationsWithNoConnection}. ` +
`URL: ${filteredUrl}`,
)
metrics
.get('wsConnectionFailoverCount')
.labels({ transport_name: this.name, url: filteredUrl })
.set(this.streamHandlerInvocationsWithNoConnection)
Comment thread
cawthorne marked this conversation as resolved.
Outdated
} else {
logger.debug(`WebSocket closed normally (code: ${event.code}). URL: ${filteredUrl}`)
}

// Also, register that the connection was closed and the reason why.
// We need to filter out query params from the URL to avoid having
// the cardinality of the metric go out of control.
const filteredUrl = this.currentUrl.split('?')[0]
metrics.get('wsConnectionActive').dec()
metrics.get('wsConnectionClosures').inc({
code: event.code,
url: filteredUrl,
Expand Down
Loading
Loading