Skip to content

Commit 1721330

Browse files
committed
fix: Dont instrument same type twice
1 parent 1e16eb1 commit 1721330

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

packages/browser/src/instrument.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,37 @@ const instrumented: { [key in InstrumentHandlerType]?: boolean } = {};
3838

3939
/** Instruments given API */
4040
function instrument(type: InstrumentHandlerType): void {
41-
if (type === 'console') {
42-
instrumentConsole();
43-
instrumented[type] = true;
44-
}
45-
if (type === 'dom') {
46-
instrumentDOM();
47-
}
48-
if (type === 'xhr') {
49-
instrumentXHR();
50-
}
51-
if (type === 'fetch') {
52-
instrumentFetch();
41+
if (instrumented[type]) {
42+
return;
5343
}
54-
if (type === 'history') {
55-
instrumentHistory();
44+
45+
instrumented[type] = true;
46+
47+
switch (type) {
48+
case 'console':
49+
instrumentConsole();
50+
break;
51+
case 'dom':
52+
instrumentDOM();
53+
break;
54+
case 'xhr':
55+
instrumentXHR();
56+
break;
57+
case 'fetch':
58+
instrumentFetch();
59+
break;
60+
case 'history':
61+
instrumentHistory();
62+
break;
63+
default:
64+
logger.warn('unknown instrumentation type:', type);
5665
}
5766
}
5867

5968
/**
60-
* Add handler that will be called when given type of instrumentation triggers
69+
* Add handler that will be called when given type of instrumentation triggers.
70+
* Use at your own risk, this might break without changelog notice, only used internally.
71+
* @hidden
6172
*/
6273
export function addInstrumentationHandler(handler: InstrumentHandler): void {
6374
// tslint:disable-next-line:strict-type-predicates

0 commit comments

Comments
 (0)