From 84b3d587100cf86481418e32a8f4b41492a0bd00 Mon Sep 17 00:00:00 2001 From: Gagan Suie Date: Sat, 4 May 2024 12:32:23 -0500 Subject: [PATCH] Feat: switched to Sentry again for testing --- package.json | 1 + src/hooks.client.ts | 37 ++++++++++++++++++++++--------------- src/hooks.server.ts | 22 +++++++++++++++++----- src/instrumentation.ts | 6 ------ vite.config.ts | 8 ++++++++ 5 files changed, 48 insertions(+), 26 deletions(-) delete mode 100644 src/instrumentation.ts diff --git a/package.json b/package.json index 6921f28c..75f621a7 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "@baselime/sveltekit-opentelemetry-middleware": "^0.1.6", "@event-calendar/core": "^2.0.0", "@event-calendar/time-grid": "^2.0.0", + "@jill64/sentry-sveltekit-cloudflare": "^1.7.11", "@neodrag/svelte": "^2.0.3", "@stripe/stripe-js": "^3.0.10", "daisyui": "^4.7.2", diff --git a/src/hooks.client.ts b/src/hooks.client.ts index 75f2f67d..88ac1dab 100644 --- a/src/hooks.client.ts +++ b/src/hooks.client.ts @@ -1,17 +1,24 @@ -// import type { Handle } from '@sveltejs/kit' -// import { get } from '$lib/api' +import { env } from '$env/dynamic/public' +import { init } from '@jill64/sentry-sveltekit-cloudflare/client' +import * as Sentry from '@sentry/browser' -// export const handle = async ({ event, resolve }: { event: any; resolve: any }) => { -// return await resolve(event, { ssr: false }) -// } +const onError = init(env.PUBLIC_SENTRY_DSN || '', { + sentryOptions: { + // tunnel: '/tunnel', + integrations: [ + Sentry.browserTracingIntegration(), + // Sentry.browserProfilingIntegration(), + Sentry.replayIntegration() + ], + tracesSampleRate: 1.0, + profilesSampleRate: 1.0, + // we only care about errors + replaysSessionSampleRate: 0, + replaysOnErrorSampleRate: 1.0 + }, + enableInDevMode: false +}) -// export const handleError = (({ error, event }) => { -// const errorId = crypto.randomUUID(); -// // example integration with https://sentry.io/ -// // Sentry.captureException(error, { event, errorId }) - -// return { -// message: 'Whoops!', -// errorId -// }; -// }) satisfies HandleClientError +export const handleError = onError((e, sentryEventId) => { + // no special error handling +}) diff --git a/src/hooks.server.ts b/src/hooks.server.ts index da930141..d8f0d94d 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -5,7 +5,19 @@ import { get } from '$lib/api' import { user_role } from '$lib/stores/userStore' import { env } from '$env/dynamic/public' -export const handle: Handle = async ({ event, resolve }) => { +import { init } from '@jill64/sentry-sveltekit-cloudflare/server' + +const { onHandle, onError } = init(env.PUBLIC_SENTRY_DSN || '', { + toucanOptions: { + tracesSampleRate: 1.0 + }, + handleOptions: { + handleUnknownRoutes: false + }, + enableInDevMode: false +}) + +export const handle = onHandle(async ({ event, resolve }) => { const pathname = event.url.pathname const userId = event.url.searchParams.get('userId') || event.cookies.get('userId') || '' let token = event.url.searchParams.get('token') || event.cookies.get('token') || '' @@ -73,11 +85,11 @@ export const handle: Handle = async ({ event, resolve }) => { } else { return await resolve(event) } -} +}) -export const handleError = ({ error }: { error: any }) => { - console.log('error', error) +export const handleError = onError((e, sentryEventId) => { + console.log('error', e) return { message: 'Whoops something went wrong!' } -} +}) diff --git a/src/instrumentation.ts b/src/instrumentation.ts deleted file mode 100644 index a2ce2aa1..00000000 --- a/src/instrumentation.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { withOpenTelemetry } from '@baselime/sveltekit-opentelemetry-middleware' -import { BaselimeSDK } from '@baselime/node-opentelemetry' - -new BaselimeSDK({}).start() - -export const handle = withOpenTelemetry(async ({ event, resolve }) => resolve(event)) diff --git a/vite.config.ts b/vite.config.ts index 2220844b..f7dc33a3 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -8,6 +8,14 @@ const config: UserConfig = { }, build: { assetsInlineLimit: 0 + }, + ssr: { + noExternal: ['@jill64/sentry-sveltekit-cloudflare'] + }, + server: { + headers: { + 'Document-Policy': 'js-profiling' + } } }