diff --git a/bun.lockb b/bun.lockb index 5a74fd7..0500fdd 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/functions/bugs-tunnel.js b/functions/bugs-tunnel.js new file mode 100644 index 0000000..2ce02a3 --- /dev/null +++ b/functions/bugs-tunnel.js @@ -0,0 +1,24 @@ +export async function onRequestPost({request}) { + let {readable, writable} = new TransformStream(); + await request.body.pipeTo(writable); + const [header, body] = readable.tee(); + let decoder = new TextDecoder(); + let chunk = ''; + const headerReader = header.getReader(); + while (true) { + const {done, value} = await headerReader.read(); + if (done) break; + chunk += decoder.decode(value); + const index = chunk.indexOf('\n'); + if (index >= 0) { + const line = chunk.slice(0, index); + const dsn = new URL(JSON.parse(line).dsn); + const headers = request.headers; + headers.set('X-Forwarded-For', request.headers.get('CF-Connecting-IP')); + return fetch(`https://${dsn.host}/api${dsn.pathname}/envelope/`, { + method: 'POST', body, headers, + }); + } + } + return new Response(null, {status: 404}); +} diff --git a/package.json b/package.json index 8371f3e..4759153 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ } }, "dependencies": { + "@sentry/vue": "^7.98.0", "bootstrap": "^5.3.2", "vue": "^3.4.15" }, diff --git a/src/env.d.ts b/src/env.d.ts index 760da20..d36bee6 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -4,6 +4,7 @@ interface ImportMetaEnv { readonly VITE_APP_VERSION: string readonly VITE_UMAMI_ID: string readonly VITE_UMAMI_SRC: string + readonly VITE_SENTRY_DSN: string; } interface ImportMeta { diff --git a/src/main.ts b/src/main.ts index 22cc151..68106d9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,21 @@ -import { createApp } from 'vue' -import 'bootstrap/scss/bootstrap.scss' -import App from './App.vue' +import {createApp} from 'vue'; +import 'bootstrap/scss/bootstrap.scss'; +import App from './App.vue'; +import * as Sentry from '@sentry/vue'; -createApp(App).mount('#app') +const app = createApp(App); + +if (import.meta.env.PROD && import.meta.env.VITE_SENTRY_DSN) { + Sentry.init({ + app, + tunnel: '/bugs-tunnel', + dsn: import.meta.env.VITE_SENTRY_DSN, + environment: import.meta.env.MODE, + integrations: [Sentry.replayIntegration()], + replaysSessionSampleRate: 1.0, + replaysOnErrorSampleRate: 1.0, + tracePropagationTargets: ['localhost', 'sentry.gander.pl'], + }); +} + +app.mount('#app');