Skip to content

Commit 5ba8c9d

Browse files
committed
feat(tracing): add long animation frame tracking
1 parent 383674c commit 5ba8c9d

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

packages/browser-utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export {
1111
addPerformanceEntries,
1212
startTrackingInteractions,
1313
startTrackingLongTasks,
14+
startTrackingLongAnimationFrames,
1415
startTrackingWebVitals,
1516
startTrackingINP,
1617
registerInpInteractionListener,

packages/browser-utils/src/metrics/browserMetrics.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,36 @@ export function startTrackingLongTasks(): void {
120120
});
121121
}
122122

123+
/**
124+
* Start tracking long animation frames.
125+
*/
126+
export function startTrackingLongAnimationFrames(): void {
127+
addPerformanceInstrumentationHandler('long-animation-frame', ({ entries }) => {
128+
for (const entry of entries) {
129+
if (!getActiveSpan()) {
130+
return;
131+
}
132+
const startTime = msToSec((browserPerformanceTimeOrigin as number) + entry.startTime);
133+
const duration = msToSec(entry.duration);
134+
135+
136+
const span = startInactiveSpan({
137+
name: 'Main UI thread blocked',
138+
op: 'ui.long-animation-frame',
139+
startTime,
140+
attributes: {
141+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',
142+
},
143+
});
144+
if (span) {
145+
span.end(startTime + duration);
146+
}
147+
}
148+
});
149+
}
150+
151+
152+
123153
/**
124154
* Start tracking interaction events.
125155
*/

packages/browser-utils/src/metrics/instrument.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { onTTFB } from './web-vitals/onTTFB';
1010

1111
type InstrumentHandlerTypePerformanceObserver =
1212
| 'longtask'
13+
| 'long-animation-frame'
1314
| 'event'
1415
| 'navigation'
1516
| 'paint'

packages/browser/src/tracing/browserTracingIntegration.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
startTrackingINP,
77
startTrackingInteractions,
88
startTrackingLongTasks,
9+
startTrackingLongAnimationFrames,
910
startTrackingWebVitals,
1011
} from '@sentry-internal/browser-utils';
1112
import {
@@ -102,6 +103,13 @@ export interface BrowserTracingOptions {
102103
*/
103104
enableLongTask: boolean;
104105

106+
/**
107+
* If true, Sentry will capture long animation frames and add them to the corresponding transaction.
108+
*
109+
* Default: false
110+
*/
111+
enableLongAnimationFrame: boolean;
112+
105113
/**
106114
* If true, Sentry will capture first input delay and add it to the corresponding transaction.
107115
*
@@ -160,6 +168,7 @@ const DEFAULT_BROWSER_TRACING_OPTIONS: BrowserTracingOptions = {
160168
instrumentPageLoad: true,
161169
markBackgroundSpan: true,
162170
enableLongTask: true,
171+
enableLongAnimationFrame: false,
163172
enableInp: true,
164173
_experiments: {},
165174
...defaultRequestInstrumentationOptions,
@@ -180,6 +189,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
180189
const {
181190
enableInp,
182191
enableLongTask,
192+
enableLongAnimationFrame,
183193
_experiments: { enableInteractions },
184194
beforeStartSpan,
185195
idleTimeout,
@@ -206,6 +216,11 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
206216
if (enableLongTask) {
207217
startTrackingLongTasks();
208218
}
219+
220+
if (enableLongAnimationFrame) {
221+
startTrackingLongAnimationFrames();
222+
}
223+
209224
if (enableInteractions) {
210225
startTrackingInteractions();
211226
}

0 commit comments

Comments
 (0)