Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tracing): make long animation frames opt-out #13255

Merged
merged 7 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ sentryTest('should capture interaction transaction. @firefox', async ({ browserN
expect(eventData.contexts).toMatchObject({ trace: { op: 'ui.action.click' } });
expect(eventData.platform).toBe('javascript');
expect(eventData.type).toBe('transaction');
expect(eventData.spans).toHaveLength(1);

const interactionSpan = eventData.spans![0];
const spans = eventData.spans?.filter(span => !span.op?.startsWith('ui.long-animation-frame'));
expect(spans).toHaveLength(1);

const interactionSpan = spans![0];
expect(interactionSpan.op).toBe('ui.interaction.click');
expect(interactionSpan.description).toBe('body > button.clicked');
expect(interactionSpan.timestamp).toBeDefined();
Expand Down Expand Up @@ -63,7 +65,8 @@ sentryTest(
await page.waitForTimeout(1000);
await page.locator('[data-test-id=interaction-button]').click();
const envelope = await envelopePromise;
expect(envelope[0].spans).toHaveLength(1);
const spans = envelope[0].spans?.filter(span => !span.op?.startsWith('ui.long-animation-frame'));
expect(spans).toHaveLength(1);
}
},
);
Expand All @@ -89,10 +92,10 @@ sentryTest(
const envelopes = await envelopePromise;
expect(envelopes).toHaveLength(1);
const eventData = envelopes[0];
const spans = eventData.spans?.filter(span => !span.op?.startsWith('ui.long-animation-frame'));
expect(spans).toHaveLength(1);

expect(eventData.spans).toHaveLength(1);

const interactionSpan = eventData.spans![0];
const interactionSpan = spans![0];
expect(interactionSpan.op).toBe('ui.interaction.click');
expect(interactionSpan.description).toBe('body > AnnotatedButton');
},
Expand Down Expand Up @@ -120,9 +123,10 @@ sentryTest(
expect(envelopes).toHaveLength(1);

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

const interactionSpan = eventData.spans![0];
const interactionSpan = spans![0];
expect(interactionSpan.op).toBe('ui.interaction.click');
expect(interactionSpan.description).toBe('body > StyledButton');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ window.Sentry = Sentry;

Sentry.init({
dsn: 'https://[email protected]/1337',
integrations: [Sentry.browserTracingIntegration({ enableLongTask: false, idleTimeout: 9000 })],
integrations: [
Sentry.browserTracingIntegration({ enableLongTask: false, enableLongAnimationFrame: false, idleTimeout: 9000 }),
],
tracesSampleRate: 1,
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Sentry.init({
integrations: [
Sentry.browserTracingIntegration({
idleTimeout: 9000,
enableLongAnimationFrame: false,
}),
],
tracesSampleRate: 1,
Expand Down
9 changes: 7 additions & 2 deletions packages/browser/src/tracing/browserTracingIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
import type { Client, IntegrationFn, StartSpanOptions, TransactionSource } from '@sentry/types';
import type { Span } from '@sentry/types';
import {
GLOBAL_OBJ,
browserPerformanceTimeOrigin,
generatePropagationContext,
getDomElement,
Expand Down Expand Up @@ -168,7 +169,7 @@ const DEFAULT_BROWSER_TRACING_OPTIONS: BrowserTracingOptions = {
instrumentPageLoad: true,
markBackgroundSpan: true,
enableLongTask: true,
enableLongAnimationFrame: false,
enableLongAnimationFrame: true,
enableInp: true,
_experiments: {},
...defaultRequestInstrumentationOptions,
Expand Down Expand Up @@ -213,7 +214,11 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
startTrackingINP();
}

if (enableLongAnimationFrame && PerformanceObserver.supportedEntryTypes.includes('long-animation-frame')) {
if (
enableLongAnimationFrame &&
GLOBAL_OBJ.PerformanceObserver &&
KevinL10 marked this conversation as resolved.
Show resolved Hide resolved
PerformanceObserver.supportedEntryTypes.includes('long-animation-frame')
) {
startTrackingLongAnimationFrames();
} else if (enableLongTask) {
startTrackingLongTasks();
Expand Down
8 changes: 6 additions & 2 deletions packages/ember/tests/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ export function assertSentryTransactions(

// instead of checking the specific order of runloop spans (which is brittle),
// we check (below) that _any_ runloop spans are added
// Also we ignore ui.long-task spans, as they are brittle and may or may not appear
// Also we ignore ui.long-task spans and ui.long-animation-frame, as they are brittle and may or may not appear
const filteredSpans = spans
.filter(span => {
const op = span.op;
return !op?.startsWith('ui.ember.runloop.') && !op?.startsWith('ui.long-task');
return (
!op?.startsWith('ui.ember.runloop.') &&
!op?.startsWith('ui.long-task') &&
!op?.startsWith('ui.long-animation-frame')
);
})
.map(spanJson => {
return `${spanJson.op} | ${spanJson.description}`;
Expand Down
1 change: 1 addition & 0 deletions packages/utils/src/worldwide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type BackwardsCompatibleSentryCarrier = SentryCarrier & {
export type InternalGlobal = {
navigator?: { userAgent?: string };
console: Console;
PerformanceObserver?: any;
Sentry?: any;
onerror?: {
(event: object | string, source?: string, lineno?: number, colno?: number, error?: Error): any;
Expand Down
Loading