Skip to content

node: implement new continuous profiling API spec #15635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6ea7aeb
types: add startProfilerSession and stopProfilerSession
JonasBa Mar 11, 2025
8d3c390
profiler: add startgst
JonasBa Mar 11, 2025
afc305f
profiler: deprecate profileSampler and profilesSampleRate
JonasBa Mar 11, 2025
80e64f8
profiler: add profilelifecycle and profilesessionsamplerate
JonasBa Mar 11, 2025
cbbba00
profiler: infer profiling mode based of current options provided
JonasBa Mar 11, 2025
7bc561f
profiler: simplify profiler check
JonasBa Mar 11, 2025
3d4942b
profiling: expect error in preprocessevent
JonasBa Mar 11, 2025
b4d8488
profiling: fix tests
JonasBa Mar 11, 2025
7c694b8
test: rename spanProfileUtils to integration.test.ts
JonasBa Mar 11, 2025
9d2a44e
fix formatting
JonasBa Mar 11, 2025
05c6cf8
profiling: implement new profiling API spec (#15636)
JonasBa Mar 12, 2025
08e12ea
fix formatting
JonasBa Mar 13, 2025
43b8aec
setup context
JonasBa Mar 13, 2025
6d16704
add envelope sending test
JonasBa Mar 13, 2025
e6fced8
remove log
JonasBa Mar 14, 2025
4b53f24
Merge branch 'develop' into jb/profiling/continuous-profiling-sv1
JonasBa Mar 14, 2025
da77c98
profiling: add debug log for mode
JonasBa Mar 18, 2025
757bb6b
profiling: add migration doc
JonasBa Mar 18, 2025
5ef0e8b
Merge branch 'develop' into jb/profiling/continuous-profiling-sv1
s1gr1d Mar 18, 2025
8c325f3
profiling: rename api
JonasBa Mar 18, 2025
dc8807c
profiling: rename api
JonasBa Mar 18, 2025
4be5973
profiling: rename api
JonasBa Mar 18, 2025
bceec4a
fix linters
JonasBa Mar 18, 2025
ba85359
Merge branch 'develop' into jb/profiling/continuous-profiling-sv1
JonasBa Mar 19, 2025
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
52 changes: 52 additions & 0 deletions packages/core/src/profiling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function isProfilingIntegrationWithProfiler(
* Starts the Sentry continuous profiler.
* This mode is exclusive with the transaction profiler and will only work if the profilesSampleRate is set to a falsy value.
* In continuous profiling mode, the profiler will keep reporting profile chunks to Sentry until it is stopped, which allows for continuous profiling of the application.
* @deprecated Use `startProfileSession()` instead.
*/
function startProfiler(): void {
const client = getClient();
Expand All @@ -44,6 +45,7 @@ function startProfiler(): void {
/**
* Stops the Sentry continuous profiler.
* Calls to stop will stop the profiler and flush the currently collected profile data to Sentry.
* @deprecated Use `stopProfilerSession()` instead.
*/
function stopProfiler(): void {
const client = getClient();
Expand All @@ -66,7 +68,57 @@ function stopProfiler(): void {
integration._profiler.stop();
}

/**
* Starts a new profiler session.
*/
function startProfileSession(): void {
const client = getClient();
if (!client) {
DEBUG_BUILD && logger.warn('No Sentry client available, profiling is not started');
return;
}

const integration = client.getIntegrationByName<ProfilingIntegration<any>>('ProfilingIntegration');
if (!integration) {
DEBUG_BUILD && logger.warn('ProfilingIntegration is not available');
return;
}

if (!isProfilingIntegrationWithProfiler(integration)) {
DEBUG_BUILD && logger.warn('Profiler is not available on profiling integration.');
return;
}

integration._profiler.startProfileSession();
}

/**
* Stops the current profiler session.
*/
function stopProfileSession(): void {
const client = getClient();
if (!client) {
DEBUG_BUILD && logger.warn('No Sentry client available, profiling is not started');
return;
}

const integration = client.getIntegrationByName<ProfilingIntegration<any>>('ProfilingIntegration');
if (!integration) {
DEBUG_BUILD && logger.warn('ProfilingIntegration is not available');
return;
}

if (!isProfilingIntegrationWithProfiler(integration)) {
DEBUG_BUILD && logger.warn('Profiler is not available on profiling integration.');
return;
}

integration._profiler.stopProfileSession();
}

export const profiler: Profiler = {
startProfiler,
stopProfiler,
startProfileSession,
stopProfileSession,
};
21 changes: 21 additions & 0 deletions packages/core/src/types-hoist/profiling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,36 @@ export interface ContinuousProfiler<T extends Client> {
initialize(client: T): void;
start(): void;
stop(): void;
startProfileSession(): void;
stopProfileSession(): void;
}

export interface ProfilingIntegration<T extends Client> extends Integration {
_profiler: ContinuousProfiler<T>;
}

export interface Profiler {
/**
* Starts the profiler.
* @deprecated Use `startProfileSession()` instead.
*/
startProfiler(): void;

/**
* Stops the profiler.
* @deprecated Use `stopProfilerSession()` instead.
*/
stopProfiler(): void;

/**
* Starts a new profiler session.
*/
startProfileSession(): void;

/**
* Stops the current profiler session.
*/
stopProfileSession(): void;
}

export type ThreadId = string;
Expand Down
20 changes: 20 additions & 0 deletions packages/node/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export interface BaseNodeOptions {

/**
* Sets profiling sample rate when @sentry/profiling-node is installed
*
* @deprecated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add migration docs for this and profilesSampler.

*/
profilesSampleRate?: number;

Expand All @@ -39,9 +41,27 @@ export interface BaseNodeOptions {
*
* @returns A sample rate between 0 and 1 (0 drops the profile, 1 guarantees it will be sent). Returning `true` is
* equivalent to returning 1 and returning `false` is equivalent to returning 0.
*
* @deprecated
*/
profilesSampler?: (samplingContext: SamplingContext) => number | boolean;

/**
* Sets profiling session sample rate - only evaluated once per SDK initialization.
* @default 0
*/
profileSessionSampleRate?: number;

/**
* Set the lifecycle of the profiler.
*
* - `manual`: The profiler will be manually started and stopped.
* - `trace`: The profiler will be automatically started when when a span is sampled and stopped when there are no more sampled spans.
*
* @default 'manual'
*/
profileLifecycle?: 'manual' | 'trace';

/** Sets an optional server name (device name) */
serverName?: string;

Expand Down
Loading
Loading