Astro
Sentry's Astro SDK enables automatic reporting of errors and performance data.
The Astro SDK is in Alpha and may undergo breaking changes. Please report any issues you encounter in our Github Repository.
Compatibility
The minimum supported Astro version is 3.0.0
.
This SDK currently only works on Node runtimes.
Non-Node runtimes, like Vercel's Edge runtime or Cloudflare Pages, are currently not supported.
On this page, we get you up and running with Sentry's SDK.
Don't already have an account and Sentry
Install
Sentry captures data by using an SDK within your application’s runtime.
We recommend installing the SDK by using the astro
CLI:
npx astro add @sentry/astro
The astro
CLI installs the SDK package and adds the Sentry integration to your astro.config.mjs
file.
To finish the setup, configure the Sentry integration.
Configure
Get started by adding your
astro.config.mjs
import { defineConfig } from "astro/config";
import sentry from "@sentry/astro";
export default defineConfig({
integrations: [
sentry({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
sourceMapsUploadOptions: {
project: "example-project",
authToken: process.env.SENTRY_AUTH_TOKEN,
},
}),
],
});
Once you've added your dsn
, the SDK will automatically capture and send errors and performance events to Sentry.
Add Readable Stack Traces to Errors
To get readable stack traces in your production builds, add the SENTRY_AUTH_TOKEN
environment variable to your environment, like in a .env
file or in your CI setup.
.env
SENTRY_AUTH_TOKEN=sntrys_YOUR_TOKEN_HERE
This, in combination with your sourceMapsUploadOptions
configuration, will upload source maps to Sentry every time you make a production build.
Verify
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.
Trigger a test error somewhere in your Astro app, for example in one of your pages:
home.astro
<button onclick="throw new Error('This is a test error')">
Throw test error
</button>
Errors triggered from within Browser DevTools are sandboxed and won't trigger an error handler. Place the snippet directly in your code instead.
Learn more about manually capturing an error or message in our Usage documentation.
To view and resolve the recorded error, log into sentry.io and open your
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").
- Package:
- npm:@sentry/astro
- Version:
- 7.74.1
- Repository:
- https://github.com/getsentry/sentry-javascript