Sentry CLI
Interact with Sentry.io for error monitoring, release management, and debug artifact uploads.
Installation
CODEBLOCK0
Authentication
CODEBLOCK1
Store tokens in .sentryclirc or environment:
CODEBLOCK2
Releases
Create & Finalize
CODEBLOCK3
Deploys
CODEBLOCK4
List Releases
CODEBLOCK5
Source Maps
Upload source maps for JavaScript error deobfuscation:
CODEBLOCK6
Inject Debug IDs (Recommended)
CODEBLOCK7
Debug Files (iOS/Android)
dSYMs (iOS)
CODEBLOCK8
ProGuard (Android)
CODEBLOCK9
Check Debug Files
CODEBLOCK10
Events & Issues
Send Test Event
CODEBLOCK11
Query Issues
CODEBLOCK12
Monitors (Cron)
CODEBLOCK13
CI/CD Integration
GitHub Actions
CODEBLOCK14
Generic CI
CODEBLOCK15
Common Flags
| Flag | Description |
|---|
| INLINECODE1 | Organization slug |
| INLINECODE2 |
Project slug |
|
--auth-token | Override auth token |
|
--log-level | debug/info/warn/error |
|
--quiet | Suppress output |
Troubleshooting
CODEBLOCK16
Sentry CLI
与Sentry.io交互,用于错误监控、发布管理和调试产物上传。
安装
bash
macOS
brew install sentry-cli
npm(跨平台)
npm install -g @sentry/cli
直接下载
curl -sL https://sentry.io/get-cli/ | bash
认证
bash
交互式登录(打开浏览器)
sentry-cli login
或直接设置令牌
export SENTRY
AUTHTOKEN=sntrys_...
验证
sentry-cli info
将令牌存储在 .sentryclirc 或环境变量中:
ini
[auth]
token=sntrys_...
[defaults]
org=my-org
project=my-project
发布
创建与完成
bash
创建发布(通常使用Git SHA或版本号)
sentry-cli releases new $VERSION
关联提交(将错误链接到提交)
sentry-cli releases set-commits $VERSION --auto
部署后完成
sentry-cli releases finalize $VERSION
CI中的单行命令
sentry-cli releases new $VERSION --finalize
部署
bash
标记发布已部署到某个环境
sentry-cli releases deploys $VERSION new -e production
sentry-cli releases deploys $VERSION new -e staging
列出发布
bash
sentry-cli releases list
sentry-cli releases info $VERSION
源码映射
上传源码映射以还原混淆的JavaScript错误:
bash
上传所有 .js 和 .map 文件
sentry-cli sourcemaps upload ./dist --release=$VERSION
带URL前缀(匹配你的部署路径)
sentry-cli sourcemaps upload ./dist \
--release=$VERSION \
--url-prefix=~/static/js
上传前验证
sentry-cli sourcemaps explain ./dist/main.js.map
注入调试ID(推荐)
bash
将调试ID注入源文件(现代方法)
sentry-cli sourcemaps inject ./dist
sentry-cli sourcemaps upload ./dist --release=$VERSION
调试文件(iOS/Android)
dSYM(iOS)
bash
从Xcode归档上传dSYM
sentry-cli debug-files upload --include-sources path/to/dSYMs
从派生数据上传
sentry-cli debug-files upload ~/Library/Developer/Xcode/DerivedData/
/Build/Products//*.app.dSYM
ProGuard(Android)
bash
sentry-cli upload-proguard mapping.txt --uuid=$UUID
检查调试文件
bash
sentry-cli debug-files check path/to/file
sentry-cli debug-files list
事件与问题
发送测试事件
bash
sentry-cli send-event -m 测试错误消息
sentry-cli send-event -m 错误 --logfile /var/log/app.log
查询问题
bash
列出未解决的问题
sentry-cli issues list
解决一个问题
sentry-cli issues resolve ISSUE_ID
静默/忽略
sentry-cli issues mute ISSUE_ID
监控(定时任务)
bash
包装一个定时任务
sentry-cli monitors run my-cron-monitor -- /path/to/script.sh
手动签到
sentry-cli monitors check-in my-monitor --status ok
sentry-cli monitors check-in my-monitor --status error
CI/CD集成
GitHub Actions
yaml
uses: getsentry/action-release@v1
env:
SENTRY
AUTHTOKEN: ${{ secrets.SENTRY
AUTHTOKEN }}
SENTRY_ORG: my-org
SENTRY_PROJECT: my-project
with:
environment: production
sourcemaps: ./dist
通用CI
bash
export SENTRYAUTHTOKEN=$SENTRY_TOKEN
export SENTRY_ORG=my-org
export SENTRY_PROJECT=my-project
VERSION=$(sentry-cli releases propose-version)
sentry-cli releases new $VERSION --finalize
sentry-cli releases set-commits $VERSION --auto
sentry-cli sourcemaps upload ./dist --release=$VERSION
sentry-cli releases deploys $VERSION new -e production
常用标志
| 标志 | 描述 |
|---|
| -o, --org | 组织标识符 |
| -p, --project |
项目标识符 |
| --auth-token | 覆盖认证令牌 |
| --log-level | debug/info/warn/error |
| --quiet | 抑制输出 |
故障排除
bash
检查配置
sentry-cli info
调试上传问题
sentry-cli --log-level=debug sourcemaps upload ./dist
验证源码映射
sentry-cli sourcemaps explain ./dist/main.js.map
检查连接
sentry-cli send-event -m test --log-level=debug