我有 Sentry 与 SvelteKit 集成
hooks.server.js
。
错误已正确记录在 Sentry 中,但缺少用户代理、请求 URL、IP 地址等 HTTP 请求元数据,如下面的问题屏幕截图所示。这些对于解决许多问题非常重要。
我正在使用以下
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;
您好,您可以尝试更新您的 init 以包含
sendDefaultPII
吗?
import * as Sentry from "@sentry/sveltekit";
Sentry.init({
dsn: YOUR_DSN,
integrations: [Sentry.httpClientIntegration()]
....
sendDefaultPii: true,
});
请参阅文档此处