Unsampled pageload span is profiled when profileLifecycle is 'trace' (browser UI profiling)
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 82/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- javascript, typescript
- Bereich
- frontend, performance
Rechercherichtung
Beginne mit packages/browser/src/profiling/UIProfiler.ts und vergleiche notifyRootSpanActive() mit dem spanStart-Listener in _setupTraceLifecycleListeners(). Prüfe in den bestehenden Profiling-Tests, ob ein bereits aktiver, nicht gesampelter Root-Span beim Setup abgedeckt ist. Als erledigt gilt die Aufgabe, wenn dieser Fall den Profiler nicht startet und keinen Profil-Chunk sendet, während gesampelte Root-Spans weiterhin das Profiling starten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/browser
SDK Version
@sentry/browser 11.8.0 (also reproduced on 11.4.0; UIProfiler.ts on develop is unchanged as of 2026-10-19)
Framework Version
No response
Link to Sentry event
No response
Reproduction Example/SDK Setup
import * as Sentry from '@sentry/browser';
Sentry.init({
dsn: '<dsn>',
integrations: [Sentry.browserTracingIntegration(), Sentry.browserProfilingIntegration()],
tracesSampleRate: 0, // pageload span NOT sampled -> expect NO profiling
profileSessionSampleRate: 1,
profileLifecycle: 'trace',
});
The page is served with Document-Policy: js-profiling.
Steps to Reproduce
- Initialize the SDK with
profileLifecycle: 'trace',profileSessionSampleRate: 1andtracesSampleRate: 0(see SDK setup above). - Load the page. The pageload span is not sampled (
isRecording() === false,traceFlags === 0). - Observe that
new Profiler(...)is called once and aprofile_chunkenvelope is sent when the pageload span ends.
Expected Result
The pageload span is not sampled, so trace lifecycle profiling should not start. This is how root spans started after setup are already handled.
Actual Result
The profiler starts for the unsampled pageload span and a profile_chunk is sent.
I checked this in Chromium with a window.Profiler stub that counts constructor calls and an in-memory transport:
tracesSampleRate: 0,profileSessionSampleRate: 1: profiler started once,profile_chunksenttracesSampleRate: 0,profileSessionSampleRate: 0: profiler not started (control)tracesSampleRate: 1,profileSessionSampleRate: 1: profiler started once,profile_chunkand the pageload span sent (expected)tracesSampleRate: 0,profileSessionSampleRate: 1, pageload instrumentation off, an unsampled root span started afterinit: profiler not started
The last case shows that only the root span that is already active at setup skips the sampling check.
Additional Context
Root cause (source walkthrough)
In packages/browser/src/profiling/integration.ts (develop):
- After
profiler.initialize(client), setup callsprofiler.notifyRootSpanActive(rootSpan)for the active root span. The comment says "If there is an active, sampled root span already, notify the profiler". - Setup calls it again in a
setTimeout(0). This is the path that picks up the pageload span thatbrowserTracingIntegrationstarts inafterAllSetup.
In packages/browser/src/profiling/UIProfiler.ts:
- The
spanStartlistener registered by_setupTraceLifecycleListeners()returns early when!span.isRecording()("Only count sampled root spans"). notifyRootSpanActive()only checks the lifecycle mode and_sessionSampled. It then registers the span and calls_beginProfiling()without checkingrootSpan.isRecording().
So an unsampled root span that is already active at setup starts the profiler. The unsampled span still emits spanEnd, so the profile runs for the length of the pageload.
#17619, which added the trace lifecycle, describes it as "Starts when the first sampled root span starts".
Impact
With profileSessionSampleRate: 1, unsampled pageload spans can still start UI profiling in supported browsers. Reducing tracesSampleRate, even to 0, does not prevent this startup path. This can add unintended profiling overhead and profile usage, without a sampled pageload span to correlate with the resulting chunks.
Related
#22927 was the same kind of gap in the Node trace lifecycle, there for the session sampling decision.
Suggested fix
Return early in notifyRootSpanActive() when !rootSpan.isRecording(), matching the spanStart listener. Happy to open a PR.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 8.8k
- Forks
- 1.9k
- Ø Merge
- 1 T. 11 Std.
- Gemergte PRs (30 T.)
- 613
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus getsentry/sentry-javascript
-
Hapi: `route.method.toUpperCase is not a function` for routes registered with an array of methodsEvtl. vergeben @s1gr1d hat das vor 1 Tag übernommen. OffenBug Hapi Waiting for: Product Owner
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
getsentry/sentry-javascript#25481 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
node:http client span never ends when the response is destroyed without an error (res.destroy())Evtl. vergeben @4ktLuffy hat das vor 1 Tag übernommen. OffenBug Node.js
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
getsentry/sentry-javascript#25469 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Core Feature: Typescript Meta: Breaking
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
getsentry/sentry-javascript#25286 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 80/100
getsentry/sentry-javascript#24860 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
javascript
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
getsentry/sentry-javascript#24200 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in getsentry/sentry-javascript
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
diegosouzapw/OmniRoute#17386 ·
Maintainer antworten meist innerhalb von 1 Tag
-
ready-for-agent
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
Maintainer antworten meist innerhalb von 1 Tag
-
area/dashboard kind/bug kind/bug-qa QA/dev-automation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
vybestack/llxprt-code#3917 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
api-parity
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
IBM/carbon-components-ember#1157 ·
Maintainer antworten meist innerhalb von 1 Tag