Skip to content

Commit c11cde7

Browse files
committed
attach headers in event processor
1 parent 5aa7a53 commit c11cde7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

packages/nextjs/src/server/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
applySdkMetadata,
1212
debug,
1313
extractTraceparentData,
14+
getActiveSpan,
1415
getCapturedScopesOnSpan,
1516
getClient,
1617
getCurrentScope,
@@ -36,6 +37,7 @@ import {
3637
TRANSACTION_ATTR_SENTRY_TRACE_BACKFILL,
3738
TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION,
3839
} from '../common/span-attributes-with-logic-attached';
40+
import { addHeadersAsAttributes } from '../common/utils/addHeadersAsAttributes';
3941
import { isBuild } from '../common/utils/isBuild';
4042
import { distDirRewriteFramesIntegration } from './distDirRewriteFramesIntegration';
4143

@@ -307,6 +309,26 @@ export function init(options: NodeOptions): NodeClient | undefined {
307309
),
308310
);
309311

312+
getGlobalScope().addEventProcessor(
313+
Object.assign(
314+
(event => {
315+
const shouldSendDefaultPii = getClient()?.getOptions().sendDefaultPii ?? false;
316+
if (event.type === 'transaction' && event.sdkProcessingMetadata?.normalizedRequest && shouldSendDefaultPii) {
317+
const activeSpan = getActiveSpan();
318+
const rootSpan = activeSpan ? getRootSpan(activeSpan) : undefined;
319+
if (rootSpan) {
320+
addHeadersAsAttributes(event.sdkProcessingMetadata.normalizedRequest.headers, rootSpan);
321+
}
322+
323+
return event;
324+
}
325+
326+
return event;
327+
}) satisfies EventProcessor,
328+
{ id: 'HttpRequestEnhancer' },
329+
),
330+
);
331+
310332
// Use the preprocessEvent hook instead of an event processor, so that the users event processors receive the most
311333
// up-to-date value, but also so that the logic that detects changes to the transaction names to set the source to
312334
// "custom", doesn't trigger.

0 commit comments

Comments
 (0)