Skip to content

Commit 27799ca

Browse files
committed
ref(node): Avoid unnecessary array parsing for incoming requests
Small optimization to avoid unnecessary work.
1 parent fa8e043 commit 27799ca

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

packages/node/src/integrations/http/SentryHttpInstrumentation.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,18 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
153153

154154
return (
155155
original: (event: string, ...args: unknown[]) => boolean,
156-
): ((this: unknown, event: string, ...args: unknown[]) => boolean) => {
157-
return function incomingRequest(this: unknown, event: string, ...args: unknown[]): boolean {
156+
): ((this: unknown, ...args: [event: string, ...args: unknown[]]) => boolean) => {
157+
return function incomingRequest(this: unknown, ...args: [event: string, ...args: unknown[]]): boolean {
158158
// Only traces request events
159-
if (event !== 'request') {
160-
return original.apply(this, [event, ...args]);
159+
if (args[0] !== 'request') {
160+
return original.apply(this, args);
161161
}
162162

163163
instrumentation._diag.debug('http instrumentation for incoming request');
164164

165165
const isolationScope = getIsolationScope().clone();
166-
const request = args[0] as http.IncomingMessage;
167-
const response = args[1] as http.OutgoingMessage;
166+
const request = args[1] as http.IncomingMessage;
167+
const response = args[2] as http.OutgoingMessage;
168168

169169
const normalizedRequest = httpRequestToRequestData(request);
170170

@@ -202,12 +202,12 @@ export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpIns
202202

203203
// If we don't want to extract the trace from the header, we can skip this
204204
if (!instrumentation.getConfig().extractIncomingTraceFromHeader) {
205-
return original.apply(this, [event, ...args]);
205+
return original.apply(this, args);
206206
}
207207

208208
const ctx = propagation.extract(context.active(), normalizedRequest.headers);
209209
return context.with(ctx, () => {
210-
return original.apply(this, [event, ...args]);
210+
return original.apply(this, args);
211211
});
212212
});
213213
};

0 commit comments

Comments
 (0)