sentry上传sourcemap
第一种方式:webpack 配置
参考文档:https://docs.sentry.io/platforms/javascript/sourcemaps/
- 安装 @sentry/webpack-plugin 和 clean-webpack-plugin
yarn add @sentry/webpack-plugin clean-webpack-plugin -D
- 获取 authToken(两种获取方式)
- Organization Settings -> Developer Settings -> New Internal Integration -> Save Changes
note: PERMISSIONS 列表中需要选中 Releases -> Admin
- API keys -> Auth Tokens -> Create New Token
- 在 webpack.config.js 中添加以下代码:
const SentryWebpackPlugin = require("@sentry/webpack-plugin");
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
// other configuration
plugins: [
// 多次构建后会因文件过多无法上传,先清理一下
new CleanWebpackPlugin(),
new SentryWebpackPlugin({
// 自托管 sentry 地址
url: "",
authToken: "",
org: "example-org",
project: "example-project",
// 本地 sourcemap 所在目录
include: "",
// js 访问路径
urlPrefix: ""
}),
],
};
第二种方式:sentry-cli
参考文档:https://docs.sentry.io/product/cli/configuration/
https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/
- 配置和认证
(1)获取 authToken,至少具有以下范围:
- project:read
- project:releases
- org:read
(2)配置(四种方式)
- 创建 .sentryclirc
[defaults]
url = https://mysentry.invalid/
[auth]
token=your-auth-token
- 导出为环境变量
// .env
export SENTRY_URL=https://mysentry.invalid/
export SENTRY_AUTH_TOKEN=your-auth-token
- 使用 Properties
// .env
export SENTRY_PROPERTIES=./sentry.properties
// sentry.properties
defaults.url=https://mysentry.invalid/
auth.token=your-auth-token
- 作为命令行参数
sentry-cli --url https://mysentry.invalid/ --auth-token your-auth-token
- 创建新版本
sentry-cli releases -o example-org -p example-project new <release_name>
note: release_name 需要在 example-org 内唯一,且与 Sentry.init 中的 release 选项保持一致
- 上传 sourcemap
sentry-cli releases -o example-org -p example-project files <release_name> upload-sourcemaps /path/to/files --url-prefix example-url