-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
docs(cli): Add code mappings documentation page #17196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
6d06adb
df548ee
6dc17ed
486f541
c9a55ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| --- | ||
| 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/). | ||
|
|
||
| You can manage code mappings through the Sentry web UI (see [Setting Up Code Mappings](/product/issues/suspect-commits/#set-up-code-mappings)), or upload them in bulk using `sentry-cli`. | ||
|
romtsn marked this conversation as resolved.
Outdated
|
||
|
|
||
| ## Permissions | ||
|
|
||
| The `sentry-cli` requires an [Organization Token](https://sentry.io/orgredirect/organizations/:orgslug/settings/auth-tokens/) with the `org:ci` scope to upload code mappings. | ||
|
szokeasaurusrex marked this conversation as resolved.
Outdated
romtsn marked this conversation as resolved.
Outdated
|
||
|
|
||
| ## Upload Code Mappings | ||
|
|
||
| <Alert> | ||
|
|
||
| You need to specify the organization and project you are working with because code mappings work on projects. For more information about this refer to [Working with Projects](/cli/configuration/#sentry-cli-working-with-projects). | ||
|
|
||
| </Alert> | ||
|
romtsn marked this conversation as resolved.
Outdated
|
||
|
|
||
| ```bash | ||
| sentry-cli code-mappings upload ./mappings.json \ | ||
| --org my-org \ | ||
| --project my-project \ | ||
| --repo owner/repo \ | ||
| --default-branch main | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| | Option | Required | Description | | ||
| |--------|----------|-------------| | ||
| | `--org` | Required | The organization slug. Can also be set via `SENTRY_ORG` or in `.sentryclirc`. | | ||
| | `--project` | Required | The project slug. Can also be set via `SENTRY_PROJECT` or in `.sentryclirc`. | | ||
| | `--repo` | Optional | The repository name (e.g. `getsentry/sentry`). Defaults to the git remote origin. Required if not running from within a git repository. | | ||
| | `--default-branch` | Optional | The default branch name. Defaults to the git remote HEAD or `main`. Required if not running from within a git repository. | | ||
|
romtsn marked this conversation as resolved.
Outdated
|
||
|
|
||
| ### JSON File Format | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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`. | ||
|
|
||
| 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" | ||
| } | ||
| ] | ||
| ``` | ||
|
|
||
| - **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. In the example above, `io/sentry/opentelemetry` maps to two different modules. Sentry evaluates mappings from most specific to least specific, using the first one that resolves to a real file in the repository. | ||
|
romtsn marked this conversation as resolved.
Outdated
|
||
|
|
||
| ### Batching | ||
|
|
||
| Mappings are uploaded in batches of up to 300 per request. If your file contains more than 300 mappings, the CLI will automatically split them into multiple batches. | ||
|
romtsn marked this conversation as resolved.
Outdated
|
||
|
|
||
| ### Output | ||
|
|
||
| The CLI reports the result of each batch: | ||
|
|
||
| ``` | ||
| Uploading 47 code mapping(s)... | ||
| Created: 42, Updated: 5, Errors: 0 | ||
| ``` | ||
|
|
||
| - **Created**: New mappings that were added. | ||
| - **Updated**: Existing mappings (matched by project, stack root, and source root) whose metadata was updated. | ||
| - **Errors**: Mappings that failed to save. | ||
|
|
||
| If any errors occur, the CLI exits with a non-zero exit code and prints a table showing which mappings failed. | ||
|
romtsn marked this conversation as resolved.
Outdated
|
||
|
|
||
| ## Stack Trace Root and Source Code Root | ||
|
romtsn marked this conversation as resolved.
Outdated
|
||
|
|
||
| <Include name="common-imgs/code-mappings-stacktrace" /> | ||
|
|
||
| For platforms that use file paths in stack traces (Python, JavaScript, etc.), the `stackRoot` and `sourceRoot` are typically file path prefixes. For example, if your stack traces show `src/app/utils.py` and the file lives at `backend/src/app/utils.py` in your repo: | ||
|
|
||
| - `stackRoot`: `src/` | ||
| - `sourceRoot`: `backend/src/` | ||
|
|
||
| For Java and other JVM languages, stack traces use package names (e.g. `com.example.app.MyClass`), which are converted to paths (`com/example/app`). The `sourceRoot` is the path in the repository to the corresponding source directory. Read more in the [Java source context docs](/platforms/java/source-context/#setting-up-code-mappings). | ||
|
|
||
| ## CI/CD Integration | ||
|
|
||
| You can run `sentry-cli code-mappings upload` as part of your CI/CD pipeline to keep code mappings in sync with your repository structure: | ||
|
|
||
| ```bash | ||
| sentry-cli code-mappings upload ./mappings.json \ | ||
| --org $SENTRY_ORG \ | ||
| --project $SENTRY_PROJECT \ | ||
| --repo $GITHUB_REPOSITORY \ | ||
| --default-branch $GITHUB_REF_NAME | ||
| ``` | ||
|
|
||
| For authentication, set the `SENTRY_AUTH_TOKEN` environment variable. See [Configuration](/cli/configuration/) for details. | ||
|
romtsn marked this conversation as resolved.
Outdated
|
||
Uh oh!
There was an error while loading. Please reload this page.