Skip to content

Commit abf11dc

Browse files
committed
Wrap in try catch incase there is an internal error
1 parent ec58516 commit abf11dc

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

packages/tracing/src/browser/browsertracing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { startIdleTransaction } from '../hubextensions';
66
import { DEFAULT_FINAL_TIMEOUT, DEFAULT_IDLE_TIMEOUT } from '../idletransaction';
77
import { extractTraceparentData } from '../utils';
88
import { registerBackgroundTabDetection } from './backgroundtab';
9-
import { addPerformanceEntries, startTrackingWebVitals } from './metrics';
9+
import { addPerformanceEntries, startTrackingLongTasks, startTrackingWebVitals } from './metrics';
1010
import {
1111
defaultRequestInstrumentationOptions,
1212
instrumentOutgoingRequests,
@@ -148,7 +148,7 @@ export class BrowserTracing implements Integration {
148148

149149
const { _metricOptions } = this.options;
150150
startTrackingWebVitals(_metricOptions && _metricOptions._reportAllChanges);
151-
// startTrackingLongTasks();
151+
startTrackingLongTasks();
152152
}
153153

154154
/**

packages/tracing/src/browser/metrics/index.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,26 @@ export function startTrackingWebVitals(reportAllChanges: boolean = false): void
4444
* Start tracking long tasks.
4545
*/
4646
export function startTrackingLongTasks(): void {
47-
const entryHandler: PerformanceEntryHandler = (entry: PerformanceEntry): void => {
48-
const transaction = getActiveTransaction() as IdleTransaction | undefined;
49-
if (!transaction) {
50-
return;
51-
}
52-
const startTime = msToSec(entry.startTime);
53-
const duration = msToSec(entry.duration);
54-
transaction.startChild({
55-
description: 'Long Task',
56-
op: 'ui.long-task',
57-
startTimestamp: startTime,
58-
endTimestamp: startTime + duration,
59-
});
60-
};
47+
try {
48+
const entryHandler: PerformanceEntryHandler = (entry: PerformanceEntry): void => {
49+
const transaction = getActiveTransaction() as IdleTransaction | undefined;
50+
if (!transaction) {
51+
return;
52+
}
53+
const startTime = msToSec(entry.startTime);
54+
const duration = msToSec(entry.duration);
55+
transaction.startChild({
56+
description: 'Long Task',
57+
op: 'ui.long-task',
58+
startTimestamp: startTime,
59+
endTimestamp: startTime + duration,
60+
});
61+
};
6162

62-
observe('longtask', entryHandler);
63+
observe('longtask', entryHandler);
64+
} catch (_) {
65+
// Do nothing
66+
}
6367
}
6468

6569
/** Starts tracking the Cumulative Layout Shift on the current page. */

0 commit comments

Comments
 (0)