You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/platforms/javascript/common/profiling/node-profiling.mdx
+57-5
Original file line number
Diff line number
Diff line change
@@ -36,6 +36,14 @@ You have to have the <PlatformSdkPackageName fallback="@sentry/node"/> (minimum
36
36
37
37
## Enabling Profiling
38
38
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
+
39
47
To enable profiling, add `@sentry/profiling-node` to your imports and set up `nodeProfilingIntegration` in your Sentry config.
40
48
41
49
```javascript {diff}
@@ -48,24 +56,67 @@ Sentry.init({
48
56
+nodeProfilingIntegration(),
49
57
],
50
58
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',
53
61
});
54
62
55
63
// 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.
58
65
Sentry.startSpan(
59
66
{
60
67
op:"rootSpan",
61
68
name:"My root span",
62
69
},
63
70
() => {
64
-
//Any code in this callback will be profiled.
71
+
//The code executed here will be profiled
65
72
}
66
73
);
67
74
```
68
75
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.
// 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.
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
82
133
- Windows x64:Node v16, v18, v20, v22
83
134
84
135
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.
0 commit comments