NestJS + Sentry - 源映射未正确映射

问题描述 投票:0回答:1

我需要将 NestJs-origin 源映射集成到 Sentry 中。我浏览了官方故障排除指南以及 Github Sentry 存储库上的几乎每个问题,但我仍然无法正确连接源映射,以便 Sentry 能够在问题视图中正确显示原始源代码。这是 Sentry 问题代码部分:

这也是事件 JSON 负载中的堆栈帧之一(未附加任何源映射):

{
  "function": "HealthCheckController.errorCheck1",
  "module": "health-check.controller.ts",
  "filename": "app:///dist/http-app/health-check.controller.ts",
  "abs_path": "app:///dist/http-app/health-check.controller.ts",
  "lineno": 16,
  "colno": 11,
  "in_app": true
}

Sentry SDK版本:7.54.0

Sentry CLI 版本:2.18.1

对于构建,我使用

tsc
和以下配置:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2020",
    "sourceMap": true, // as suggested in official docs
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": true,
    "noImplicitAny": true,
    "strictBindCallApply": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "inlineSources": true, // as suggested in official docs
    "sourceRoot": "/" // as suggested in official docs
  }
}

在寻找解决方案时,我还应用了

RewriteFrames
Sentry 集成来手动将文件映射到正确的源映射,这是它的当前配置:

new RewriteFrames({
        iteratee: (frame) => {
          if (!frame.filename) return frame;
          const filename = path.basename(frame.filename);
          const fileDir = path.dirname(frame.filename);
          const relativePath = path
            .relative(process.cwd(), fileDir)
            .replace(/^src\//g, 'dist/');
          frame.filename = `app:///${relativePath}/${filename}`;
          return frame;
        },
})

在 CI 管道中,构建最终映像时,使用以下代码片段创建发布、注入调试 id 并将源映射上传到 Sentry(

SENTRY_ORG
SENTRY_PROJECT
SENTRY_AUTH_TOKEN
envs 已正确设置) :

sentry-cli releases new "$SENTRY_RELEASE"
sentry-cli releases set-commits --ignore-missing --auto "$SENTRY_RELEASE"
sentry-cli sourcemaps inject dist/
sentry-cli sourcemaps upload --release="$SENTRY_RELEASE" ./dist --url-prefix '~/dist' 
sentry-cli releases finalize "$SENTRY_RELEASE"

源映射已上传并与正确的版本关联(如果更深入,我确认该问题也与正确的版本相关),并且所有内容都在仪表板中可见。

请让我知道我做错了什么或问题可能出在哪里。

node.js nestjs sentry source-maps tsc
1个回答
0
投票

您需要禁用自动映射,为此请在以下位置添加

--no-sourcemap-reference

sentry-cli sourcemaps upload --release="$SENTRY_RELEASE" ./dist --url-prefix '~/dist' --no-sourcemap-reference
© www.soinside.com 2019 - 2024. All rights reserved.