Skip to content

Commit 28a8237

Browse files
authored
feat(tracing): make long animation frames opt-out (#13255)
Enable long animation frames by default. If long animation frames are not supported by the browser, Sentry will fallback to using long tasks where enabled.
1 parent 2a1d8ee commit 28a8237

File tree

6 files changed

+30
-13
lines changed

6 files changed

+30
-13
lines changed

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/interactions/test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ sentryTest('should capture interaction transaction. @firefox', async ({ browserN
3333
expect(eventData.contexts).toMatchObject({ trace: { op: 'ui.action.click' } });
3434
expect(eventData.platform).toBe('javascript');
3535
expect(eventData.type).toBe('transaction');
36-
expect(eventData.spans).toHaveLength(1);
3736

38-
const interactionSpan = eventData.spans![0];
37+
const spans = eventData.spans?.filter(span => !span.op?.startsWith('ui.long-animation-frame'));
38+
expect(spans).toHaveLength(1);
39+
40+
const interactionSpan = spans![0];
3941
expect(interactionSpan.op).toBe('ui.interaction.click');
4042
expect(interactionSpan.description).toBe('body > button.clicked');
4143
expect(interactionSpan.timestamp).toBeDefined();
@@ -63,7 +65,8 @@ sentryTest(
6365
await page.waitForTimeout(1000);
6466
await page.locator('[data-test-id=interaction-button]').click();
6567
const envelope = await envelopePromise;
66-
expect(envelope[0].spans).toHaveLength(1);
68+
const spans = envelope[0].spans?.filter(span => !span.op?.startsWith('ui.long-animation-frame'));
69+
expect(spans).toHaveLength(1);
6770
}
6871
},
6972
);
@@ -89,10 +92,10 @@ sentryTest(
8992
const envelopes = await envelopePromise;
9093
expect(envelopes).toHaveLength(1);
9194
const eventData = envelopes[0];
95+
const spans = eventData.spans?.filter(span => !span.op?.startsWith('ui.long-animation-frame'));
96+
expect(spans).toHaveLength(1);
9297

93-
expect(eventData.spans).toHaveLength(1);
94-
95-
const interactionSpan = eventData.spans![0];
98+
const interactionSpan = spans![0];
9699
expect(interactionSpan.op).toBe('ui.interaction.click');
97100
expect(interactionSpan.description).toBe('body > AnnotatedButton');
98101
},
@@ -120,9 +123,10 @@ sentryTest(
120123
expect(envelopes).toHaveLength(1);
121124

122125
const eventData = envelopes[0];
123-
expect(eventData.spans).toHaveLength(1);
126+
const spans = eventData.spans?.filter(span => !span.op?.startsWith('ui.long-animation-frame'));
127+
expect(spans).toHaveLength(1);
124128

125-
const interactionSpan = eventData.spans![0];
129+
const interactionSpan = spans![0];
126130
expect(interactionSpan.op).toBe('ui.interaction.click');
127131
expect(interactionSpan.description).toBe('body > StyledButton');
128132
},

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/long-tasks-disabled/init.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ window.Sentry = Sentry;
44

55
Sentry.init({
66
dsn: 'https://[email protected]/1337',
7-
integrations: [Sentry.browserTracingIntegration({ enableLongTask: false, idleTimeout: 9000 })],
7+
integrations: [
8+
Sentry.browserTracingIntegration({ enableLongTask: false, enableLongAnimationFrame: false, idleTimeout: 9000 }),
9+
],
810
tracesSampleRate: 1,
911
});

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/long-tasks-enabled/init.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Sentry.init({
77
integrations: [
88
Sentry.browserTracingIntegration({
99
idleTimeout: 9000,
10+
enableLongAnimationFrame: false,
1011
}),
1112
],
1213
tracesSampleRate: 1,

packages/browser/src/tracing/browserTracingIntegration.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
import type { Client, IntegrationFn, StartSpanOptions, TransactionSource } from '@sentry/types';
2929
import type { Span } from '@sentry/types';
3030
import {
31+
GLOBAL_OBJ,
3132
browserPerformanceTimeOrigin,
3233
generatePropagationContext,
3334
getDomElement,
@@ -168,7 +169,7 @@ const DEFAULT_BROWSER_TRACING_OPTIONS: BrowserTracingOptions = {
168169
instrumentPageLoad: true,
169170
markBackgroundSpan: true,
170171
enableLongTask: true,
171-
enableLongAnimationFrame: false,
172+
enableLongAnimationFrame: true,
172173
enableInp: true,
173174
_experiments: {},
174175
...defaultRequestInstrumentationOptions,
@@ -213,7 +214,11 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
213214
startTrackingINP();
214215
}
215216

216-
if (enableLongAnimationFrame && PerformanceObserver.supportedEntryTypes.includes('long-animation-frame')) {
217+
if (
218+
enableLongAnimationFrame &&
219+
GLOBAL_OBJ.PerformanceObserver &&
220+
PerformanceObserver.supportedEntryTypes.includes('long-animation-frame')
221+
) {
217222
startTrackingLongAnimationFrames();
218223
} else if (enableLongTask) {
219224
startTrackingLongTasks();

packages/ember/tests/helpers/utils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@ export function assertSentryTransactions(
6464

6565
// instead of checking the specific order of runloop spans (which is brittle),
6666
// we check (below) that _any_ runloop spans are added
67-
// Also we ignore ui.long-task spans, as they are brittle and may or may not appear
67+
// Also we ignore ui.long-task spans and ui.long-animation-frame, as they are brittle and may or may not appear
6868
const filteredSpans = spans
6969
.filter(span => {
7070
const op = span.op;
71-
return !op?.startsWith('ui.ember.runloop.') && !op?.startsWith('ui.long-task');
71+
return (
72+
!op?.startsWith('ui.ember.runloop.') &&
73+
!op?.startsWith('ui.long-task') &&
74+
!op?.startsWith('ui.long-animation-frame')
75+
);
7276
})
7377
.map(spanJson => {
7478
return `${spanJson.op} | ${spanJson.description}`;

packages/utils/src/worldwide.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type BackwardsCompatibleSentryCarrier = SentryCarrier & {
4949
export type InternalGlobal = {
5050
navigator?: { userAgent?: string };
5151
console: Console;
52+
PerformanceObserver?: any;
5253
Sentry?: any;
5354
onerror?: {
5455
(event: object | string, source?: string, lineno?: number, colno?: number, error?: Error): any;

0 commit comments

Comments
 (0)