Skip to content

Commit b34bcf8

Browse files
committed
feat: Add fetch tracking
1 parent b41142c commit b34bcf8

File tree

1 file changed

+32
-54
lines changed

1 file changed

+32
-54
lines changed

packages/apm/src/integrations/tracing.ts

+32-54
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ function xhrCallback(handlerData: { [key: string]: any }): void {
432432

433433
handlerData.xhr.__sentry_xhr_activity_id__ = Tracing.pushActivity('xhr', {
434434
data: {
435-
request_data: xhr.data,
435+
...xhr.data,
436+
type: 'xhr',
436437
},
437438
description: `${xhr.method} ${xhr.url}`,
438439
op: 'http',
@@ -443,58 +444,30 @@ function xhrCallback(handlerData: { [key: string]: any }): void {
443444
/**
444445
* Creates breadcrumbs from fetch API calls
445446
*/
446-
// function fetchHandler(handlerData: { [key: string]: any }): void {
447-
// // We only capture complete fetch requests
448-
// if (!handlerData.requestComplete) {
449-
// return;
450-
// }
451-
452-
// const client = getCurrentHub().getClient<BrowserClient>();
453-
// const dsn = client && client.getDsn();
454-
455-
// if (dsn) {
456-
// const filterUrl = new API(dsn).getStoreEndpoint();
457-
// // if Sentry key appears in URL, don't capture it as a request
458-
// // but rather as our own 'sentry' type breadcrumb
459-
// if (
460-
// filterUrl &&
461-
// handlerData.fetchData.url.indexOf(filterUrl) !== -1 &&
462-
// handlerData.fetchData.method === 'POST' &&
463-
// handlerData.args[1] &&
464-
// handlerData.args[1].body
465-
// ) {
466-
// addSentryBreadcrumb(handlerData.args[1].body);
467-
// return;
468-
// }
469-
// }
470-
471-
// if (handlerData.error) {
472-
// getCurrentHub().addBreadcrumb(
473-
// {
474-
// category: 'fetch',
475-
// data: handlerData.fetchData,
476-
// level: Severity.Error,
477-
// type: 'http',
478-
// },
479-
// {
480-
// data: handlerData.error,
481-
// input: handlerData.args,
482-
// },
483-
// );
484-
// } else {
485-
// getCurrentHub().addBreadcrumb(
486-
// {
487-
// category: 'fetch',
488-
// data: handlerData.fetchData,
489-
// type: 'http',
490-
// },
491-
// {
492-
// input: handlerData.args,
493-
// response: handlerData.response,
494-
// },
495-
// );
496-
// }
497-
// }
447+
function fetchCallback(handlerData: { [key: string]: any }): void {
448+
// tslint:disable: no-unsafe-any
449+
if (!Tracing.options.traceFetch) {
450+
return;
451+
}
452+
453+
if (handlerData.requestComplete && handlerData.__activity) {
454+
Tracing.popActivity(handlerData.__activity, handlerData.fetchData);
455+
} else {
456+
handlerData.__activity = Tracing.pushActivity('fetch', {
457+
data: {
458+
...handlerData.fetchData,
459+
type: 'fetch',
460+
},
461+
description: `${handlerData.fetchData.method} ${handlerData.fetchData.url}`,
462+
op: 'http',
463+
});
464+
}
465+
466+
// if (handlerData.error) {
467+
// } else {
468+
// }
469+
// tslint:enable: no-unsafe-any
470+
}
498471

499472
/**
500473
* Creates transaction from navigation changes
@@ -518,5 +491,10 @@ const xhrHandler = {
518491
type: 'xhr',
519492
};
520493

494+
const fetchHandler = {
495+
callback: fetchCallback,
496+
type: 'fetch',
497+
};
498+
521499
// tslint:disable-next-line: variable-name
522-
export const TracingHandlers = [historyHandler, xhrHandler];
500+
export const TracingHandlers = [historyHandler, xhrHandler, fetchHandler];

0 commit comments

Comments
 (0)