Astro

Astro is a web framework for building content-driven websites including blogs, marketing, and e-commerce sites. Learn how to set it up with Sentry.

We've released v8 of the JavaScript SDKs. If you're using version 7.x, we recommend upgrading to the latest version. Check out the Migration docs to learn how to make the switch.

Don't have a Sentry account? Sign up for Sentry for free, then return to this page.

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

Install 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.

Get started by adding your DSN to your Astro config file (astro.config.mjs):

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.

To get readable stack traces in your production builds, set the SENTRY_AUTH_TOKEN environment variable in your build environment. You can also add the environment variable to a .env.sentry-build-plugin file in the root of your project.

.env.sentry-build-plugin
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.

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>

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 project. 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!) or suggesting an update ("yeah, this would be better").