Skip to content

Commit 20cb626

Browse files
authored
feat: Trigger handlers when starting fetch request as well (getsentry#2320)
1 parent 48ceb9d commit 20cb626

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/browser/src/integrations/breadcrumbs.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type XMLHttpRequestProp = 'onload' | 'onerror' | 'onprogress';
4545

4646
/**
4747
* Default Breadcrumbs instrumentations
48-
* @deprecated With v6, this will be renamed
48+
* TODO: Deprecated - with v6, this will be renamed to `Instrument`
4949
*/
5050
export class Breadcrumbs implements Integration {
5151
/**
@@ -255,19 +255,24 @@ export class Breadcrumbs implements Integration {
255255
method: getFetchMethod(args),
256256
url: getFetchUrl(args),
257257
},
258+
requestComplete: false,
258259
startTimestamp: Date.now(),
259260
};
260261

262+
triggerHandlers(handlerData);
263+
261264
return originalFetch.apply(global, args).then(
262265
(response: Response) => {
263266
handlerData.endTimestamp = Date.now();
267+
handlerData.requestComplete = true;
264268
handlerData.response = response;
265269
handlerData.fetchData.status_code = response.status;
266270
triggerHandlers(handlerData);
267271
return response;
268272
},
269273
(error: Error) => {
270274
handlerData.endTimestamp = Date.now();
275+
handlerData.requestComplete = true;
271276
handlerData.error = error;
272277
triggerHandlers(handlerData);
273278
throw error;
@@ -387,6 +392,7 @@ export class Breadcrumbs implements Integration {
387392
const handlerData: { [key: string]: any } = {
388393
args,
389394
endTimestamp: Date.now(),
395+
requestComplete: false,
390396
startTimestamp: Date.now(),
391397
xhr,
392398
};

packages/browser/src/integrations/instrumenthandlers.ts

+5
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ function xhrBreadcrumb(handlerData: { [key: string]: any }): void {
103103
* Creates breadcrumbs from fetch API calls
104104
*/
105105
function fetchBreadcrumb(handlerData: { [key: string]: any }): void {
106+
// We only capture complete fetch requests
107+
if (!handlerData.requestComplete) {
108+
return;
109+
}
110+
106111
const client = getCurrentHub().getClient<BrowserClient>();
107112
const dsn = client && client.getDsn();
108113

0 commit comments

Comments
 (0)