Skip to content

Commit 9409e2a

Browse files
JonasBaphacops
andauthored
docs: update continuous profiling docs (#12998)
* docs: update continuous profiling docs * add profileSessionSampleRate * Update docs/platforms/javascript/common/profiling/node-profiling.mdx * Update docs/platforms/javascript/common/profiling/node-profiling.mdx Co-authored-by: Pierre Massat <[email protected]> * Update docs/platforms/javascript/common/profiling/node-profiling.mdx Co-authored-by: Pierre Massat <[email protected]> * Update docs/platforms/javascript/common/profiling/node-profiling.mdx Co-authored-by: Pierre Massat <[email protected]> * Update docs/platforms/javascript/common/profiling/node-profiling.mdx Co-authored-by: Pierre Massat <[email protected]> * Update docs/platforms/javascript/common/profiling/node-profiling.mdx Co-authored-by: Pierre Massat <[email protected]> * fix start and stop naming --------- Co-authored-by: Pierre Massat <[email protected]>
1 parent a591d56 commit 9409e2a

File tree

1 file changed

+57
-5
lines changed

1 file changed

+57
-5
lines changed

docs/platforms/javascript/common/profiling/node-profiling.mdx

+57-5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ You have to have the <PlatformSdkPackageName fallback="@sentry/node"/> (minimum
3636

3737
## Enabling Profiling
3838

39+
Profiling supports two modes - `manual` and `trace`. The two modes are mutually exclusive, and cannot be used at the same time.
40+
41+
In `manual` mode, the profiling data collection can be managed via calls to `Sentry.profiler.startProfiler` and `Sentry.profiler.stopProfiler`. You are entirely in the in control of when the profiler runs.
42+
43+
In `trace` mode, the profiler manages its own start and stop calls, which are based on spans: the profiler continues to run while there is at least one active span, and stops when there are no active spans.
44+
45+
### Enabling Trace Lifecycle Profiling
46+
3947
To enable profiling, add `@sentry/profiling-node` to your imports and set up `nodeProfilingIntegration` in your Sentry config.
4048

4149
```javascript {diff}
@@ -48,24 +56,67 @@ Sentry.init({
4856
+ nodeProfilingIntegration(),
4957
],
5058
tracesSampleRate: 1.0,
51-
+ // Set sampling rate for profiling - this is relative to tracesSampleRate
52-
+ profilesSampleRate: 1.0,
59+
+ profileSessionSampleRate: 1.0,
60+
+ profileLifecycle: 'trace',
5361
});
5462

5563
// Profiling happens automatically after setting it up with `Sentry.init()`.
56-
// All spans captured in your application will have profiling data attached to them.
57-
// You can also manually capture spans with `startSpan`, as shown below:
64+
// All spans (unless those discarded by sampling) will have profiling data attached to them.
5865
Sentry.startSpan(
5966
{
6067
op: "rootSpan",
6168
name: "My root span",
6269
},
6370
() => {
64-
// Any code in this callback will be profiled.
71+
// The code executed here will be profiled
6572
}
6673
);
6774
```
6875

76+
### Enabling Manual Lifecycle Profiling
77+
78+
To enable profiling, add `@sentry/profiling-node` to your imports and set up `nodeProfilingIntegration` in your Sentry config.
79+
80+
```javascript {diff}
81+
const { nodeProfilingIntegration } = require("@sentry/profiling-node");
82+
83+
Sentry.init({
84+
dsn: "___PUBLIC_DSN___",
85+
integrations: [
86+
// Add our Profiling integration
87+
+ nodeProfilingIntegration(),
88+
],
89+
tracesSampleRate: 1.0,
90+
+ profileSessionSampleRate: 1.0,
91+
+ profileLifecycle: 'manual',
92+
});
93+
94+
// All spans (unless those discarded by sampling) will have profiling data attached to them.
95+
Sentry.profiler.startProfiler();
96+
// Code executed between these two calls will be profiled
97+
Sentry.profiler.stopProfiler();
98+
```
99+
100+
### Managing profile sampling rates
101+
102+
Sentry SDK supports an additional `profileSessionSampleRate` that will enable or disable profiling for the entire session. This can be used if you want to control session sampling rates at the service level as the sampling decision is evaluated only once at SDK init.
103+
104+
This is useful for cases where you deploy your service many times, but would only like a subset of those services to be profiled.
105+
106+
```javascript {diff}
107+
const { nodeProfilingIntegration } = require("@sentry/profiling-node");
108+
109+
Sentry.init({
110+
dsn: "___PUBLIC_DSN___",
111+
integrations: [
112+
// Add our Profiling integration
113+
nodeProfilingIntegration(),
114+
],
115+
tracesSampleRate: 1.0,
116+
+ profileSessionSampleRate: 0.0
117+
});
118+
119+
69120
## How Does It Work?
70121

71122
Under the hood, the Sentry profiler uses V8's [CpuProfiler](https://v8docs.nodesource.com/node-18.2/d2/d34/classv8_1_1_cpu_profiler.html) to collect stack samples. This means that `sentry/profiling-node` is written as a [native add-on](https://nodejs.org/docs/latest-v18.x/api/addons.html) for Node and won't run in environments like Deno or Bun. Profiling enhances tracing by providing profiles for individual transactions. This allows you to look at higher level performance information like transaction and span durations before diving deeper and looking at profiles.
@@ -82,3 +133,4 @@ Starting from version `0.1.0`, the `@sentry/profiling-node` package precompiles
82133
- Windows x64: Node v16, v18, v20, v22
83134

84135
The set of common architectures should cover a wide variety of use cases, but if you have feedback or experience different behavior, please open an issue in the [Sentry JavaScript SDK](https://github.com/getsentry/sentry-javascript) repository.
136+
```

0 commit comments

Comments
 (0)