Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions packages/node/src/integrations/http/SentryHttpInstrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { getRequestInfo } from './vendor/getRequestInfo';
type Http = typeof http;
type Https = typeof https;

const INSTRUMENTATION_NAME = '@sentry/instrumentation-http';

export type SentryHttpInstrumentationOptions = InstrumentationConfig & {
/**
* Whether breadcrumbs should be recorded for requests.
Expand Down Expand Up @@ -101,7 +103,7 @@ const MAX_BODY_BYTE_LENGTH = 1024 * 1024;
*/
export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpInstrumentationOptions> {
public constructor(config: SentryHttpInstrumentationOptions = {}) {
super('@sentry/instrumentation-http', VERSION, config);
super(INSTRUMENTATION_NAME, VERSION, config);
}

/** @inheritdoc */
Expand Down Expand Up @@ -377,6 +379,10 @@ function patchRequestToCaptureBody(req: IncomingMessage, isolationScope: Scope):
apply: (target, thisArg, args: Parameters<typeof req.on>) => {
const [event, listener, ...restArgs] = args;

if (DEBUG_BUILD) {
logger.log(INSTRUMENTATION_NAME, 'Patching request.on', event);
}

if (event === 'data') {
const callback = new Proxy(listener, {
apply: (target, thisArg, args: Parameters<typeof listener>) => {
Expand All @@ -387,7 +393,8 @@ function patchRequestToCaptureBody(req: IncomingMessage, isolationScope: Scope):
chunks.push(chunk);
} else if (DEBUG_BUILD) {
logger.log(
`Dropping request body chunk because it maximum body length of ${MAX_BODY_BYTE_LENGTH}b is exceeded.`,
INSTRUMENTATION_NAME,
`Dropping request body chunk because maximum body length of ${MAX_BODY_BYTE_LENGTH}b is exceeded.`,
);
}

Expand All @@ -410,8 +417,10 @@ function patchRequestToCaptureBody(req: IncomingMessage, isolationScope: Scope):
const normalizedRequest = { data: body } satisfies RequestEventData;
isolationScope.setSDKProcessingMetadata({ normalizedRequest });
}
} catch {
// ignore errors here
} catch (error) {
if (DEBUG_BUILD) {
logger.error(INSTRUMENTATION_NAME, 'Error building captured request body', error);
}
}

return Reflect.apply(target, thisArg, args);
Expand Down Expand Up @@ -445,8 +454,10 @@ function patchRequestToCaptureBody(req: IncomingMessage, isolationScope: Scope):
return Reflect.apply(target, thisArg, args);
},
});
} catch {
// ignore errors if we can't patch stuff
} catch (error) {
if (DEBUG_BUILD) {
logger.error(INSTRUMENTATION_NAME, 'Error patching request to capture body', error);
}
}
}

Expand Down
Loading