Move Sentry initialization

- makes sense to have it in sentry.ts and called from root layout.ts
This commit is contained in:
Mattias Granlund 2024-01-23 14:57:15 +01:00
parent 3915ff2530
commit 14cafcdc1e
3 changed files with 16 additions and 11 deletions

View File

@ -1,14 +1,5 @@
import { handleErrorWithSentry, init } from '@sentry/sveltekit';
import { handleErrorWithSentry } from '@sentry/sveltekit';
import type { NavigationEvent } from '@sveltejs/kit';
import { dev } from '$app/environment';
import { PUBLIC_SENTRY_ENVIRONMENT } from '$env/static/public';
init({
enabled: !dev,
dsn: 'https://a35bbd6688a3a8f76e4956c6871f414a@o4504644069687296.ingest.sentry.io/4505976067129344',
environment: PUBLIC_SENTRY_ENVIRONMENT,
tracesSampleRate: 1.0
});
function myErrorHandler({ error, event }: { error: any; event: NavigationEvent }) {
console.error('An error occurred on the client side:', error, event);

View File

@ -1,5 +1,17 @@
import { startSpan, setUser, type Span } from '@sentry/sveltekit';
import { startSpan, setUser, type Span, init } from '@sentry/sveltekit';
import type { User } from '../backend/cloud';
import { dev } from '$app/environment';
import { PUBLIC_SENTRY_ENVIRONMENT } from '$env/static/public';
export function initSentry() {
init({
enabled: !dev,
dsn: 'https://a35bbd6688a3a8f76e4956c6871f414a@o4504644069687296.ingest.sentry.io/4505976067129344',
environment: PUBLIC_SENTRY_ENVIRONMENT,
tracesSampleRate: 1.0
});
}
export function setSentryUser(user: User) {
setUser({

View File

@ -6,6 +6,7 @@ import { UpdaterService } from '$lib/backend/updater';
import { UserService } from '$lib/stores/user';
import { config } from 'rxjs';
import { initPostHog } from '$lib/analytics/posthog';
import { initSentry } from '$lib/analytics/sentry';
// call on startup so we don't accumulate old items
lscache.flushExpired();
@ -20,6 +21,7 @@ export const csr = true;
let homeDir: () => Promise<string>;
export const load: LayoutLoad = async ({ fetch: realFetch }: { fetch: typeof fetch }) => {
initSentry();
initPostHog();
const userService = new UserService();
const updaterService = new UpdaterService();