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.0.0-alpha.5
This is the fifth alpha release of Sentry JavaScript SDK v8, which includes a variety of breaking changes.
Read the in-depth migration guide to find out how to address any breaking changes in your code.
Important Changes
- feat(nextjs): Remove
client.(server|client).config.ts
functionality in favor of instrumentation.ts
(#11059)
- feat(nextjs): Bump minimum required Next.js version to
13.2.0
(#11097)
With version 8 of the SDK we will no longer support the use of sentry.server.config.ts
and sentry.edge.config.ts
files. Instead, please initialize the Sentry Next.js SDK for the serverside in a
Next.js instrumentation hook.
sentry.client.config.ts|js
is still supported and encouraged for initializing the clientside SDK. Please see the
Migration Guide for more details.
In addition, the Next.js SDK now requires a minimum Next.js version of 13.2.0
.
- feat(v8/angular): Merge angular and angular-ivy packages and start Angular support at v14 (#11091)
The @sentry/angular-ivy
package has been removed. The @sentry/angular
package now supports Ivy by default and
requires at least Angular 14. See the Migration Guide for more
details.
Removal/Refactoring of deprecated functionality
- feat(aws-serverless): Remove deprecated
rethrowAfterCapture
option (#11126) - feat(node): Remove deprecated/duplicate/unused definitions (#11120)
- feat(v8): Remove deprecated integration methods on client (#11134)
- feat(v8/browser): Remove class export for linked errors (#11129)
- feat(v8/browser): Remove deprecated wrap export (#11127)
- feat(v8/core): Remove deprecated client.setupIntegrations method (#11179)
- feat(v8/core): Remove deprecated integration classes (#11132)
- feat(v8/ember): Remove InitSentryForEmber export (#11202)
- feat(v8/nextjs): Remove usage of class integrations (#11182)
- feat(v8/replay): Delete deprecated types (#11177)
- feat(v8/utils): Remove deprecated util functions (#11143)
- ref(node): Remove class based export for local variable integration (#11128)
Other Changes
- feat(browser): Make fetch the default transport for offline (#11209)
- feat(core): Filter out noisy GoogleTag error by default (#11208)
- feat(deps): Bump @sentry/cli from 2.30.0 to 2.30.2 (#11168)
- feat(nextjs): Prefix webpack plugin log messages with runtime (#11173)
- feat(node-profiling): Output ESM and remove Sentry deps from output (#11135)
- feat(node): Allow Anr worker to be stopped and restarted (#11214)
- feat(node): Support
tunnel
option for ANR (#11163) - feat(opentelemetry): Do not capture exceptions for timed events (#11221)
- feat(serverless): Add Node.js 20 to compatible runtimes (#11103)
- feat(sveltekit): Switch to Otel-based
@sentry/node
package (#11075) - fix(attachments): Add missing
view_hierarchy
attachment type (#11197) - fix(build): Ensure tree shaking works properly for ESM output (#11122)
- fix(feedback): Only allow screenshots in secure contexts (#11188)
- fix(feedback): Reduce force layout in screenshots (#11181)
- fix(feedback): Smoother cropping experience and better UI (#11165)
- fix(feedback): Fix screenshot black bars in Safari (#11233)
- fix(metrics): use correct statsd data category (#11184)
- fix(metrics): use web-vitals ttfb calculation (#11185)
- fix(node): Export
initOpenTelemetry
(#11158) - fix(node): Clear ANR timer on stop (#11229)
- fix(node): Time zone handling for
cron
(#11225) - fix(node): Use unique variable for ANR context transfer (#11161)
- fix(opentelemetry): Do not stomp span error status (#11169)
- fix(types): Fix incorrect
sampled
type on Transaction
(#11115)