name: sentry-release-management description: 用于管理Sentry发布、上传source maps或跟踪部署。涵盖发布健康和提交关联。 allowed-tools:
- Read
- Write
- Edit
- Bash
- Grep
- Glob
Sentry - 发布管理
管理发布、上传source maps和跟踪部署。
创建发布
使用 sentry-cli
# 创建新发布
sentry-cli releases new "$VERSION"
# 关联提交
sentry-cli releases set-commits "$VERSION" --auto
# 最终化发布
sentry-cli releases finalize "$VERSION"
在 CI/CD 中
# GitHub Actions
- name: 创建 Sentry 发布
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: your-org
SENTRY_PROJECT: your-project
with:
environment: production
version: ${{ github.sha }}
GitLab CI
release:
stage: deploy
script:
- sentry-cli releases new "$CI_COMMIT_SHA"
- sentry-cli releases set-commits "$CI_COMMIT_SHA" --auto
- sentry-cli releases finalize "$CI_COMMIT_SHA"
- sentry-cli releases deploys "$CI_COMMIT_SHA" new -e production
Source Maps
上传 Source Maps
# 为发布上传 source maps
sentry-cli sourcemaps upload \
--release="$VERSION" \
--url-prefix="~/" \
./dist
# 带验证
sentry-cli sourcemaps upload \
--release="$VERSION" \
--validate \
./dist
Webpack 插件
// webpack.config.js
const { sentryWebpackPlugin } = require("@sentry/webpack-plugin");
module.exports = {
devtool: "source-map",
plugins: [
sentryWebpackPlugin({
org: "your-org",
project: "your-project",
authToken: process.env.SENTRY_AUTH_TOKEN,
release: {
name: process.env.RELEASE_VERSION,
},
sourcemaps: {
assets: "./dist/**",
},
}),
],
};
Vite 插件
// vite.config.ts
import { sentryVitePlugin } from "@sentry/vite-plugin";
export default defineConfig({
build: {
sourcemap: true,
},
plugins: [
sentryVitePlugin({
org: "your-org",
project: "your-project",
authToken: process.env.SENTRY_AUTH_TOKEN,
}),
],
});
Next.js
// next.config.js
const { withSentryConfig } = require("@sentry/nextjs");
module.exports = withSentryConfig(nextConfig, {
org: "your-org",
project: "your-project",
authToken: process.env.SENTRY_AUTH_TOKEN,
silent: true,
hideSourceMaps: true,
});
部署
# 创建部署
sentry-cli releases deploys "$VERSION" new \
--env production \
--started $(date +%s) \
--finished $(date +%s)
发布健康
在 SDK 中跟踪
Sentry.init({
dsn: "...",
release: "my-app@1.2.3",
environment: "production",
autoSessionTracking: true,
});
跟踪的指标
- 无崩溃会话: 无崩溃的会话百分比
- 无崩溃用户: 无崩溃的用户百分比
- 会话计数: 发布的会话总数
- 采用率: 用户采用率
配置文件
.sentryclirc
[defaults]
org = your-org
project = your-project
[auth]
token = your-auth-token
sentry.properties
defaults.org=your-org
defaults.project=your-project
auth.token=your-auth-token
最佳实践
- 使用语义版本控制进行发布
- 关联提交以使用嫌疑提交功能
- 在部署前上传 source maps
- 创建部署以跟踪发布运行位置
- 全面推广前监控发布健康
- 删除旧 source maps 以管理存储
- 使用 CI/CD 集成进行自动化发布
清理
# 删除旧发布
sentry-cli releases delete "$OLD_VERSION"
# 删除 source maps(保留发布)
sentry-cli releases files "$VERSION" delete --all