@@ -4,6 +4,7 @@ import { Event, EventProcessor, Integration, Severity, Span, SpanContext, Transa
4
4
import {
5
5
addInstrumentationHandler ,
6
6
getGlobalObject ,
7
+ isInstanceOf ,
7
8
isMatchingPattern ,
8
9
logger ,
9
10
safeJoin ,
@@ -1019,18 +1020,24 @@ function fetchCallback(handlerData: { [key: string]: any }): void {
1019
1020
if ( activity ) {
1020
1021
const span = activity . span ;
1021
1022
if ( span ) {
1023
+ const request = ( handlerData . args [ 0 ] = handlerData . args [ 0 ] as string | Request ) ;
1022
1024
const options = ( handlerData . args [ 1 ] = ( handlerData . args [ 1 ] as { [ key : string ] : any } ) || { } ) ;
1023
- if ( options . headers ) {
1024
- if ( typeof options . headers . append === 'function' ) {
1025
- options . headers . append ( 'sentry-trace' , span . toTraceparent ( ) ) ;
1026
- } else if ( Array . isArray ( options . headers ) ) {
1027
- options . headers = [ ...options . headers , [ 'sentry-trace' , span . toTraceparent ( ) ] ] ;
1025
+ let headers = options . headers ;
1026
+ if ( isInstanceOf ( request , Request ) ) {
1027
+ headers = ( request as Request ) . headers ;
1028
+ }
1029
+ if ( headers ) {
1030
+ if ( typeof headers . append === 'function' ) {
1031
+ headers . append ( 'sentry-trace' , span . toTraceparent ( ) ) ;
1032
+ } else if ( Array . isArray ( headers ) ) {
1033
+ headers = [ ...headers , [ 'sentry-trace' , span . toTraceparent ( ) ] ] ;
1028
1034
} else {
1029
- options . headers = { ... options . headers , 'sentry-trace' : span . toTraceparent ( ) } ;
1035
+ headers = { ...headers , 'sentry-trace' : span . toTraceparent ( ) } ;
1030
1036
}
1031
1037
} else {
1032
- options . headers = { 'sentry-trace' : span . toTraceparent ( ) } ;
1038
+ headers = { 'sentry-trace' : span . toTraceparent ( ) } ;
1033
1039
}
1040
+ options . headers = headers ;
1034
1041
}
1035
1042
}
1036
1043
}
0 commit comments