Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/profiling-node/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ 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(
Expand Down
22 changes: 22 additions & 0 deletions packages/profiling-node/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Loading