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: packages/node-core/README.md
+110Lines changed: 110 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,6 +116,116 @@ If it is not possible for you to pass the `--import` flag to the Node.js binary,
116
116
NODE_OPTIONS="--import ./instrument.mjs" npm run start
117
117
```
118
118
119
+
## Errors-only Lightweight Mode
120
+
121
+
If you only need error monitoring without performance tracing, you can use the lightweight mode which doesn't require OpenTelemetry dependencies. This mode is ideal for:
122
+
123
+
- Applications that only need error tracking
124
+
- Reducing bundle size and runtime overhead
125
+
- Environments where OpenTelemetry isn't needed
126
+
127
+
### Installation (Light Mode)
128
+
129
+
```bash
130
+
npm install @sentry/node-core
131
+
132
+
# Or yarn
133
+
yarn add @sentry/node-core
134
+
```
135
+
136
+
### Usage (Light Mode)
137
+
138
+
Import from `@sentry/node-core/light` instead of `@sentry/node-core`:
139
+
140
+
```js
141
+
// ESM
142
+
import*asSentryfrom'@sentry/node-core/light';
143
+
144
+
// CJS
145
+
constSentry=require('@sentry/node-core/light');
146
+
147
+
// Initialize Sentry BEFORE creating your HTTP server
148
+
Sentry.init({
149
+
dsn:'__DSN__',
150
+
// ...
151
+
});
152
+
153
+
// Then create your server (Express, Fastify, etc.)
154
+
constapp=express();
155
+
```
156
+
157
+
**Important:** Initialize Sentry **before** creating your HTTP server to enable automatic request isolation.
158
+
159
+
### Features in Light Mode
160
+
161
+
**Included:**
162
+
163
+
- Error tracking and reporting
164
+
- Automatic request isolation (Node.js 22+)
165
+
- Breadcrumbs
166
+
- Context and user data
167
+
- Local variables capture
168
+
- Distributed tracing (via `sentry-trace` and `baggage` headers)
169
+
170
+
**Not included:**
171
+
172
+
- Performance monitoring (no spans/transactions)
173
+
174
+
### Automatic Request Isolation
175
+
176
+
Light mode includes automatic request isolation for HTTP servers (requires Node.js 22+). This ensures that context (tags, user data, breadcrumbs) set during a request doesn't leak to other concurrent requests.
177
+
178
+
No manual middleware or `--import` flag is required - just initialize Sentry before creating your server:
179
+
180
+
```js
181
+
import*asSentryfrom'@sentry/node-core/light';
182
+
importexpressfrom'express';
183
+
184
+
// Initialize FIRST
185
+
Sentry.init({ dsn:'__DSN__' });
186
+
187
+
// Then create server
188
+
constapp=express();
189
+
190
+
app.get('/error', (req, res) => {
191
+
// This data is automatically isolated per request
192
+
Sentry.setTag('userId', req.params.id);
193
+
Sentry.captureException(newError('Something went wrong'));
194
+
res.status(500).send('Error');
195
+
});
196
+
```
197
+
198
+
### Manual Request Isolation (Node.js < 22)
199
+
200
+
If you're using Node.js versions below 22, automatic request isolation is not available. You'll need to manually wrap your request handlers with `withIsolationScope`:
201
+
202
+
```js
203
+
import*asSentryfrom'@sentry/node-core/light';
204
+
importexpressfrom'express';
205
+
206
+
Sentry.init({ dsn:'__DSN__' });
207
+
208
+
constapp=express();
209
+
210
+
// Add middleware to manually isolate requests
211
+
app.use((req, res, next) => {
212
+
Sentry.withIsolationScope(() => {
213
+
next();
214
+
});
215
+
});
216
+
217
+
app.get('/error', (req, res) => {
218
+
Sentry.setTag('userId', req.params.id);
219
+
Sentry.captureException(newError('Something went wrong'));
220
+
res.status(500).send('Error');
221
+
});
222
+
```
223
+
224
+
**Caveats:**
225
+
- Manual isolation prevents scope data leakage between requests
226
+
- However, **distributed tracing will not work correctly** - incoming `sentry-trace` and `baggage` headers won't be automatically extracted and propagated
227
+
- For full distributed tracing support, use Node.js 22+ or the full `@sentry/node` SDK with OpenTelemetry
0 commit comments