I have a Sentry integration with SvelteKit hooks.server.js
.
Errors are correctly logged in Sentry, but HTTP request metadata like user agent, request URL, IP addresses and such are missing, as seen in the issue screenshot below. These are quite important to troubleshoot many issues.
I am using the following hooks.server.js
integration code (based on Sentry's example):
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 SDK maintainer here!
Your setup looks correct but Http request data extraction was missing in the SvelteKit SDK.We added the feature recently to the sentryHandle
request handler. Once version 8.6.0 is released, you should be getting http request data like url, method and headers.