Skip to content

Files

Latest commit

May 30, 2025
78cd42f · May 30, 2025

History

History
This branch is 4 commits behind develop.

astro

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Apr 28, 2025
May 28, 2025
Apr 28, 2025
Dec 13, 2024
Jan 23, 2025
Nov 4, 2024
May 30, 2025
Apr 3, 2024
Oct 13, 2023
Oct 6, 2023
Jul 30, 2024
Oct 6, 2023
Jul 30, 2024

Sentry

Official Sentry SDK for Astro

npm version npm dm npm dt

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:

// src/middleware.js
import { sequence } from 'astro:middleware';
import * as Sentry from '@sentry/astro';

export const onRequest = sequence(
  Sentry.handleRequest(),
  // Add your other handlers after Sentry.handleRequest()
);

The Sentry middleware enhances the data collected by Sentry on the server side by:

  • Enabling 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: