@@ -13,6 +13,7 @@ import {
1313 winterCGRequestToRequestData ,
1414 withIsolationScope ,
1515} from '@sentry/core' ;
16+ import { addHeadersAsAttributes } from '../common/utils/headersToAttributes' ;
1617import { flushSafelyWithTimeout } from '../common/utils/responseEnd' ;
1718import type { EdgeRouteHandler } from './types' ;
1819
@@ -31,11 +32,15 @@ export function wrapApiHandlerWithSentry<H extends EdgeRouteHandler>(
3132 const req : unknown = args [ 0 ] ;
3233 const currentScope = getCurrentScope ( ) ;
3334
35+ let headerAttributes : Record < string , string [ ] > = { } ;
36+
3437 if ( req instanceof Request ) {
3538 isolationScope . setSDKProcessingMetadata ( {
3639 normalizedRequest : winterCGRequestToRequestData ( req ) ,
3740 } ) ;
3841 currentScope . setTransactionName ( `${ req . method } ${ parameterizedRoute } ` ) ;
42+
43+ headerAttributes = addHeadersAsAttributes ( req . headers ) ;
3944 } else {
4045 currentScope . setTransactionName ( `handler (${ parameterizedRoute } )` ) ;
4146 }
@@ -58,6 +63,7 @@ export function wrapApiHandlerWithSentry<H extends EdgeRouteHandler>(
5863 rootSpan . setAttributes ( {
5964 [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'http.server' ,
6065 [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'route' ,
66+ ...headerAttributes ,
6167 } ) ;
6268 setCapturedScopesOnSpan ( rootSpan , currentScope , isolationScope ) ;
6369 }
@@ -74,6 +80,7 @@ export function wrapApiHandlerWithSentry<H extends EdgeRouteHandler>(
7480 attributes : {
7581 [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'route' ,
7682 [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.function.nextjs.wrapApiHandlerWithSentry' ,
83+ ...headerAttributes ,
7784 } ,
7885 } ,
7986 ( ) => {
0 commit comments