| 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. |
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, suspect commits, stack trace linking, and code owners.
You can manage code mappings through the Sentry web UI, 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.
Sentry CLI requires an Organization Token with the org:ci scope to upload code mappings.
Use the sentry-cli code-mappings upload command to upload code mappings:
sentry-cli code-mappings upload ./mappings.jsonRun sentry-cli code-mappings upload --help to see all available options.
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/corefor 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.
The following example is based on the getsentry/sentry-java monorepo, which has multiple modules sharing the io/sentry package prefix:
[
{
"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"
}
]