diff --git a/src/metrics/index.ts b/src/metrics/index.ts index 658b46a6..ca082f87 100644 --- a/src/metrics/index.ts +++ b/src/metrics/index.ts @@ -360,6 +360,6 @@ export const metrics = new Metrics(() => ({ wsConnectionFailoverCount: new client.Gauge({ name: 'ws_connection_failover_count', help: 'The number of consecutive unresponsive connection detections (no data for WS_SUBSCRIPTION_UNRESPONSIVE_TTL), used to trigger URL failover', - labelNames: ['transport_name'] as const, + labelNames: ['transport_name', 'url'] as const, }), })) diff --git a/src/transports/websocket.ts b/src/transports/websocket.ts index de74ac64..f38736dc 100644 --- a/src/transports/websocket.ts +++ b/src/transports/websocket.ts @@ -417,9 +417,12 @@ export class WebSocketTransport< logger.info( `The connection is unresponsive (last message ${timeSinceLastMessage}ms ago), incremented failover counter to ${this.streamHandlerInvocationsWithNoConnection}`, ) + // Filter out query params from the URL to avoid leaking sensitive data + // and prevent metric cardinality explosion + const filteredUrl = this.currentUrl.split('?')[0] metrics .get('wsConnectionFailoverCount') - .labels({ transport_name: this.name }) + .labels({ transport_name: this.name, url: filteredUrl }) .set(this.streamHandlerInvocationsWithNoConnection) }