Astro

Sentry's Astro SDK enables automatic reporting of errors and performance data.

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

projectRepresents your service in Sentry and allows you to scope events to a distinct application.
established? Head over to sentry.io, then return to this page.

Install

Sentry captures data by using an SDK within your application’s runtime.

We recommend installing the SDK by using the astro CLI:

Copied
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

DSNThe Data Source Name (DSN) key tells the Sentry SDK where to send events, ensuring they go to the right project.
to your Astro config file:

astro.config.mjs
Copied
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
Copied
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
Copied
<button onclick="throw new Error('This is a test error')">
  Throw test error
</button>

To view and resolve the recorded error, log into sentry.io and open your

projectRepresents your service in Sentry and allows you to scope events to a distinct application.
. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.

Help improve this content
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").