Official Sentry SDK for Astro

Links
SDK Status
This SDK is in Beta and not yet fully stable. If you have feedback or encounter any bugs, feel free to
open an issue.
General
This package is a wrapper around @sentry/node
for the server and @sentry/browser
for the client side.
Installation and Setup
Install the Sentry Astro SDK with the astro
CLI:
npx astro add @sentry/astro
Add your DSN and source maps upload configuration:
import { defineConfig } from 'astro/config';
import sentry from '@sentry/astro';
export default defineConfig({
integrations: [
sentry({
dsn: '__DSN__',
sourceMapsUploadOptions: {
project: 'your-sentry-project-slug',
authToken: process.env.SENTRY_AUTH_TOKEN,
},
}),
],
});
Follow this guide to create an auth
token and add it to your environment variables:
SENTRY_AUTH_TOKEN="your-token"
Server Instrumentation
For Astro apps configured for (hybrid) Server Side Rendering (SSR), the Sentry integration will automatically add
middleware to your server to instrument incoming requests if you're using Astro 3.5.2 or newer.
If you're using Astro <3.5.2, complete the setup by adding the Sentry middleware to your src/middleware.js
file:
import { sequence } from 'astro:middleware';
import * as Sentry from '@sentry/astro';
export const onRequest = sequence(
Sentry.handleRequest(),
);
The Sentry middleware enhances the data collected by Sentry on the server side by:
- Enabling distributed tracing between client and server
- Collecting performance spans for incoming requests
- Enhancing captured errors with additional information
Disable Automatic Server Instrumentation
You can opt out of using the automatic sentry server instrumentation in your astro.config.mjs
file:
import { defineConfig } from 'astro/config';
import sentry from '@sentry/astro';
export default defineConfig({
integrations: [
sentry({
dsn: '__DSN__',
autoInstrumentation: {
requestHandler: false,
},
}),
],
});
Configuration
Check out our docs for configuring your SDK setup:
9.3.0
Important Changes
With this release we're publishing two new SDKs in experimental alpha stage:
- feat(tanstackstart): Add TanStack Start SDK (#15523)
For details please refer to the README
- feat(react-router): Add React Router SDK (#15524)
For details please refer to the README
- feat(remix): Add support for Hydrogen (#15450)
This PR adds support for Shopify Hydrogen applications running on MiniOxygen runtime.
Other Changes
- feat(core): Add
forceTransaction
to trpc middleware options (#15519) - feat(core): Default filter unactionable error (#15527)
- feat(core): Rename
inboundFiltersIntegration
to eventFiltersIntegration
(#15434) - feat(deps): bump @prisma/instrumentation from 6.2.1 to 6.4.1 (#15480)
- feat(react-router): Add build-time config (#15406)
- feat(replay): Bump rrweb to 2.33.0 (#15514)
- fix(core): Fix
allowUrls
and denyUrls
for linked and aggregate exceptions (#15521) - fix(nextjs): Don't capture devmode server-action redirect errors (#15485)
- fix(nextjs): warn about missing onRequestError handler #15488)
- fix(nextjs): Prevent wrong culprit from showing up for clientside error events #15475)
- fix(nuxt): Ignore 300-400 status codes on app errors in Nuxt (#15473)
- fix(react): Add support for cross-usage of React Router instrumentations (#15283)
- fix(sveltekit): Guard
process
check when flushing events (#15516)
Work in this release was contributed by @GerryWilko and @leoambio. Thank you for your contributions!