Skip to content

Commit 3ec7566

Browse files
committed
ref(tracing): Use new addInstrumentationHandler
1 parent 7659398 commit 3ec7566

File tree

3 files changed

+28
-43
lines changed

3 files changed

+28
-43
lines changed

packages/tracing/src/browser/request.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,14 @@ export function instrumentOutgoingRequests(_options?: Partial<RequestInstrumenta
118118
const spans: Record<string, Span> = {};
119119

120120
if (traceFetch) {
121-
addInstrumentationHandler({
122-
callback: (handlerData: FetchData) => {
123-
fetchCallback(handlerData, shouldCreateSpan, spans);
124-
},
125-
type: 'fetch',
121+
addInstrumentationHandler('fetch', (handlerData: FetchData) => {
122+
fetchCallback(handlerData, shouldCreateSpan, spans);
126123
});
127124
}
128125

129126
if (traceXHR) {
130-
addInstrumentationHandler({
131-
callback: (handlerData: XHRData) => {
132-
xhrCallback(handlerData, shouldCreateSpan, spans);
133-
},
134-
type: 'xhr',
127+
addInstrumentationHandler('xhr', (handlerData: XHRData) => {
128+
xhrCallback(handlerData, shouldCreateSpan, spans);
135129
});
136130
}
137131
}

packages/tracing/src/browser/router.ts

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,30 @@ export function instrumentRoutingWithDefaults<T extends Transaction>(
2424
}
2525

2626
if (startTransactionOnLocationChange) {
27-
addInstrumentationHandler({
28-
callback: ({ to, from }: { to: string; from?: string }) => {
29-
/**
30-
* This early return is there to account for some cases where a navigation transaction starts right after
31-
* long-running pageload. We make sure that if `from` is undefined and a valid `startingURL` exists, we don't
32-
* create an uneccessary navigation transaction.
33-
*
34-
* This was hard to duplicate, but this behavior stopped as soon as this fix was applied. This issue might also
35-
* only be caused in certain development environments where the usage of a hot module reloader is causing
36-
* errors.
37-
*/
38-
if (from === undefined && startingUrl && startingUrl.indexOf(to) !== -1) {
39-
startingUrl = undefined;
40-
return;
41-
}
27+
addInstrumentationHandler('history', ({ to, from }: { to: string; from?: string }) => {
28+
/**
29+
* This early return is there to account for some cases where a navigation transaction starts right after
30+
* long-running pageload. We make sure that if `from` is undefined and a valid `startingURL` exists, we don't
31+
* create an uneccessary navigation transaction.
32+
*
33+
* This was hard to duplicate, but this behavior stopped as soon as this fix was applied. This issue might also
34+
* only be caused in certain development environments where the usage of a hot module reloader is causing
35+
* errors.
36+
*/
37+
if (from === undefined && startingUrl && startingUrl.indexOf(to) !== -1) {
38+
startingUrl = undefined;
39+
return;
40+
}
4241

43-
if (from !== to) {
44-
startingUrl = undefined;
45-
if (activeTransaction) {
46-
logger.log(`[Tracing] Finishing current transaction with op: ${activeTransaction.op}`);
47-
// If there's an open transaction on the scope, we need to finish it before creating an new one.
48-
activeTransaction.finish();
49-
}
50-
activeTransaction = customStartTransaction({ name: global.location.pathname, op: 'navigation' });
42+
if (from !== to) {
43+
startingUrl = undefined;
44+
if (activeTransaction) {
45+
logger.log(`[Tracing] Finishing current transaction with op: ${activeTransaction.op}`);
46+
// If there's an open transaction on the scope, we need to finish it before creating an new one.
47+
activeTransaction.finish();
5148
}
52-
},
53-
type: 'history',
49+
activeTransaction = customStartTransaction({ name: global.location.pathname, op: 'navigation' });
50+
}
5451
});
5552
}
5653
}

packages/tracing/src/errors.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@ import { getActiveTransaction } from './utils';
77
* Configures global error listeners
88
*/
99
export function registerErrorInstrumentation(): void {
10-
addInstrumentationHandler({
11-
callback: errorCallback,
12-
type: 'error',
13-
});
14-
addInstrumentationHandler({
15-
callback: errorCallback,
16-
type: 'unhandledrejection',
17-
});
10+
addInstrumentationHandler('error', errorCallback);
11+
addInstrumentationHandler('unhandledrejection', errorCallback);
1812
}
1913

2014
/**

0 commit comments

Comments
 (0)