---
title: "Source Maps"
description: "Upload your source maps to Sentry to enable readable stack traces in your errors."
url: https://docs.sentry.io/platforms/javascript/guides/astro/sourcemaps/
---

# Source Maps | Sentry for Astro

The Sentry Astro SDK will generate and upload source maps automatically during a production build, so that errors in Sentry contain readable stack traces.

The Astro SDK uses the [Sentry Vite Plugin](https://www.npmjs.com/package/@sentry/vite-plugin/) to upload source maps. See the [Manual Configuration](https://docs.sentry.io/platforms/javascript/guides/astro/manual-setup.md#configure-source-maps-upload) page and the Sentry [Vite plugin documentation](https://www.npmjs.com/package/@sentry/vite-plugin/#configuration) for more details.

## [Configure Source Maps Upload](https://docs.sentry.io/platforms/javascript/guides/astro/sourcemaps.md#configure-source-maps-upload)

Source maps upload should work if you followed the [Astro CLI installation guide](https://docs.sentry.io/platforms/javascript/guides/astro.md#add-readable-stack-traces-to-errors). However, there are some options to configure source maps upload for your production builds for other configurations.

### [Enable Source Maps Upload](https://docs.sentry.io/platforms/javascript/guides/astro/sourcemaps.md#enable-source-maps-upload)

To automatically upload source maps during production builds, add the `SENTRY_AUTH_TOKEN` environment variable to your environment, for example in a `.env.sentry-build-plugin` file or in your CI setup.

`.env.sentry-build-plugin`

```bash
SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___
```

Using environment variables in Vite configs

Vite doesn't automatically load `.env` files into `process.env` when evaluating the config file. If you store your auth token in a `.env` file and want to access it via `process.env.SENTRY_AUTH_TOKEN`, use Vite's [`loadEnv`](https://vite.dev/guide/api-javascript#loadenv) helper:

`vite.config.js`

```javascript
import { defineConfig, loadEnv } from "vite";

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), "");

  return {
    plugins: [
      sentryVitePlugin({
        authToken: env.SENTRY_AUTH_TOKEN,
        // ...
      }),
    ],
  };
});
```

Alternatively, use a `.env.sentry-build-plugin` file, which the Sentry plugin reads automatically.

Next, add your project slug to the `sentry` integration options in your Astro config:

`astro.config.mjs`

```javascript
export default defineConfig({
  integrations: [
    sentry({
      // Other Sentry build-time options
      org: "___ORG_SLUG___",
      project: "___PROJECT_SLUG___",
      authToken: process.env.SENTRY_AUTH_TOKEN,
    }),
  ],
});
```

### [Disable Source Maps Upload](https://docs.sentry.io/platforms/javascript/guides/astro/sourcemaps.md#disable-source-maps-upload)

You can disable automatic source maps upload in your Astro configuration with `disable: true` under `sourcemaps` in the `sentry` integration options.

### [Setting the Source Maps Assets Directory](https://docs.sentry.io/platforms/javascript/guides/astro/sourcemaps.md#setting-the-source-maps-assets-directory)

By default, the Sentry Astro integration will look for source maps in sensible default directories, depending on your `outDir`, `rootDir` and `adapter` configuration. If these defaults don't work for you (for example, due to an advanced customized build setup or an unsupported adapter), you can specify the `assets` option to point to the folder(s) where your source maps are located:

`astro.config.mjs`

```javascript
export default defineConfig({
  integrations: [
    sentry({
      sourcemaps: {
        assets: [".clientOut/**/*", ".serverOut/**/*"],
      },
    }),
  ],
});
```

The specified patterns must follow the [glob syntax](https://www.npmjs.com/package/glob#glob-primer).

### [Working With Old Authentication Tokens](https://docs.sentry.io/platforms/javascript/guides/astro/sourcemaps.md#working-with-old-authentication-tokens)

Source maps work best with [organization-scoped auth tokens](https://docs.sentry.io/account/auth-tokens.md#organization-tokens). If you are using an old self-hosted Sentry version that doesn't yet support org-based tokens or you're using a different type of Sentry auth token, refer to our [legacy upload methods](https://docs.sentry.io/platforms/javascript/guides/astro/sourcemaps/troubleshooting_js.md#working-with-old-authentication-tokens) for more information.

### [Disabling Telemetry Data Collection](https://docs.sentry.io/platforms/javascript/guides/astro/sourcemaps.md#disabling-telemetry-data-collection)

The Astro SDK uses the Sentry Vite plugin to upload source maps. This plugin collects telemetry data to help us improve the source map uploading experience. Read more about this in our [Vite plugin documentation](https://www.npmjs.com/package/@sentry/vite-plugin#telemetry). You can disable telemetry collection by setting `telemetry: false` in the `sentry` integration options.

## [Additional Resources](https://docs.sentry.io/platforms/javascript/guides/astro/sourcemaps.md#additional-resources)

* [Using sentry-cli to Upload Source Maps](https://docs.sentry.io/cli/releases.md#sentry-cli-sourcemaps)
* [4 Reasons Why Your Source Maps Are Broken](https://blog.sentry.io/2018/10/18/4-reasons-why-your-source-maps-are-broken)

## Pages in this section

- [Troubleshooting Source Maps](https://docs.sentry.io/platforms/javascript/guides/astro/sourcemaps/troubleshooting_js.md)
