From c925e8b35910219d1eb45e0a0fc359d43fc60be0 Mon Sep 17 00:00:00 2001 From: Jay Lee Date: Sat, 1 Aug 2026 17:39:47 +0900 Subject: [PATCH 1/2] fix(profiling-node): respect session sample rate in trace lifecycle --- packages/profiling-node/src/integration.ts | 5 +++++ .../profiling-node/test/integration.test.ts | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/packages/profiling-node/src/integration.ts b/packages/profiling-node/src/integration.ts index 943ae5e35c7b..58258bec7c30 100644 --- a/packages/profiling-node/src/integration.ts +++ b/packages/profiling-node/src/integration.ts @@ -258,6 +258,11 @@ class ContinuousProfiler { * Starts trace lifecycle profiling. Profiling will remain active as long as there is an active span. */ private _startTraceLifecycleProfiling(): void { + if (!this._sampled) { + DEBUG_BUILD && debug.log('[Profiling] Profile session not sampled, trace lifecycle profiling will not be started.'); + return; + } + if (!this._client) { DEBUG_BUILD && debug.log( diff --git a/packages/profiling-node/test/integration.test.ts b/packages/profiling-node/test/integration.test.ts index 17da13aba191..13da995f303d 100644 --- a/packages/profiling-node/test/integration.test.ts +++ b/packages/profiling-node/test/integration.test.ts @@ -861,9 +861,28 @@ describe('ProfilingIntegration', () => { expect(stopProfilingSpy).not.toHaveBeenCalled(); }); + it('does not start profiler when profile session is not sampled', () => { + const [client] = makeCurrentSpanProfilingClient({ + profileLifecycle: 'trace', + profileSessionSampleRate: 0, + }); + + Sentry.setCurrentClient(client); + client.init(); + + const startProfilingSpy = vi.spyOn(CpuProfilerBindings, 'startProfiling'); + + const span = Sentry.startInactiveSpan({ forceTransaction: true, name: 'test' }); + + expect(startProfilingSpy).not.toHaveBeenCalled(); + + span.end(); + }); + it('starts profiler when first span is created', () => { const [client] = makeCurrentSpanProfilingClient({ profileLifecycle: 'trace', + profileSessionSampleRate: 1, }); Sentry.setCurrentClient(client); @@ -884,6 +903,7 @@ describe('ProfilingIntegration', () => { it('waits for the tail span to end before stopping the profiler', () => { const [client] = makeCurrentSpanProfilingClient({ profileLifecycle: 'trace', + profileSessionSampleRate: 1, }); Sentry.setCurrentClient(client); @@ -908,6 +928,7 @@ describe('ProfilingIntegration', () => { it('ending last span does not stop the profiler if first span is not ended', () => { const [client] = makeCurrentSpanProfilingClient({ profileLifecycle: 'trace', + profileSessionSampleRate: 1, }); Sentry.setCurrentClient(client); @@ -930,6 +951,7 @@ describe('ProfilingIntegration', () => { it('multiple calls to span.end do not restart the profiler', () => { const [client] = makeCurrentSpanProfilingClient({ profileLifecycle: 'trace', + profileSessionSampleRate: 1, }); Sentry.setCurrentClient(client); From be8ca07c9a8c08bafe5f7cc3f7cf187c7ab04bd1 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Mon, 3 Aug 2026 09:43:00 +0200 Subject: [PATCH 2/2] format --- packages/profiling-node/src/integration.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/profiling-node/src/integration.ts b/packages/profiling-node/src/integration.ts index 58258bec7c30..19644cf985e2 100644 --- a/packages/profiling-node/src/integration.ts +++ b/packages/profiling-node/src/integration.ts @@ -259,7 +259,8 @@ class ContinuousProfiler { */ private _startTraceLifecycleProfiling(): void { if (!this._sampled) { - DEBUG_BUILD && debug.log('[Profiling] Profile session not sampled, trace lifecycle profiling will not be started.'); + DEBUG_BUILD && + debug.log('[Profiling] Profile session not sampled, trace lifecycle profiling will not be started.'); return; }