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