feat: connect sentry to dash and api
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import * as Sentry from '@sentry/sveltekit';
|
||||
import { dev } from '$app/environment';
|
||||
import { env } from '$env/dynamic/public';
|
||||
import { handleErrorWithSentry } from '@sentry/sveltekit';
|
||||
|
||||
const dsn = env.PUBLIC_SENTRY_DSN?.trim();
|
||||
const isSelfHosted = env.PUBLIC_IS_SELFHOSTED === 'true';
|
||||
|
||||
if (dsn && !dev && !isSelfHosted) {
|
||||
Sentry.init({
|
||||
dsn,
|
||||
environment: env.PUBLIC_SENTRY_ENVIRONMENT?.trim() || 'production',
|
||||
tracesSampleRate: Number(env.PUBLIC_SENTRY_TRACES_SAMPLE_RATE ?? 0),
|
||||
replaysSessionSampleRate: Number(env.PUBLIC_SENTRY_REPLAYS_SESSION_SAMPLE_RATE ?? 0),
|
||||
replaysOnErrorSampleRate: Number(env.PUBLIC_SENTRY_REPLAYS_ON_ERROR_SAMPLE_RATE ?? 1),
|
||||
integrations: [Sentry.replayIntegration()]
|
||||
});
|
||||
}
|
||||
|
||||
export const handleError = handleErrorWithSentry();
|
||||
@@ -1,6 +1,5 @@
|
||||
import { PUBLIC_IS_SELFHOSTED } from '$env/static/public';
|
||||
import { initPosthog, type PosthogBootstrapUser } from '$lib/utils/services/posthog';
|
||||
import { initSentry } from '$lib/utils/services/sentry';
|
||||
import { initUmami } from '$lib/utils/services/umami';
|
||||
import { licenseApi } from '$features/license/api/license.svelte';
|
||||
|
||||
@@ -10,7 +9,6 @@ export function setupAnalytics(user?: PosthogBootstrapUser) {
|
||||
if (isInitialized) return;
|
||||
isInitialized = true;
|
||||
|
||||
initSentry();
|
||||
initPosthog(user);
|
||||
initUmami();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { appInitApi } from '$features/app/init.svelte';
|
||||
import { authClient } from '$lib/utils/services/auth/client';
|
||||
import { capturePosthogEvent } from '$lib/utils/services/posthog';
|
||||
import { clearSentryUser } from '$lib/utils/services/sentry';
|
||||
import { goto } from '$app/navigation';
|
||||
import posthog from 'posthog-js';
|
||||
import { resolve } from '$app/paths';
|
||||
@@ -16,6 +17,7 @@ export async function logout(redirect = true) {
|
||||
|
||||
capturePosthogEvent('user_logged_out');
|
||||
posthog.reset();
|
||||
clearSentryUser();
|
||||
|
||||
if (redirect) {
|
||||
goto(resolve('/login', {}));
|
||||
|
||||
@@ -289,8 +289,6 @@ export function getApiHeaders(
|
||||
): { headers: { cookie: string; 'cio-org-id'?: string } } {
|
||||
const cioCookies = getCioCookieString(cookies);
|
||||
|
||||
console.log('cioCookies', cioCookies);
|
||||
console.log('cookies', cookies.getAll());
|
||||
const headers: { cookie: string; 'cio-org-id'?: string } = {
|
||||
cookie: cioCookies || ''
|
||||
};
|
||||
|
||||
@@ -1,26 +1,30 @@
|
||||
import * as Sentry from '@sentry/sveltekit';
|
||||
import { dev } from '$app/environment';
|
||||
// import * as Sentry from '@sentry/browser';
|
||||
// import { CaptureConsole } from '@sentry/integrations';
|
||||
import { env } from '$env/dynamic/public';
|
||||
|
||||
export const initSentry = (): void => {
|
||||
if (dev) return;
|
||||
const isEnabled = () =>
|
||||
Boolean(env.PUBLIC_SENTRY_DSN?.trim()) && !dev && env.PUBLIC_IS_SELFHOSTED !== 'true';
|
||||
|
||||
// Sentry.init({
|
||||
// dsn: 'https://c966f7e8cb1d4306be20b26bb4f0cc96@o476906.ingest.sentry.io/5999999',
|
||||
// integrations: [
|
||||
// new CaptureConsole({
|
||||
// levels: ['error']
|
||||
// }),
|
||||
// new Sentry.Replay()
|
||||
// ],
|
||||
// environment: 'production',
|
||||
// replaysSessionSampleRate: 0.5,
|
||||
// replaysOnErrorSampleRate: 1.0
|
||||
// });
|
||||
export type SentryUser = {
|
||||
id: string;
|
||||
email?: string | null;
|
||||
username?: string | null;
|
||||
fullname?: string | null;
|
||||
};
|
||||
|
||||
export const setSentryUser = (user: Record<string, unknown>): void => {
|
||||
if (dev) return;
|
||||
export const setSentryUser = (user: SentryUser): void => {
|
||||
if (!isEnabled()) return;
|
||||
|
||||
// Sentry.setUser(user);
|
||||
Sentry.setUser({
|
||||
id: user.id,
|
||||
...(user.email && { email: user.email }),
|
||||
...(user.username && { username: user.username }),
|
||||
...(user.fullname && { fullname: user.fullname })
|
||||
});
|
||||
};
|
||||
|
||||
export const clearSentryUser = (): void => {
|
||||
if (!isEnabled()) return;
|
||||
|
||||
Sentry.setUser(null);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user