sentry上传sourcemap


第一种方式:webpack 配置

参考文档:https://docs.sentry.io/platforms/javascript/sourcemaps/

  1. 安装 @sentry/webpack-plugin 和 clean-webpack-plugin
yarn add @sentry/webpack-plugin clean-webpack-plugin -D
  1. 获取 authToken(两种获取方式)
  • Organization Settings -> Developer Settings -> New Internal Integration -> Save Changes

note: PERMISSIONS 列表中需要选中 Releases -> Admin

  • API keys -> Auth Tokens -> Create New Token
  1. 在 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. 配置和认证

(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
  1. 创建新版本
sentry-cli releases -o example-org -p example-project new <release_name>

note: release_name 需要在 example-org 内唯一,且与 Sentry.init 中的 release 选项保持一致

  1. 上传 sourcemap
sentry-cli releases -o example-org -p example-project files <release_name> upload-sourcemaps /path/to/files --url-prefix example-url


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM