Source Maps
Source maps allow Sentry to display readable stack traces instead of minified code. This is especially useful when you bundle or transpile your code.
Using the Sentry Wizard
The easiest way to set up source maps is using the Sentry wizard:
npx @sentry/wizard@latest -i sourcemapsThe wizard will:
- Guide you through authentication
- Detect your build setup
- Configure automatic source map uploads
For Specific Organizations
If you have multiple Sentry organizations, specify yours:
npx @sentry/wizard@latest -i sourcemaps --saas --org your-org --project your-projectManual Setup
If you prefer manual configuration or the wizard doesn't detect your setup:
1. Install the Sentry CLI
npm install @sentry/cli --save-dev2. Create a .sentryclirc file
[defaults]
org=your-org
project=your-project
[auth]
token=your-auth-tokenWARNING
Never commit your auth token. Use environment variables instead:
export SENTRY_AUTH_TOKEN=your-auth-token3. Add Upload Script
Add to your package.json:
{
"scripts": {
"sentry:sourcemaps": "sentry-cli sourcemaps inject ./dist && sentry-cli sourcemaps upload ./dist"
}
}4. Run After Build
npm run build && npm run sentry:sourcemapsCI/CD Integration
GitHub Actions
- name: Upload source maps to Sentry
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: your-org
SENTRY_PROJECT: your-project
run: |
npx @sentry/cli sourcemaps inject ./dist
npx @sentry/cli sourcemaps upload ./distEnvironment Variables
Set these in your CI environment:
| Variable | Description |
|---|---|
SENTRY_AUTH_TOKEN | Your Sentry auth token |
SENTRY_ORG | Your Sentry organization slug |
SENTRY_PROJECT | Your Sentry project slug |
SENTRY_RELEASE | (Optional) Release version |
Releases
Associate source maps with releases for better tracking:
# Create a release
sentry-cli releases new v1.0.0
# Upload source maps
sentry-cli releases files v1.0.0 upload-sourcemaps ./dist
# Finalize the release
sentry-cli releases finalize v1.0.0Then configure your app to use the same release:
// config/sentry.js
module.exports.sentry = {
dsn: process.env.SENTRY_DSN,
release: process.env.SENTRY_RELEASE || 'v1.0.0'
}Sails-Specific Notes
For most Sails applications that don't use a bundler, source maps may not be necessary since you're running the original source code directly on the server.
Source maps are most useful when you:
- Use TypeScript with Sails
- Bundle your backend code
- Use Babel or other transpilers
If you're running plain JavaScript without transpilation, Sentry will show your original source code in stack traces automatically.