Unsampled pageload span is profiled when profileLifecycle is 'trace' (browser UI profiling)
維護者通常 1 天內回覆
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 82/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- javascript, typescript
- 領域
- frontend, performance
研究方向
從 packages/browser/src/profiling/UIProfiler.ts 開始,比較 notifyRootSpanActive() 與 _setupTraceLifecycleListeners() 中的 spanStart 監聽器。檢查現有的 profiling 測試是否涵蓋設定時已處於作用中且未取樣的根 span。完成標準是:此情況不會啟動 profiler,也不會傳送 profile 資料區塊;而已取樣的根 span 仍會啟動 profiling。
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- TypeScript
- 星號
- 8.8k
- 分支
- 1.9k
- 平均合併
- 1 天 12 小時
- 30 天內合併 PR
- 598
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
getsentry/sentry-javascript 的其他 Issue
-
Hapi: `route.method.toUpperCase is not a function` for routes registered with an array of methods可能已有人在做 @itisrmk 於 2 天前認領。 未關閉Bug Hapi Waiting for: Product Owner
難度 2/5 1-3 小時 新手友好度 88/100
getsentry/sentry-javascript#25481 · 1 則留言 ·
維護者通常 1 天內回覆
-
node:http client span never ends when the response is destroyed without an error (res.destroy())可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉Bug Node.js Waiting for: Product Owner
難度 2/5 1-3 小時 新手友好度 78/100
getsentry/sentry-javascript#25469 · 1 則留言 ·
維護者通常 1 天內回覆
-
Core Feature: Typescript Meta: Breaking
難度 2/5 1-3 小時 新手友好度 65/100
getsentry/sentry-javascript#25286 · 2 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 80/100
getsentry/sentry-javascript#24860 · 1 則留言 ·
維護者通常 1 天內回覆
-
javascript
難度 2/5 1-3 小時 新手友好度 75/100
getsentry/sentry-javascript#24200 · 2 則留言 ·
維護者通常 1 天內回覆
查看 getsentry/sentry-javascript 的全部 Issue
相似的 Issue
-
docs(api): openapi.yaml still documents gif-tools optimize colors as 2-256 instead of 2, 4, 16, 256未關閉area: backend documentation priority: low
難度 2/5 1-3 小時 新手友好度 84/100
snapotter-hq/SnapOtter#2919 ·
維護者通常 1 天內回覆
-
accepted :+1: bug db/redis
難度 2/5 1-3 小時 新手友好度 76/100
beekeeper-studio/beekeeper-studio#4882 · 1 則留言 ·
維護者通常 1 天內回覆
-
ready-for-triage
難度 2/5 1-3 小時 新手友好度 72/100
konflux-ci/konflux-ui#1630 · 1 則留言 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 67/100
ahmedkhaleel2004/gitdiagram#233 ·
-
難度 2/5 1-3 小時 新手友好度 72/100
simkimsia/netlify-axi#19 ·
維護者通常 1 天內回覆