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
Auto instrumentation only works for Astro 3.5.2 or newer. If you're using an older version, you need to [manually add the Sentry middleware](#manually-add-server-instrumentation) instead.
198
+
199
+
</Alert>
200
+
201
+
In SSR or hybrid mode configured Astro apps, the Sentry Astro integration will automatically add an [Astro middleware](https://docs.astro.build/en/guides/middleware/) request handler to your server code. This middleware enhances the data collected by Sentry on the server side by:
202
+
203
+
- Collecting performance spans for incoming requests
204
+
- Enabeling distributed tracing between client and server
205
+
- Enhancing captured errors with additional information
206
+
207
+
### Manually Add Server Instrumentation
208
+
209
+
For Astro versions below 3.5.2, you need to manually add the Sentry middleware to your `src/middleware.js` file:
210
+
211
+
```javascript {filename:src/middleware.(js|ts)}
212
+
import*asSentryfrom"@sentry/astro";
213
+
import { sequence } from"astro:middleware";
214
+
215
+
exportconstonRequest=sequence(
216
+
Sentry.handleRequest()
217
+
// other middleware handlers
218
+
);
219
+
```
220
+
221
+
If you have multiple request handlers, make sure to add the Sentry middleware as the first handler in the sequence.
222
+
223
+
### Customize Server Instrumentation
224
+
225
+
Sentry's Astro middleware allows control over what additional data should be added to the recorded request spans.
226
+
227
+
To customize the server instrumentation, add the Sentry middleware to your `src/middleware.js` file:
228
+
229
+
```javascript {filename:src/middleware.(js|ts)}
230
+
import*asSentryfrom"@sentry/astro";
231
+
import { sequence } from"astro:middleware";
232
+
233
+
exportconstonRequest=sequence(
234
+
Sentry.handleRequest({
235
+
trackClientIp:true, // defaults to false
236
+
trackHeaders:true, // defaults to false
237
+
})
238
+
// other middleware handlers
239
+
);
240
+
```
241
+
242
+
If you're using Astro 3.5.2 or newer, make sure to also disable auto instrumentation as shown below.
243
+
244
+
### Disable Auto Server Instrumentation
245
+
246
+
For Astro 3.5.2 or newer, you can disable the automatic server instrumentation by turning off the `requestHandler` auto instrumentation option:
247
+
248
+
```javascript {filename:astro.config.mjs}
249
+
import { defineConfig } from"astro/config";
250
+
importsentryfrom"@sentry/astro";
251
+
252
+
exportdefaultdefineConfig({
253
+
integrations: [
254
+
sentry({
255
+
autoInstrumentation: {
256
+
requestHandler:false,
257
+
},
258
+
}),
259
+
],
260
+
output:"server",
261
+
});
262
+
```
263
+
193
264
## Configure Source Maps Upload
194
265
195
266
To enable readable stack traces, <PlatformLinkto="/sourcemaps">set up source maps upload</PlatformLink> for your production builds.
0 commit comments