From 0c4998412b4c99254dd2b7cb9125871f6ed6e26f Mon Sep 17 00:00:00 2001 From: cawthorne Date: Sun, 8 Feb 2026 14:58:43 +0000 Subject: [PATCH] Add filtered URL label to ws_connection_failover_count metrics --- src/metrics/index.ts | 2 +- src/transports/websocket.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) 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) }