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(
141141 return ;
142142 }
143143
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 ] ;
146149 if ( span ) {
147150 if ( handlerData . response ) {
148151 // TODO (kmclb) remove this once types PR goes through
@@ -154,7 +157,7 @@ export function fetchCallback(
154157 span . finish ( ) ;
155158
156159 // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
157- delete spans [ handlerData . fetchData . __span ] ;
160+ delete spans [ spanId ] ;
158161 }
159162 return ;
160163 }
Original file line number Diff line number Diff line change @@ -174,6 +174,23 @@ describe('callbacks', () => {
174174 expect ( newSpan ! . status ) . toBe ( spanStatusfromHttpCode ( 404 ) ) ;
175175 } ) ;
176176
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+
177194 it ( 'adds sentry-trace header to fetch requests' , ( ) => {
178195 // TODO
179196 } ) ;
You can’t perform that action at this time.
0 commit comments