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