Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions docs/cli/code-mappings.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: "Code Mappings"
sidebar_order: 5
description: "Upload code mappings to Sentry via the CLI. Code mappings link stack trace paths to source code paths in your repository, enabling source context, suspect commits, and code owners."
---

Code mappings link stack trace paths to source code paths in your repository. They enable features like [source context](/platforms/java/source-context/), [suspect commits](/product/issues/suspect-commits/), [stack trace linking](/organization/integrations/source-code-mgmt/github/#stack-trace-linking), and [code owners](/product/issues/ownership-rules/).
Comment on lines +6 to +7
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Code mappings link stack trace paths to source code paths in your repository. They enable features like [source context](/platforms/java/source-context/), [suspect commits](/product/issues/suspect-commits/), [stack trace linking](/organization/integrations/source-code-mgmt/github/#stack-trace-linking), and [code owners](/product/issues/ownership-rules/).
_Available in version 3.3.4 of Sentry CLI_
Code mappings link stack trace paths to source code paths in your repository. They enable features like [source context](/platforms/java/source-context/), [suspect commits](/product/issues/suspect-commits/), [stack trace linking](/organization/integrations/source-code-mgmt/github/#stack-trace-linking), and [code owners](/product/issues/ownership-rules/).

@szokeasaurusrex not sure if we should mention the min supported version here?


You can [manage code mappings through the Sentry web UI](/product/issues/suspect-commits/#set-up-code-mappings), or upload them in bulk using Sentry CLI. It is also possible to upload code mappings automatically in your CI process to keep them in sync with your repository structure.

## Permissions

Sentry CLI requires an [Organization Token](https://sentry.io/orgredirect/organizations/:orgslug/settings/auth-tokens/) with the `org:ci` scope to upload code mappings.

## Upload Code Mappings

Use the `sentry-cli code-mappings upload` command to upload code mappings:

```bash
sentry-cli code-mappings upload ./mappings.json
```

Run `sentry-cli code-mappings upload --help` to see all available options.

### JSON File Format
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a standardized way to generate such files? If so, I think we should mention it.

Copy link
Copy Markdown
Member Author

@romtsn romtsn Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, not really. I was thinking to add a sentry.io/changelog entry where I'd provide an example snippet on how to do this in Gradle, but I could also add it here if you prefer. Although, the next step would be to do this automatically in the Sentry Gradle plugin so this would make the snippet redundant.


The input file should be a JSON array of mapping objects, each with a `stackRoot` and `sourceRoot`:

- **stackRoot**: The path prefix as it appears in stack traces (e.g. `io/sentry/android/core` for Java, `src/` for Python/JS).
- **sourceRoot**: The corresponding path in your repository where the source code lives.

Multiple mappings can share the same `stackRoot` if they point to different `sourceRoot` paths. This is useful for monorepos where the same package prefix exists in multiple modules. Sentry evaluates mappings from most specific to least specific, using the first one that resolves to a real file in the repository.

#### Example

The following example is based on the [getsentry/sentry-java](https://github.com/getsentry/sentry-java) monorepo, which has multiple modules sharing the `io/sentry` package prefix:

```json {filename:mappings.json}
[
{
"stackRoot": "io/sentry/android/core",
"sourceRoot": "sentry-android-core/src/main/java/io/sentry/android/core"
},
{
"stackRoot": "io/sentry/opentelemetry",
"sourceRoot": "sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry"
},
{
"stackRoot": "io/sentry/opentelemetry",
"sourceRoot": "sentry-opentelemetry/sentry-opentelemetry-bootstrap/src/main/java/io/sentry/opentelemetry"
},
{
"stackRoot": "io/sentry",
"sourceRoot": "sentry/src/main/java/io/sentry"
}
]
```

2 changes: 1 addition & 1 deletion docs/cli/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ These docs cover `sentry-cli`, used in CI/CD pipelines and build processes. If y

</Alert>

For certain actions, you can use the `sentry-cli` command line executable. It can connect to the Sentry API and manage some data for your projects. It’s primarily used for managing debug information files for iOS, Android as well as release and source maps management for other platforms.
For certain actions, you can use the `sentry-cli` command line executable. It can connect to the Sentry API and manage some data for your projects. It’s primarily used for managing debug information files for iOS, Android, release and source maps management, as well as code mappings for other platforms.

<PageGrid />
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ By default, this feature is automatically enabled once your GitHub integration h

<Alert>

Sentry will automatically try to set up code mappings on JavaScript, Python, Java, PHP, Ruby, Go, C#, and Kotlin for organizations with the GitHub integration installed. If your project uses a different SDK, you can add code mappings manually.
Sentry will automatically try to set up code mappings on JavaScript, Python, Java, PHP, Ruby, Go, C#, and Kotlin for organizations with the GitHub integration installed. If your project uses a different SDK, you can add code mappings manually. You can also [upload code mappings in bulk via the CLI](/cli/code-mappings/).

</Alert>

Expand Down
2 changes: 1 addition & 1 deletion docs/platforms/java/common/source-context/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ og_image: /og-images/platforms-java-common-source-context.png

## Setting Up Code Mappings

To use suspect commits and stack trace linking, you'll need to set up a code mapping. This is a mapping between the source code in your repository and the source code in your stack traces. You can find information on how to set up code mappings in our [Set Up Code Mappings](/product/issues/suspect-commits/#2-set-up-code-mappings) docs.
To use suspect commits and stack trace linking, you'll need to set up a code mapping. This is a mapping between the source code in your repository and the source code in your stack traces. You can [set up code mappings manually in the Sentry UI](/product/issues/suspect-commits/#set-up-code-mappings) or [upload code mappings in bulk via Sentry CLI](/cli/code-mappings/). We recommend using the CLI if your project has many modules.

Use the following steps to determine the correct **Stack Trace Root** **Source Code Root** while setting up your code mapping:

Expand Down
2 changes: 2 additions & 0 deletions docs/product/issues/suspect-commits/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ In [sentry.io](https://sentry.io):

Sentry will automatically try to set up code mappings on JavaScript, Python, Java, PHP, Ruby, Go, C#, and Kotlin projects for organizations with the GitHub integration installed. However, you can still manually add code mappings if you choose to do so. Support for other languages and other source code integrations are planned.

You can also upload code mappings in bulk using the [Sentry CLI](/cli/code-mappings/).

</Alert>

1. Go to **Settings > Integrations > [Integration] > Configurations**.
Expand Down
Loading