@sentry/profiling-node 11.0.0 → 11.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,43 +10,12 @@
10
10
  [![npm dm](https://img.shields.io/npm/dm/@sentry/profiling-node.svg)](https://www.npmjs.com/package/@sentry/profiling-node)
11
11
  [![npm dt](https://img.shields.io/npm/dt/@sentry/profiling-node.svg)](https://www.npmjs.com/package/@sentry/profiling-node)
12
12
 
13
- ## Installation
13
+ Profiling for Node.js applications.
14
14
 
15
- Profiling works as an extension of tracing so you will need both @sentry/node and @sentry/profiling-node installed.
15
+ ## Documentation
16
16
 
17
- ```bash
18
- # Using yarn
19
- yarn add @sentry/node @sentry/profiling-node
20
-
21
- # Using npm
22
- npm install --save @sentry/node @sentry/profiling-node
23
- ```
24
-
25
- ## Usage
26
-
27
- ```javascript
28
- import * as Sentry from '@sentry/node';
29
- import { nodeProfilingIntegration } from '@sentry/profiling-node';
30
-
31
- Sentry.init({
32
- dsn: 'https://7fa19397baaf433f919fbe02228d5470@o1137848.ingest.sentry.io/6625302',
33
- debug: true,
34
- tracesSampleRate: 1,
35
- profileSessionSampleRate: 1,
36
- profileLifecycle: 'trace',
37
- integrations: [nodeProfilingIntegration()],
38
- });
39
- ```
40
-
41
- The Sentry SDK will now collect profile chunks while spans are active, including spans started by automatic instrumentation.
42
-
43
- ```javascript
44
- Sentry.startSpan({ name: 'some workflow' }, () => {
45
- // The code in here will be profiled
46
- });
47
- ```
48
-
49
- With `profileLifecycle: 'manual'` (the default), you can start and stop the profiler by calling `Sentry.profiler.startProfiler()` and `Sentry.profiler.stopProfiler()`.
17
+ - [Getting started](https://docs.sentry.io/platforms/javascript/guides/node/profiling/)
18
+ - [Configuration](https://docs.sentry.io/platforms/javascript/guides/node/profiling/#enabling-profiling)
50
19
 
51
20
  ### Building the package from source
52
21
 
@@ -55,19 +24,16 @@ from source. The libraries required to successfully build the package from sourc
55
24
  already required to build any other package which uses native modules and if your codebase uses any of those modules,
56
25
  there is a fairly good chance this will work out of the box. The required packages are python, make and g++.
57
26
 
58
- **Windows:** If you are building on windows, you may need to install windows-build-tools
27
+ **Windows:** If you are building on windows, you may need to install Visual Studio's C++ build tools.
59
28
 
60
- **_Python:_** Python 3.12 is not supported yet so you will need a version of python that is lower than 3.12
61
-
62
- ```bash
29
+ **macOS:** Install Xcode Command Line Tools for the compiler and make.
63
30
 
64
- # using yarn package manager
65
- yarn global add windows-build-tools
66
- # or npm package manager
67
- npm i -g windows-build-tools
68
- ```
31
+ See the [node-gyp prerequisites](https://github.com/nodejs/node-gyp#installation) for supported Python versions and
32
+ platform-specific requirements.
69
33
 
70
- After you have installed the toolchain, you should be able to build the binaries from source
34
+ After you have installed the toolchain, you should be able to build the binaries from source.
35
+ The native bindings are maintained in the [Node CPU profiler repository](https://github.com/getsentry/sentry-javascript-profiling-node-binaries).
36
+ Clone that repository, install its dependencies with `yarn install --ignore-scripts`, and run the following from its root:
71
37
 
72
38
  ```bash
73
39
  # configure node-gyp using yarn
@@ -81,206 +47,20 @@ yarn build:bindings
81
47
  npm run build:bindings
82
48
  ```
83
49
 
84
- After the binaries are built, you should see them inside the profiling-node/lib folder.
50
+ After the binaries are built, you should see them inside that repository's lib folder.
85
51
 
86
52
  ### Prebuilt binaries
87
53
 
88
- We currently ship prebuilt binaries for a few of the most common platforms and node versions (v18-24).
54
+ We currently ship prebuilt binaries for a few of the most common platforms and node versions.
89
55
 
90
56
  - macOS x64
91
57
  - Linux ARM64 (musl)
92
58
  - Linux x64 (glibc)
93
59
  - Windows x64
94
60
 
95
- For a more detailed list, see job_compile_bindings_profiling_node job in our build.yml github action workflow.
96
-
97
- ### Bundling
98
-
99
- If you are looking to squeeze some extra performance or improve cold start in your application (especially true for
100
- serverless environments where modules are often evaluates on a per request basis), then we recommend you look into
101
- bundling your code. Modern JS engines are much faster at parsing and compiling JS than following long module resolution
102
- chains and reading file contents from disk. Because @sentry/profiling-node is a package that uses native node modules,
103
- bundling it is slightly different than just bundling javascript. In other words, the bundler needs to recognize that a
104
- .node file is node native binding and move it to the correct location so that it can later be used. Failing to do so
105
- will result in a MODULE_NOT_FOUND error.
106
-
107
- The easiest way to make bundling work with @sentry/profiling-node and other modules which use native nodejs bindings is
108
- to mark the package as external - this will prevent the code from the package from being bundled, but it means that you
109
- will now need to rely on the package to be installed in your production environment.
110
-
111
- To mark the package as external, use the following configuration:
112
-
113
- [Next.js 13+](https://nextjs.org/docs/app/api-reference/next-config-js/serverComponentsExternalPackages)
114
-
115
- ```js
116
- const { withSentryConfig } = require('@sentry/nextjs');
117
-
118
- /** @type {import('next').NextConfig} */
119
- const nextConfig = {
120
- experimental: {
121
- // Add the "@sentry/profiling-node" to serverComponentsExternalPackages.
122
- serverComponentsExternalPackages: ['@sentry/profiling-node'],
123
- },
124
- };
125
-
126
- module.exports = withSentryConfig(nextConfig, {/* ... */});
127
- ```
128
-
129
- [webpack](https://webpack.js.org/configuration/externals/#externals)
130
-
131
- ```js
132
- externals: {
133
- "@sentry/profiling-node": "commonjs @sentry/profiling-node",
134
- },
135
- ```
136
-
137
- [esbuild](https://esbuild.github.io/api/#external)
138
-
139
- ```js
140
- {
141
- entryPoints: ['index.js'],
142
- platform: 'node',
143
- external: ['@sentry/profiling-node'],
144
- }
145
- ```
146
-
147
- [Rollup](https://rollupjs.org/configuration-options/#external)
148
-
149
- ```js
150
- {
151
- entry: 'index.js',
152
- external: '@sentry/profiling-node'
153
- }
154
- ```
155
-
156
- [serverless-esbuild (serverless.yml)](https://www.serverless.com/plugins/serverless-esbuild#external-dependencies)
157
-
158
- ```yml
159
- custom:
160
- esbuild:
161
- external:
162
- - @sentry/profiling-node
163
- packagerOptions:
164
- scripts:
165
- - npm install @sentry/profiling-node
166
- ```
167
-
168
- [vercel-ncc](https://github.com/vercel/ncc#programmatically-from-nodejs)
169
-
170
- ```js
171
- {
172
- externals: ["@sentry/profiling-node"],
173
- }
174
- ```
175
-
176
- [vite](https://vitejs.dev/config/ssr-options.html#ssr-external)
177
-
178
- ```js
179
- ssr: {
180
- external: ['@sentry/profiling-node'];
181
- }
182
- ```
183
-
184
- Marking the package as external is the simplest and most future proof way of ensuring it will work, however if you want
185
- to bundle it, it is possible to do so as well. Bundling has the benefit of improving your script startup time as all of
186
- the code is (usually) inside a single executable .js file, which saves time on module resolution.
187
-
188
- In general, when attempting to bundle .node native file extensions, you will need to tell your bundler how to treat
189
- these, as by default it does not know how to handle them. The required approach varies between build tools and you will
190
- need to find which one will work for you.
191
-
192
- The result of bundling .node files correctly is that they are placed into your bundle output directory with their
193
- require paths updated to reflect their final location.
194
-
195
- Example of bundling @sentry/profiling-node with esbuild and .copy loader
196
-
197
- ```json
198
- // package.json
199
- {
200
- "scripts": "node esbuild.serverless.js"
201
- }
202
- ```
203
-
204
- ```js
205
- // esbuild.serverless.js
206
- const { sentryEsbuildPlugin } = require('@sentry/esbuild-plugin');
207
-
208
- require('esbuild').build({
209
- entryPoints: ['./index.js'],
210
- outfile: './dist',
211
- platform: 'node',
212
- bundle: true,
213
- minify: true,
214
- sourcemap: true,
215
- // This is no longer necessary
216
- // external: ["@sentry/profiling-node"],
217
- loader: {
218
- // ensures .node binaries are copied to ./dist
219
- '.node': 'copy',
220
- },
221
- plugins: [
222
- // See https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/esbuild/
223
- sentryEsbuildPlugin({
224
- project: '',
225
- org: '',
226
- authToken: '',
227
- release: '',
228
- sourcemaps: {
229
- // Specify the directory containing build artifacts
230
- assets: './dist/**',
231
- },
232
- }),
233
- ],
234
- });
235
- ```
236
-
237
- Once you run `node esbuild.serverless.js` esbuild wil bundle and output the files to ./dist folder, but note that all of
238
- the binaries will be copied. This is wasteful as you will likely only need one of these libraries to be available during
239
- runtime. Since the binaries follow the `sentry_cpu_profiler-<platform>-<arch>-<stdlib>-<abi>.node` naming scheme, you can
240
- delete the ones that do not match your target runtime as part of your build step to reduce the deployment size.
241
-
242
- ### Environment flags
243
-
244
- The default mode of the v8 CpuProfiler is kEagerLoggin which enables the profiler even when no profiles are active -
245
- this is good because it makes calls to startProfiling fast at the tradeoff for constant CPU overhead. The behavior can
246
- be controlled via the `SENTRY_PROFILER_LOGGING_MODE` environment variable with values of `eager|lazy`. If you opt to use
247
- the lazy logging mode, calls to startProfiling may be slow (depending on environment and node version, it can be in the
248
- order of a few hundred ms).
249
-
250
- Example of starting a server with lazy logging mode.
251
-
252
- ```javascript
253
- SENTRY_PROFILER_LOGGING_MODE=lazy node server.js
254
- ```
255
-
256
- ## FAQ 💭
257
-
258
- ### Can the profiler leak PII to Sentry?
259
-
260
- The profiler does not collect function arguments so leaking any PII is unlikely. We only collect a subset of the values
261
- which may identify the device and os that the profiler is running on (if you are already using tracing, it is likely
262
- that these values are already being collected by the SDK).
263
-
264
- There is one way a profiler could leak pii information, but this is unlikely and would only happen for cases where you
265
- might be creating or naming functions which might contain pii information such as
266
-
267
- ```js
268
- eval('function scriptFor${PII_DATA}....');
269
- ```
270
-
271
- In that case it is possible that the function name may end up being reported to Sentry.
272
-
273
- ### Are worker threads supported?
274
-
275
- No. All instances of the profiler are scoped per thread In practice, this means that starting a transaction on thread A
276
- and delegating work to thread B will only result in sample stacks being collected from thread A. That said, nothing
277
- should prevent you from starting a transaction on thread B concurrently which will result in two independent profiles
278
- being sent to the Sentry backend. We currently do not do any correlation between such transactions, but we would be open
279
- to exploring the possibilities. Please file an issue if you have suggestions or specific use-cases in mind.
61
+ For a more detailed list, see the `job_compile` job in the [native build workflow](https://github.com/getsentry/sentry-javascript-profiling-node-binaries/blob/main/.github/workflows/build.yml).
280
62
 
281
- ### How much overhead will this profiler add?
63
+ ## Support
282
64
 
283
- The profiler uses the kEagerLogging option by default which trades off fast calls to startProfiling for a small amount
284
- of constant CPU overhead. If you are using kEagerLogging then the tradeoff is reversed and there will be a small CPU
285
- overhead while the profiler is not running, but calls to startProfiling could be slow (in our tests, this varies by
286
- environments and node versions, but could be in the order of a couple 100ms).
65
+ - [Report a bug](https://github.com/getsentry/sentry-javascript/issues/new/choose)
66
+ - [Contributing](https://github.com/getsentry/sentry-javascript/blob/develop/CONTRIBUTING.md)
@@ -1 +1 @@
1
- {"type":"module","version":"11.0.0","sideEffects":false}
1
+ {"type":"module","version":"11.1.0","sideEffects":false}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/profiling-node",
3
- "version": "11.0.0",
3
+ "version": "11.1.0",
4
4
  "description": "Official Sentry SDK for Node.js Profiling",
5
5
  "repository": "git://github.com/getsentry/sentry-javascript.git",
6
6
  "homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/profiling-node",
@@ -51,8 +51,8 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@sentry/node-cpu-profiler": "^2.4.4",
54
- "@sentry/core": "11.0.0",
55
- "@sentry/node": "11.0.0"
54
+ "@sentry/core": "11.1.0",
55
+ "@sentry/node": "11.1.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/node": "^18.19.1"