From 14cafcdc1e2ecee9a6b3a018bde3b358e78f4405 Mon Sep 17 00:00:00 2001 From: Mattias Granlund Date: Tue, 23 Jan 2024 14:57:15 +0100 Subject: [PATCH] Move Sentry initialization - makes sense to have it in sentry.ts and called from root layout.ts --- gitbutler-ui/src/hooks.client.ts | 11 +---------- gitbutler-ui/src/lib/analytics/sentry.ts | 14 +++++++++++++- gitbutler-ui/src/routes/+layout.ts | 2 ++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/gitbutler-ui/src/hooks.client.ts b/gitbutler-ui/src/hooks.client.ts index cdebbc496..17791675a 100644 --- a/gitbutler-ui/src/hooks.client.ts +++ b/gitbutler-ui/src/hooks.client.ts @@ -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); diff --git a/gitbutler-ui/src/lib/analytics/sentry.ts b/gitbutler-ui/src/lib/analytics/sentry.ts index 4b2d24aa1..e6f7d97a6 100644 --- a/gitbutler-ui/src/lib/analytics/sentry.ts +++ b/gitbutler-ui/src/lib/analytics/sentry.ts @@ -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({ diff --git a/gitbutler-ui/src/routes/+layout.ts b/gitbutler-ui/src/routes/+layout.ts index dfd56bab0..541cb623b 100644 --- a/gitbutler-ui/src/routes/+layout.ts +++ b/gitbutler-ui/src/routes/+layout.ts @@ -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; export const load: LayoutLoad = async ({ fetch: realFetch }: { fetch: typeof fetch }) => { + initSentry(); initPostHog(); const userService = new UserService(); const updaterService = new UpdaterService();