diff --git a/.github/workflows/github_actions.yml b/.github/workflows/github_actions.yml index 7a132cfd..3ca11459 100644 --- a/.github/workflows/github_actions.yml +++ b/.github/workflows/github_actions.yml @@ -121,6 +121,9 @@ jobs: - name: Restore dependencies run: npm ci - name: Build Cef-html + env: + SENTRY_URL: ${{ secrets.SentryUrl }} + SENTRY_AUTH_TOKEN: ${{ secrets.SentryAuthToken }} run: npm run prod - name: Upload Cef-html artifacts uses: actions/upload-artifact@v4 diff --git a/src/plugin/sentry.js b/src/plugin/sentry.js index da421e5a..ec986827 100644 --- a/src/plugin/sentry.js +++ b/src/plugin/sentry.js @@ -1,29 +1,60 @@ import * as Sentry from '@sentry/vue'; import configRepository from '../service/config'; -export function initSentry(app) { - configRepository - .getString('VRCX_SentryEnabled', 'false') - .then((enabled) => { - let isNightly = false; - AppApi.GetVersion().then( - (v) => (isNightly = v.includes('Nightly')) - ); - if (enabled === 'true' && isNightly) { - Sentry.init({ - app, - dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0', - environment: 'nightly', - replaysSessionSampleRate: 0.1, - replaysOnErrorSampleRate: 1.0, - integrations: [ - Sentry.replayIntegration({ - maskAllText: true, - blockAllMedia: true - }) - ] - }); - console.log('Sentry initialized'); - } +export async function initSentry(app) { + const enabled = await configRepository.getString( + 'VRCX_SentryEnabled', + 'false' + ); + const version = await AppApi.GetVersion(); + const isNightly = version.includes('Nightly'); + if (enabled !== 'true' || !isNightly) { + return; + } + const vrcxId = await configRepository.getString('VRCX_id', ''); + const response = await webApiService.execute({ + url: 'https://api0.vrcx.app/errorreporting/getdsn', + method: 'GET', + headers: { + Referer: 'https://vrcx.app', + 'VRCX-ID': vrcxId + } + }); + if (response.status !== 200) { + console.error( + 'Failed to get Sentry DSN:', + response.status, + response.data + ); + return; + } + try { + const dsn = atob(response.data); + Sentry.init({ + app, + dsn, + environment: 'nightly', + replaysSessionSampleRate: 0.1, + replaysOnErrorSampleRate: 1.0, + beforeSend(event, hint) { + if ( + event.request?.status && + (event.request.status === 404 || + event.request.status === 403) + ) { + return null; + } + }, + integrations: [ + Sentry.replayIntegration({ + maskAllText: true, + blockAllMedia: true + }) + ] }); + console.log('Sentry initialized'); + } catch (e) { + console.error('Failed to initialize Sentry:', e); + return; + } } diff --git a/src/vite.config.js b/src/vite.config.js index a6147278..19c17204 100644 --- a/src/vite.config.js +++ b/src/vite.config.js @@ -5,18 +5,21 @@ import { fileURLToPath } from 'node:url'; import { dirname, resolve } from 'node:path'; const __dirname = dirname(fileURLToPath(import.meta.url)); +const url = process.env.SENTRY_URL; +const authToken = process.env.SENTRY_AUTH_TOKEN; // https://vite.dev/config/ export default defineConfig(() => ({ base: '', plugins: [ vue(), - sentryVitePlugin({ - authToken: process.env.SENTRY_AUTH_TOKEN, - org: 'example', - project: 'vrcx-web', - url: 'https://example.example.example/' - }) + url && + sentryVitePlugin({ + url, + authToken, + org: 'vrcx', + project: 'vrcx-web' + }) ], define: { LINUX: JSON.stringify(process.env.PLATFORM === 'linux'),