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
8 changes: 1 addition & 7 deletions packages/profiling-node/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,12 @@ class ContinuousProfiler {
return;
}

const transport = this._client.getTransport();
if (!transport) {
DEBUG_BUILD && debug.log('[Profiling] No transport available to send profile chunk.');
return;
}

const dsn = this._client.getDsn();
const metadata = this._client.getSdkMetadata();
const tunnel = this._client.getOptions().tunnel;

const envelope = makeProfileChunkEnvelope('node', chunk, metadata?.sdk, tunnel, dsn);
transport.send(envelope).then(null, reason => {
this._client.sendEnvelope(envelope).then(null, reason => {
DEBUG_BUILD && debug.error('Error while sending profile chunk envelope:', reason);
});
}
Expand Down
26 changes: 26 additions & 0 deletions packages/profiling-node/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,32 @@ describe('ProfilingIntegration', () => {
}),
});
});

it('emits the `beforeEnvelope` hook for profile chunks', async () => {
const [client, transport] = makeSpanProfilingClient({
profileLifecycle: 'manual',
profileSessionSampleRate: 1,
});

Sentry.setCurrentClient(client);
client.init();

vi.spyOn(transport, 'send').mockReturnValue(Promise.resolve({}));

const beforeEnvelope = vi.fn();
client.on('beforeEnvelope', beforeEnvelope);

Sentry.profiler.startProfiler();
await wait(1000);
Sentry.profiler.stopProfiler();

await Sentry.flush(1000);

expect(beforeEnvelope).toHaveBeenCalledTimes(1);
expect(beforeEnvelope.mock.calls[0]?.[0]?.[1]?.[0]?.[0]).toMatchObject({
type: 'profile_chunk',
});
});
});
});

Expand Down
Loading