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 all 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
28 changes: 28 additions & 0 deletions docs/migration/continuous-profiling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Continuous Profiling API Changes

The continuous profiling API has been redesigned to give developers more explicit control over profiling sessions while maintaining ease of use. This guide outlines the key changes.

## New Profiling Modes

### profileLifecycle Option

We've introduced a new `profileLifecycle` option that allows you to explicitly set how profiling sessions are managed:

- `manual` (default) - You control profiling sessions using the API methods
- `trace` - Profiling sessions are automatically tied to traces

Previously, the profiling mode was implicitly determined by initialization options. Now you can clearly specify your intended behavior.

## New Sampling Controls

### profileSessionSampleRate

We've introduced `profileSessionSampleRate` to control what percentage of SDK instances will collect profiles. This is evaluated once during SDK initialization. This is particularly useful for:

- Controlling profiling costs across distributed services
- Managing profiling in serverless environments where you may only want to profile a subset of instances

### Deprecations

The `profilesSampleRate` option has been deprecated in favor of the new sampling controls.
The `profilesSampler` option hsa been deprecated in favor of manual profiler control.
7 changes: 7 additions & 0 deletions packages/core/src/types-hoist/profiling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ export interface ProfilingIntegration<T extends Client> extends Integration {
}

export interface Profiler {
/**
* Starts the profiler.
*/
startProfiler(): void;

/**
* Stops the profiler.
*/
stopProfiler(): void;
}

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