From cb43562fccbd609a659307a37da4e04d3499eab5 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Mon, 24 Aug 2026 10:56:02 +0200 Subject: [PATCH 1/2] fix(browser): Default pageload span start time to `timeOrigin` Fixes #23469 Co-Authored-By: Claude Opus 5 (1M context) --- .../src/client/browserTracingIntegration.ts | 5 --- .../src/tracing/browserTracingIntegration.ts | 20 +++++++---- .../tracing/browserTracingIntegration.test.ts | 35 +++++++++++++++++++ .../appRouterRoutingInstrumentation.ts | 3 -- .../pagesRouterRoutingInstrumentation.ts | 4 --- 5 files changed, 49 insertions(+), 18 deletions(-) diff --git a/packages/astro/src/client/browserTracingIntegration.ts b/packages/astro/src/client/browserTracingIntegration.ts index 10842f2eff17..75712aca06e5 100644 --- a/packages/astro/src/client/browserTracingIntegration.ts +++ b/packages/astro/src/client/browserTracingIntegration.ts @@ -5,7 +5,6 @@ import { } from '@sentry/browser'; import type { Client, Integration, TransactionSource } from '@sentry/core'; import { - browserPerformanceTimeOrigin, debug, hasSpanStreamingEnabled, PAGELOAD_SPAN_NAME_FALLBACK, @@ -40,14 +39,10 @@ export function browserTracingIntegration( if (WINDOW.location) { if (options.instrumentPageLoad != false) { - const origin = browserPerformanceTimeOrigin(); - const { name, source } = getPageloadSpanName(client); startBrowserTracingPageLoadSpan(client, { name, - // pageload should always start at timeOrigin (and needs to be in s, not ms) - startTime: origin ? origin / 1000 : undefined, attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source, [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.astro', diff --git a/packages/browser/src/tracing/browserTracingIntegration.ts b/packages/browser/src/tracing/browserTracingIntegration.ts index 7b92855d936f..d75bcb577263 100644 --- a/packages/browser/src/tracing/browserTracingIntegration.ts +++ b/packages/browser/src/tracing/browserTracingIntegration.ts @@ -10,7 +10,6 @@ import type { } from '@sentry/core/browser'; import { addNonEnumerableProperty, - browserPerformanceTimeOrigin, consoleSandbox, dateTimestampInSeconds, debug, @@ -37,6 +36,7 @@ import { startInactiveSpan, timestampInSeconds, TRACING_DEFAULTS, + browserPerformanceTimeOrigin, } from '@sentry/core/browser'; import { addHistoryInstrumentationHandler, @@ -636,13 +636,10 @@ export const browserTracingIntegration = ((options: Partial { expect(spanIsSampled(span!)).toBe(true); }); + it('starts the span at the time origin if no start time is provided', () => { + const client = new BrowserClient( + getDefaultBrowserClientOptions({ + tracesSampleRate: 1, + integrations: [browserTracingIntegration({ instrumentPageLoad: false })], + }), + ); + setCurrentClient(client); + client.init(); + + // Simulate the SDK (and therefore the routing instrumentation) only starting up 5s into the page load + vi.setSystemTime(browserPerformanceTimeOrigin()! + 5_000); + + const span = startBrowserTracingPageLoadSpan(client, { name: 'test span' }); + + expect(spanToJSON(span!).start_timestamp).toBe(browserPerformanceTimeOrigin()! / 1000); + }); + + it('respects an explicitly passed start time', () => { + const client = new BrowserClient( + getDefaultBrowserClientOptions({ + tracesSampleRate: 1, + integrations: [browserTracingIntegration({ instrumentPageLoad: false })], + }), + ); + setCurrentClient(client); + client.init(); + + const startTime = browserPerformanceTimeOrigin()! / 1000 + 12; + + const span = startBrowserTracingPageLoadSpan(client, { name: 'test span', startTime }); + + expect(spanToJSON(span!).start_timestamp).toBe(startTime); + }); + it('allows to overwrite properties', () => { const client = new BrowserClient( getDefaultBrowserClientOptions({ diff --git a/packages/nextjs/src/client/routing/appRouterRoutingInstrumentation.ts b/packages/nextjs/src/client/routing/appRouterRoutingInstrumentation.ts index b81bf6d9fda5..8ab4865e4e06 100644 --- a/packages/nextjs/src/client/routing/appRouterRoutingInstrumentation.ts +++ b/packages/nextjs/src/client/routing/appRouterRoutingInstrumentation.ts @@ -1,6 +1,5 @@ import type { Client, Span } from '@sentry/core'; import { - browserPerformanceTimeOrigin, GLOBAL_OBJ, hasSpanStreamingEnabled, PAGELOAD_SPAN_NAME_FALLBACK, @@ -61,12 +60,10 @@ const currentRouterPatchingNavigationSpanRef: NavigationSpanRef = { current: und export function appRouterInstrumentPageLoad(client: Client): void { const pathname = stripTrailingSlash(WINDOW.location.pathname); const parameterizedPathname = maybeParameterizeRoute(pathname); - const origin = browserPerformanceTimeOrigin(); startBrowserTracingPageLoadSpan(client, { // With span streaming, span names have to be low cardinality, so we can't fall back to the URL. name: parameterizedPathname ?? (hasSpanStreamingEnabled(client) ? PAGELOAD_SPAN_NAME_FALLBACK : pathname), // pageload should always start at timeOrigin (and needs to be in s, not ms) - startTime: origin ? origin / 1000 : undefined, attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload', [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.nextjs.app_router_instrumentation', diff --git a/packages/nextjs/src/client/routing/pagesRouterRoutingInstrumentation.ts b/packages/nextjs/src/client/routing/pagesRouterRoutingInstrumentation.ts index 27d54fddf6cc..824bf2dfa9c0 100644 --- a/packages/nextjs/src/client/routing/pagesRouterRoutingInstrumentation.ts +++ b/packages/nextjs/src/client/routing/pagesRouterRoutingInstrumentation.ts @@ -1,6 +1,5 @@ import type { Client, TransactionSource } from '@sentry/core'; import { - browserPerformanceTimeOrigin, debug, hasSpanStreamingEnabled, PAGELOAD_SPAN_NAME_FALLBACK, @@ -123,13 +122,10 @@ export function pagesRouterInstrumentPageLoad(client: Client): void { name = name.replace(/^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS|TRACE|CONNECT)\s+/i, ''); } - const origin = browserPerformanceTimeOrigin(); startBrowserTracingPageLoadSpan( client, { name, - // pageload should always start at timeOrigin (and needs to be in s, not ms) - startTime: origin ? origin / 1000 : undefined, attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload', [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.nextjs.pages_router_instrumentation', From 71a1c1ddd849e0453781f887294f19376e7f9a02 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Mon, 24 Aug 2026 14:14:47 +0200 Subject: [PATCH 2/2] remove leftover from rebase --- packages/browser/src/tracing/browserTracingIntegration.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/browser/src/tracing/browserTracingIntegration.ts b/packages/browser/src/tracing/browserTracingIntegration.ts index d75bcb577263..3ab093acd852 100644 --- a/packages/browser/src/tracing/browserTracingIntegration.ts +++ b/packages/browser/src/tracing/browserTracingIntegration.ts @@ -733,7 +733,6 @@ export function startBrowserTracingPageLoadSpan( }; client.emit('startPageLoadSpan', pageloadSpanOptions, traceOptions); - getCurrentScope().setTransactionName(pageloadSpanOptions.name); const pageloadSpan = getActiveIdleSpan(client);