Skip to content

perf(node): Store normalized request for processing #15570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 4, 2025
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
7 changes: 5 additions & 2 deletions packages/node/src/integrations/tracing/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ExpressRequestInfo } from '@opentelemetry/instrumentation-express'
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
import type { IntegrationFn } from '@sentry/core';
import {
httpRequestToRequestData,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
captureException,
defineIntegration,
Expand Down Expand Up @@ -135,9 +136,10 @@ export function expressErrorHandler(options?: ExpressHandlerOptions): ExpressErr
res: http.ServerResponse,
next: (error: MiddlewareError) => void,
): void {
const normalizedRequest = httpRequestToRequestData(request);
// Ensure we use the express-enhanced request here, instead of the plain HTTP one
// When an error happens, the `expressRequestHandler` middleware does not run, so we set it here too
getIsolationScope().setSDKProcessingMetadata({ request });
getIsolationScope().setSDKProcessingMetadata({ normalizedRequest });

const shouldHandleError = options?.shouldHandleError || defaultShouldHandleError;

Expand All @@ -156,8 +158,9 @@ function expressRequestHandler(): ExpressMiddleware {
_res: http.ServerResponse,
next: () => void,
): void {
const normalizedRequest = httpRequestToRequestData(request);
// Ensure we use the express-enhanced request here, instead of the plain HTTP one
getIsolationScope().setSDKProcessingMetadata({ request });
getIsolationScope().setSDKProcessingMetadata({ normalizedRequest });

next();
};
Expand Down
Loading