Skip to content

Commit e95527e

Browse files
committed
add request to transaction/scope metadata in express request/tracing/error handlers
1 parent 6e70534 commit e95527e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/node/src/handlers.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ export function tracingHandler(): (
6666
...traceparentData,
6767
metadata: {
6868
dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext,
69+
// The request should already have been stored in `scope.sdkProcessingMetadata` (which will become
70+
// `event.sdkProcessingMetadata` the same way the metadata here will) by `sentryRequestMiddleware`, but on the
71+
// off chance someone is using `sentryTracingMiddleware` without `sentryRequestMiddleware`, it doesn't hurt to
72+
// be sure
73+
request: req,
6974
source,
7075
},
7176
},
@@ -162,6 +167,8 @@ export function requestHandler(
162167

163168
currentHub.configureScope(scope => {
164169
scope.addEventProcessor(backwardsCompatibleEventProcessor);
170+
scope.setSDKProcessingMetadata({ request: req });
171+
165172
const client = currentHub.getClient<NodeClient>();
166173
if (isAutoSessionTrackingEnabled(client)) {
167174
const scope = currentHub.getScope();
@@ -240,6 +247,11 @@ export function errorHandler(options?: {
240247

241248
if (shouldHandleError(error)) {
242249
withScope(_scope => {
250+
// The request should already have been stored in `scope.sdkProcessingMetadata` by `sentryRequestMiddleware`,
251+
// but on the off chance someone is using `sentryErrorMiddleware` without `sentryRequestMiddleware`, it doesn't
252+
// hurt to be sure
253+
_scope.setSDKProcessingMetadata({ request: _req });
254+
243255
// For some reason we need to set the transaction on the scope again
244256
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
245257
const transaction = (res as any).__sentry_transaction as Span;

0 commit comments

Comments
 (0)