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:
- Enabeling 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:
8.33.0
Important Changes
- feat(nextjs): Support new async APIs (
headers()
, params
, searchParams
)
(#13828)
Adds support for new dynamic Next.js APIs.
- feat(node): Add
lru-memoizer
instrumentation
(#13796)
Adds integration for lru-memoizer using @opentelemetry/instrumentation-lru-memoizer.
- feat(nuxt): Add
unstable_sentryBundlerPluginOptions
to module options
(#13811)
Allows passing other options from the bundler plugins (vite and rollup) to Nuxt module options.
Other Changes
- fix(browser): Ensure
wrap()
only returns functions
(#13838) - fix(core): Adapt trpc middleware input attachment
(#13831)
- fix(core): Don't return trace data in
getTraceData
and getTraceMetaTags
if SDK is disabled
(#13760) - fix(nuxt): Don't restrict source map assets upload
(#13800)
- fix(nuxt): Use absolute path for client config (#13798)
- fix(replay): Stop global event handling for paused replays
(#13815)
- fix(sveltekit): add url param to source map upload options
(#13812)
- fix(types): Add jsdocs to cron types (#13776)
- fix(nextjs): Loosen @sentry/nextjs webpack peer dependency
(#13826)
Work in this release was contributed by @joshuajaco. Thank you for your contribution!