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.2.0
Important Changes
- feat(node): Support Express v5 (#15380)
This release adds full tracing support for Express v5, and improves tracing support for Nest.js 11 (which uses Express v5) in the Nest.js SDK.
- feat(sveltekit): Add Support for Cloudflare (#14672)
This release adds support for deploying SvelteKit applications to Cloudflare Pages.
A docs update with updated instructions will follow shortly.
Until then, you can give this a try by setting up the SvelteKit SDK as usual and then following the instructions outlined in the PR.
Thank you @SG60 for contributing this feature!
Other Changes
- feat(core): Add
addLink(s)
to Sentry span (#15452) - feat(core): Add links to span options (#15453)
- feat(deps): Bump @sentry/webpack-plugin from 2.22.7 to 3.1.2 (#15328)
- feat(feedback): Disable Feedback submit & cancel buttons while submitting (#15408)
- feat(nextjs): Add experimental flag to not strip origin information from different origin stack frames (#15418)
- feat(nuxt): Add
enableNitroErrorHandler
to server options (#15444) - feat(opentelemetry): Add
addLink(s)
to span (#15387) - feat(opentelemetry): Add
links
to span options (#15403) - feat(replay): Expose rrweb recordCrossOriginIframes under _experiments (#14916)
- fix(browser): Ensure that
performance.measure
spans have a positive duration (#15415) - fix(bun): Includes correct sdk metadata (#15459)
- fix(core): Add Google
gmo
error to Inbound Filters (#15432) - fix(core): Ensure
http.client
span descriptions don't contain query params or fragments (#15404) - fix(core): Filter out unactionable Facebook Mobile browser error (#15430)
- fix(nestjs): Pin dependency on
@opentelemetry/instrumentation
(#15419) - fix(nuxt): Only use filename with file extension from command (#15445)
- fix(nuxt): Use
SentryNuxtServerOptions
type for server init (#15441) - fix(sveltekit): Avoid loading vite config to determine source maps setting (#15440)
- ref(profiling-node): Bump chunk interval to 60s (#15361)
Work in this release was contributed by @6farer, @dgavranic and @SG60. Thank you for your contributions!