Aller au contenu

Monitor your Astro Site with Sentry

Ce contenu n’est pas encore disponible dans votre langue.

As Astro’s Official Monitoring Partner, Sentry offers a comprehensive application monitoring and error tracking service designed to help developers identify, diagnose, and resolve issues in real-time.

Sentry’s Astro SDK enables automatic reporting of errors and tracing data in your Astro application.

A full list of prerequisites can be found in the Sentry guide for Astro.

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

Install the SDK by running the following command for the package manager of your choice in the Astro CLI:

Terminal window
npx astro add @sentry/astro

The astro CLI installs the SDK package and adds the Sentry integration to your astro.config.mjs file.

  1. Configure Get started by adding your DSN to your astro.config.mjs:

    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 the following <button> element to one of your .astro pages. This will allow you to manually trigger an error so you can test the error reporting process.

src/pages/home.astro
<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 project.