11import {
22 applySdkMetadata ,
3+ getClient ,
34 getGlobalScope ,
5+ getIsolationScope ,
46 getRootSpan ,
57 GLOBAL_OBJ ,
68 registerSpanErrorInstrumentation ,
@@ -13,6 +15,7 @@ import {
1315} from '@sentry/core' ;
1416import type { VercelEdgeOptions } from '@sentry/vercel-edge' ;
1517import { getDefaultIntegrations , init as vercelEdgeInit } from '@sentry/vercel-edge' ;
18+ import { addHeadersAsAttributes } from '../common/utils/addHeadersAsAttributes' ;
1619import { isBuild } from '../common/utils/isBuild' ;
1720import { flushSafelyWithTimeout } from '../common/utils/responseEnd' ;
1821import { distDirRewriteFramesIntegration } from './distDirRewriteFramesIntegration' ;
@@ -59,6 +62,8 @@ export function init(options: VercelEdgeOptions = {}): void {
5962
6063 client ?. on ( 'spanStart' , span => {
6164 const spanAttributes = spanToJSON ( span ) . data ;
65+ const rootSpan = getRootSpan ( span ) ;
66+ const isRootSpan = span === rootSpan ;
6267
6368 // Mark all spans generated by Next.js as 'auto'
6469 if ( spanAttributes ?. [ 'next.span_type' ] !== undefined ) {
@@ -70,6 +75,13 @@ export function init(options: VercelEdgeOptions = {}): void {
7075 span . setAttribute ( SEMANTIC_ATTRIBUTE_SENTRY_OP , 'http.server.middleware' ) ;
7176 span . setAttribute ( SEMANTIC_ATTRIBUTE_SENTRY_SOURCE , 'url' ) ;
7277 }
78+
79+ const shouldSendDefaultPii = getClient ( ) ?. getOptions ( ) . sendDefaultPii ?? false ;
80+ if ( shouldSendDefaultPii && isRootSpan ) {
81+ // todo: check if we can set request headers for edge on sdkProcessingMetadata
82+ const headers = getIsolationScope ( ) . getScopeData ( ) . sdkProcessingMetadata ?. normalizedRequest ?. headers ;
83+ addHeadersAsAttributes ( headers , rootSpan ) ;
84+ }
7385 } ) ;
7486
7587 // Use the preprocessEvent hook instead of an event processor, so that the users event processors receive the most
0 commit comments