Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Unsampled pageload span is profiled when profileLifecycle is 'trace' (browser UI profiling)

Abierto Apto para principiantes
#25,497 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@Jxxunnn ya está trabajando en esto.

Desde el 19/10/2026.

  • #25498 de @Jxxunnn — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
82/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
javascript, typescript

Línea de trabajo

Empieza con packages/browser/src/profiling/UIProfiler.ts y compara notifyRootSpanActive() con el listener spanStart de _setupTraceLifecycleListeners(). Comprueba en las pruebas de profiling existentes si se contempla el caso de un span raíz ya activo y no muestreado durante la configuración. Se considera terminado cuando ese caso no inicia el profiler ni envía un fragmento de perfil, mientras que los spans raíz muestreados siguen iniciando el profiling.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Browser Waiting for: Product Owner
Is there an existing issue for this?
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
  1. Initialize the SDK with profileLifecycle: 'trace', profileSessionSampleRate: 1 and tracesSampleRate: 0 (see SDK setup above).
  2. Load the page. The pageload span is not sampled (isRecording() === false, traceFlags === 0).
  3. Observe that new Profiler(...) is called once and a profile_chunk envelope 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_chunk sent
  • tracesSampleRate: 0, profileSessionSampleRate: 0: profiler not started (control)
  • tracesSampleRate: 1, profileSessionSampleRate: 1: profiler started once, profile_chunk and the pageload span sent (expected)
  • tracesSampleRate: 0, profileSessionSampleRate: 1, pageload instrumentation off, an unsampled root span started after init: 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 calls profiler.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 that browserTracingIntegration starts in afterAllSetup.

In packages/browser/src/profiling/UIProfiler.ts:

  • The spanStart listener 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 checking rootSpan.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.

Lenguaje dominante
TypeScript
Estrellas
8.8k
Forks
1.9k
Merge medio
1 d 11 h
PR fusionados (30 d)
578

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de getsentry/sentry-javascript

Todos los issues de getsentry/sentry-javascript

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.