Source Context

Sentry can show you snippets of code around the crash, so you can quickly identify the problem.

Sentry can display snippets of your code next to the event stack traces. This feature is called source context.

There are three options for setting up source context:

If you add the --include-sources flag to the sentry-cli debug-files upload command, sentry-cli will scan your debug files to find references to the source code files, resolve them in the local file system, bundle them up, and upload them to Sentry.

You can manually create an Auth Token or sign in to create a token directly from this page.
The following code sample will let you choose your personal config from the dropdown, once you're logged in.
Copied
sentry-cli debug-files upload --auth-token sntrys_YOUR_TOKEN_HERE \
  --include-sources \
  --org example-org \
  --project example-project \
  PATH_TO_DSYMS

If you're already using Fastlane, you can use the Sentry Fastlane plugin to upload your source to Sentry by adding include_sources: true to the plugin call.

You can manually create an Auth Token or sign in to create a token directly from this page.
The following code sample will let you choose your personal config from the dropdown, once you're logged in.
Copied
sentry_debug_files_upload(
  auth_token: 'sntrys_YOUR_TOKEN_HERE',
  org_slug: 'example-org',
  project_slug: 'example-project',
  include_sources: true, # Optional. For source context.
)

You can upload your sources to Sentry after every build through Xcode. To do this, add the --include-sources flag to the sentry-cli debug-files upload command in the Upload Debug Symbols Xcode build phase script.

You can manually create an Auth Token or sign in to create a token directly from this page.
The following code sample will let you choose your personal config from the dropdown, once you're logged in.
Copied
if [[ "$(uname -m)" == arm64 ]]; then
    export PATH="/opt/homebrew/bin:$PATH"
fi

if which sentry-cli >/dev/null; then
export SENTRY_ORG=example-org
export SENTRY_PROJECT=example-project
export SENTRY_AUTH_TOKEN=sntrys_YOUR_TOKEN_HERE
ERROR=$(sentry-cli debug-files upload --include-sources "$DWARF_DSYM_FOLDER_PATH" 2>&1 >/dev/null)
if [ ! $? -eq 0 ]; then
echo "warning: sentry-cli - $ERROR"
fi
else
echo "warning: sentry-cli not installed, download from https://github.com/getsentry/sentry-cli/releases"
fi
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").