---
title: Source Maps
description: >-
  Automatically upload JavaScript source maps to Datadog at build time to
  deobfuscate stack traces in Error Tracking and RUM.
breadcrumbs: >-
  Docs > RUM & Session Replay > Application Monitoring > RUM Browser Monitoring
  > Build Plugins > Source Maps
---

# Source Maps

## Overview{% #overview %}

The Source Maps build plugin automatically uploads JavaScript source maps to Datadog during your build, enabling deobfuscated stack traces in [Error Tracking](https://docs.datadoghq.com/real_user_monitoring/error_tracking.md) and [RUM](https://docs.datadoghq.com/real_user_monitoring.md). This replaces the need to manually run `datadog-ci sourcemaps upload` or configure CI/CD pipelines for source map uploads.

The plugin hooks into the build process, discovers all `.js` files with corresponding `.map` source map files from the build output, and uploads them to Datadog with git metadata.

## Prerequisites{% #prerequisites %}

- A Datadog API key, set with `auth.apiKey` or the `DATADOG_API_KEY` environment variable.
- Source maps enabled in your bundler configuration. The plugin uploads source maps but does not generate them. See [Upload JavaScript Source Maps](https://docs.datadoghq.com/real_user_monitoring/guide/upload-javascript-source-maps.md#instrument-your-code) for bundler-specific source map generation setup.
- The RUM SDK initialized with `service` and `version` parameters that match the plugin's `service` and `releaseVersion` configuration.
- The Datadog build plugin installed and registered with your bundler. See [Build Plugins](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/browser/build_plugins.md) for installation instructions.

## Configuration{% #configuration %}

Configure the `errorTracking.sourcemaps` object in your build plugin options:

| Parameter                                     | Type    | Required | Default | Description                                                                                                                               |
| --------------------------------------------- | ------- | -------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `errorTracking.sourcemaps.service`            | String  | Yes      | None    | Service name. Must match the RUM SDK `service` initialization parameter.                                                                  |
| `errorTracking.sourcemaps.releaseVersion`     | String  | Yes      | None    | Release version. Must match the RUM SDK `version` initialization parameter.                                                               |
| `errorTracking.sourcemaps.minifiedPathPrefix` | String  | Yes      | None    | URL or root-relative path prefix for your minified JavaScript files are served. For example, `https://example.com/static/` or `/static/`. |
| `errorTracking.sourcemaps.bailOnError`        | Boolean | No       | `false` | If `true`, the build fails when a source map upload error occurs.                                                                         |
| `errorTracking.sourcemaps.dryRun`             | Boolean | No       | `false` | If `true`, the plugin runs through the upload process without sending data to Datadog. Use this to verify your configuration.             |
| `errorTracking.sourcemaps.maxConcurrency`     | Number  | No       | `20`    | Maximum number of concurrent source map uploads.                                                                                          |

The following environment variables override configuration values:

- `DATADOG_SITE` or `DD_SITE`: Overrides `auth.site` for the intake URL.
- `DATADOG_SOURCEMAP_INTAKE_URL`: Overrides the full intake URL directly.

## Example{% #example %}

```javascript
const { datadogWebpackPlugin } = require('@datadog/webpack-plugin');

module.exports = {
  plugins: [
    datadogWebpackPlugin({
      auth: {
        apiKey: process.env.DATADOG_API_KEY,
        site: 'datadoghq.com', // Optional: defaults to datadoghq.com
      },
      errorTracking: {
        sourcemaps: {
          service: 'my-application',
          releaseVersion: '1.0.0',
          minifiedPathPrefix: 'https://example.com/static/',
        },
      },
    }),
  ],
};
```

{% alert level="info" %}
This example uses webpack. The configuration object is identical across all supported bundlers — only the import and plugin function name differ. See [Build Plugins](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/browser/build_plugins.md) for installation instructions for your bundler.
{% /alert %}

To also display inline source code in Error Tracking stack traces, pair source map uploads with the [Source Code Context](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/browser/build_plugins/source_code_context.md) plugin. Source maps provide the file mapping; source code context provides the service and version association.

## Further reading{% #further-reading %}

- [Upload JavaScript Source Maps (manual method)](https://docs.datadoghq.com/real_user_monitoring/guide/upload-javascript-source-maps.md)
- [Error Tracking](https://docs.datadoghq.com/real_user_monitoring/error_tracking.md)
- [Datadog Build Plugins GitHub Repository](https://github.com/DataDog/build-plugins)
