File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -141,8 +141,11 @@ export function fetchCallback(
141
141
return ;
142
142
}
143
143
144
- if ( handlerData . endTimestamp && handlerData . fetchData . __span ) {
145
- const span = spans [ handlerData . fetchData . __span ] ;
144
+ if ( handlerData . endTimestamp ) {
145
+ const spanId = handlerData . fetchData . __span ;
146
+ if ( ! spanId ) return ;
147
+
148
+ const span = spans [ spanId ] ;
146
149
if ( span ) {
147
150
if ( handlerData . response ) {
148
151
// TODO (kmclb) remove this once types PR goes through
@@ -154,7 +157,7 @@ export function fetchCallback(
154
157
span . finish ( ) ;
155
158
156
159
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
157
- delete spans [ handlerData . fetchData . __span ] ;
160
+ delete spans [ spanId ] ;
158
161
}
159
162
return ;
160
163
}
Original file line number Diff line number Diff line change @@ -174,6 +174,23 @@ describe('callbacks', () => {
174
174
expect ( newSpan ! . status ) . toBe ( spanStatusfromHttpCode ( 404 ) ) ;
175
175
} ) ;
176
176
177
+ it ( 'ignores response with no associated span' , ( ) => {
178
+ // the request might be missed somehow. E.g. if it was sent before tracing gets enabled.
179
+
180
+ const postRequestFetchHandlerData = {
181
+ ...fetchHandlerData ,
182
+ endTimestamp,
183
+ response : { status : 404 } as Response ,
184
+ } ;
185
+
186
+ // in that case, the response coming back will be ignored
187
+ fetchCallback ( postRequestFetchHandlerData , alwaysCreateSpan , { } ) ;
188
+
189
+ const newSpan = transaction . spanRecorder ?. spans [ 1 ] ;
190
+
191
+ expect ( newSpan ) . toBeUndefined ( ) ;
192
+ } ) ;
193
+
177
194
it ( 'adds sentry-trace header to fetch requests' , ( ) => {
178
195
// TODO
179
196
} ) ;
You can’t perform that action at this time.
0 commit comments