Skip to content

Commit

Permalink
add long animation frame observer
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinL10 committed Jul 5, 2024
1 parent 683ea21 commit 2083357
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/browser-utils/src/metrics/browserMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,32 @@ export function startTrackingLongAnimationFrames(): void {
// NOTE: the current web-vitals version (3.5.2) does not support long-animation-frame, so
// we should directly observe `long-animation-frame` events here instead of through the web-vitals
// `observe` helper function.
if (PerformanceObserver.supportedEntryTypes.includes('long-animation-frame')) {
const observer = new PerformanceObserver(list => {
for (const entry of list.getEntries()) {
if (!getActiveSpan()) {
return;
}
const startTime = msToSec((browserPerformanceTimeOrigin as number) + entry.startTime);
const duration = msToSec(entry.duration);

const span = startInactiveSpan({
name: 'Main UI thread blocked',
op: 'ui.long-animation-frame',
startTime,
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',
},
});
if (span) {
span.end(startTime + duration);
}
}
});

observer.observe({ type: 'long-animation-frame', buffered: true });
}

// addPerformanceInstrumentationHandler('long-animation-frame', ({ entries }) => {
// for (const entry of entries) {
// if (!getActiveSpan()) {
Expand Down

0 comments on commit 2083357

Please sign in to comment.