Skip to content

Commit 4613a83

Browse files
authored
fix(v8/browser): Ensure that performance.measure spans have a positive duration (#19959)
## Summary Cherry-picks to the `v8` branch: - #15415 — Ensure `performance.measure` spans have a positive duration - #17541 — Remove unused `geist` font from nextjs-t3 test app ## Test plan - Existing tests included in cherry-picks
1 parent 623a2a3 commit 4613a83

File tree

5 files changed

+33
-19
lines changed

5 files changed

+33
-19
lines changed

dev-packages/e2e-tests/test-applications/nextjs-t3/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"@trpc/client": "^11.0.0-rc.446",
2121
"@trpc/react-query": "^11.0.0-rc.446",
2222
"@trpc/server": "^11.0.0-rc.446",
23-
"geist": "^1.3.0",
2423
"next": "^14.2.4",
2524
"react": "^18.3.1",
2625
"react-dom": "^18.3.1",

dev-packages/e2e-tests/test-applications/nextjs-t3/src/app/layout.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import '~/styles/globals.css';
22

3-
import { GeistSans } from 'geist/font/sans';
43
import { type Metadata } from 'next';
54

65
import { TRPCReactProvider } from '~/trpc/react';
@@ -13,7 +12,7 @@ export const metadata: Metadata = {
1312

1413
export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
1514
return (
16-
<html lang="en" className={`${GeistSans.variable}`}>
15+
<html lang="en">
1716
<body>
1817
<TRPCReactProvider>{children}</TRPCReactProvider>
1918
</body>
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
import { type Config } from 'tailwindcss';
2-
import { fontFamily } from 'tailwindcss/defaultTheme';
32

43
export default {
54
content: ['./src/**/*.tsx'],
6-
theme: {
7-
extend: {
8-
fontFamily: {
9-
sans: ['var(--font-geist-sans)', ...fontFamily.sans],
10-
},
11-
},
12-
},
135
plugins: [],
146
} satisfies Config;

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ export function _addMeasureSpans(
425425
startTime: number,
426426
duration: number,
427427
timeOrigin: number,
428-
): number {
428+
): void {
429429
const navEntry = getNavigationEntry(false);
430430
const requestTime = msToSec(navEntry ? navEntry.requestStart : 0);
431431
// Because performance.measure accepts arbitrary timestamps it can produce
@@ -450,13 +450,14 @@ export function _addMeasureSpans(
450450
attributes['sentry.browser.measure_start_time'] = measureStartTimestamp;
451451
}
452452

453-
startAndEndSpan(span, measureStartTimestamp, measureEndTimestamp, {
454-
name: entry.name as string,
455-
op: entry.entryType as string,
456-
attributes,
457-
});
458-
459-
return measureStartTimestamp;
453+
// Measurements from third parties can be off, which would create invalid spans, dropping transactions in the process.
454+
if (measureStartTimestamp <= measureEndTimestamp) {
455+
startAndEndSpan(span, measureStartTimestamp, measureEndTimestamp, {
456+
name: entry.name as string,
457+
op: entry.entryType as string,
458+
attributes,
459+
});
460+
}
460461
}
461462

462463
/** Instrument navigation entries */

packages/browser-utils/test/browser/browserMetrics.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,29 @@ describe('_addMeasureSpans', () => {
9292
}),
9393
);
9494
});
95+
96+
it('drops measurement spans with negative duration', () => {
97+
const spans: Span[] = [];
98+
99+
getClient()?.on('spanEnd', span => {
100+
spans.push(span);
101+
});
102+
103+
const entry = {
104+
entryType: 'measure',
105+
name: 'measure-1',
106+
duration: 10,
107+
startTime: 12,
108+
} as PerformanceEntry;
109+
110+
const timeOrigin = 100;
111+
const startTime = 23;
112+
const duration = -50;
113+
114+
_addMeasureSpans(span, entry, startTime, duration, timeOrigin);
115+
116+
expect(spans).toHaveLength(0);
117+
});
95118
});
96119

97120
describe('_addResourceSpans', () => {

0 commit comments

Comments
 (0)