Skip to content

Commit d219775

Browse files
authored
Add filtered URL label to ws_connection_failover_count metrics (#684)
1 parent bab96ca commit d219775

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/metrics/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,6 @@ export const metrics = new Metrics(() => ({
360360
wsConnectionFailoverCount: new client.Gauge({
361361
name: 'ws_connection_failover_count',
362362
help: 'The number of consecutive unresponsive connection detections (no data for WS_SUBSCRIPTION_UNRESPONSIVE_TTL), used to trigger URL failover',
363-
labelNames: ['transport_name'] as const,
363+
labelNames: ['transport_name', 'url'] as const,
364364
}),
365365
}))

src/transports/websocket.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,12 @@ export class WebSocketTransport<
417417
logger.info(
418418
`The connection is unresponsive (last message ${timeSinceLastMessage}ms ago), incremented failover counter to ${this.streamHandlerInvocationsWithNoConnection}`,
419419
)
420+
// Filter out query params from the URL to avoid leaking sensitive data
421+
// and prevent metric cardinality explosion
422+
const filteredUrl = this.currentUrl.split('?')[0]
420423
metrics
421424
.get('wsConnectionFailoverCount')
422-
.labels({ transport_name: this.name })
425+
.labels({ transport_name: this.name, url: filteredUrl })
423426
.set(this.streamHandlerInvocationsWithNoConnection)
424427
}
425428

0 commit comments

Comments
 (0)