Skip to content

Commit 5e7262a

Browse files
committed
feat: add whiteListedURLs to web-socket instrumentation config
1 parent a72bdc0 commit 5e7262a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

experimental/instrumentation-websocket/src/instrumentation.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class WebSocketInstrumentation<T = Record<string, unknown>> extends Instr
1717

1818
private messageTransform: MessageTransform<T>;
1919
private sendTransform: MessageTransform<T>;
20+
private whiteListedURLs: string[];
2021

2122
private pendingRequests = new Map<number, PendingRequest>();
2223

@@ -25,6 +26,7 @@ export class WebSocketInstrumentation<T = Record<string, unknown>> extends Instr
2526

2627
this.messageTransform = options.messageTransform ?? this.defaultTransform;
2728
this.sendTransform = options.sendTransform ?? this.defaultTransform;
29+
this.whiteListedURLs = options.whiteListedURLs ?? [];
2830
}
2931

3032
protected init() {
@@ -88,8 +90,10 @@ export class WebSocketInstrumentation<T = Record<string, unknown>> extends Instr
8890
constructor(url: string, protocols?: string | string[]) {
8991
super(url, protocols);
9092

91-
if (isLocalhost(url)) {
92-
console.log('Skipping WebSocket instrumentation for localhost:', url);
93+
const isURLWhitelistEmpty = self.whiteListedURLs.length === 0;
94+
95+
if (isLocalhost(url) || (!isURLWhitelistEmpty && !self.whiteListedURLs.includes(url))) {
96+
console.log('Skipping WebSocket instrumentation for non-whitelisted URL:', url);
9397
return;
9498
}
9599

experimental/instrumentation-websocket/src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type MessageTransform<T = Record<string, unknown>> = (
77
export interface WebSocketInstrumentationConfig<T = Record<string, unknown>> {
88
messageTransform?: MessageTransform<T>;
99
sendTransform?: MessageTransform<T>;
10+
whiteListedURLs?: string[];
1011
}
1112

1213
export interface PendingRequest {

0 commit comments

Comments
 (0)