Sentry 记录 SvelteKit 缺少 HTTP 服务器端元数据

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

我有 Sentry 与 SvelteKit 集成

hooks.server.js

错误已正确记录在 Sentry 中,但缺少用户代理、请求 URL、IP 地址等 HTTP 请求元数据,如下面的问题屏幕截图所示。这些对于解决许多问题非常重要。

enter image description here

我正在使用以下

hooks.server.js
集成代码(基于Sentry的示例):

import { sequence } from '@sveltejs/kit/hooks';
import * as Sentry from '@sentry/sveltekit';
import { dev } from '$app/environment';
import { env } from '$env/dynamic/private';

if(!dev) {
  Sentry.init({
    dsn: env.SENTRY_DSN,
    environment: dev ? "dev" : "production",
    // https://github.com/getsentry/sentry-javascript/issues/8925#issue-1876274074
    ignoreErrors: [
      "TypeError: Failed to fetch dynamically imported module",
      "Load failed",
      "TypeError: Load failed",
      "TypeError: Failed to fetch",
      "Failed to fetch",
      "TypeError: NetworkError when attempting to fetch resource",
      "TypeError: Importing a module script failed",
      "TypeError: error loading dynamically imported module",
      "RollupError: Expected unicode escape"
    ],  
  });
}

export const handleError = Sentry.handleErrorWithSentry((async ({ error }) => {  
    const eventId = Sentry.lastEventId();
    if (eventId) {
        return { message: 'Internal Server Error', eventId };
    }
}));


// prettier-ignore
let handle;

if(!dev) {
  handle = sequence(
    Sentry.sentryHandle(),
    # ... rest
  );  
} else {
  handle =   handle = sequence(
    # ... rest
  );  
}


export default handle;

  • Sentry 的 SvelteKit 集成未正确记录这些内容可能是什么原因?
sveltekit sentry
1个回答
0
投票

您好,您可以尝试更新您的 init 以包含

sendDefaultPII
吗?

import * as Sentry from "@sentry/sveltekit";

Sentry.init({
  dsn: YOUR_DSN,
  integrations: [Sentry.httpClientIntegration()]
  ....
  sendDefaultPii: true,
});

请参阅文档此处

© www.soinside.com 2019 - 2024. All rights reserved.