✨(frontend) add sentry
In order to monitor the frontend, we are adding sentry.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
"@gouvfr-lasuite/integration": "1.0.2",
|
||||
"@hocuspocus/provider": "2.13.7",
|
||||
"@openfun/cunningham-react": "2.9.4",
|
||||
"@sentry/nextjs": "8.39.0",
|
||||
"@tanstack/react-query": "5.60.5",
|
||||
"i18next": "23.16.5",
|
||||
"i18next-browser-languagedetector": "8.0.0",
|
||||
|
||||
@@ -13,6 +13,12 @@ jest.mock('next/router', () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('@sentry/nextjs', () => ({
|
||||
captureException: jest.fn(),
|
||||
captureMessage: jest.fn(),
|
||||
setUser: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('Page', () => {
|
||||
it('checks Page rendering', () => {
|
||||
render(<Page />, { wrapper: AppWrapper });
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
import { PropsWithChildren } from 'react';
|
||||
import { PropsWithChildren, useEffect } from 'react';
|
||||
|
||||
import { useSentryStore } from '@/stores/useSentryStore';
|
||||
|
||||
import { useConfig } from './api/useConfig';
|
||||
|
||||
export const ConfigProvider = ({ children }: PropsWithChildren) => {
|
||||
useConfig();
|
||||
const { data: conf } = useConfig();
|
||||
const { setSentry } = useSentryStore();
|
||||
|
||||
useEffect(() => {
|
||||
if (!conf?.SENTRY_DSN) {
|
||||
return;
|
||||
}
|
||||
|
||||
setSentry(conf.SENTRY_DSN, conf.ENVIRONMENT);
|
||||
}, [conf?.SENTRY_DSN, conf?.ENVIRONMENT, setSentry]);
|
||||
|
||||
return children;
|
||||
};
|
||||
|
||||
32
src/frontend/apps/impress/src/stores/useSentryStore.tsx
Normal file
32
src/frontend/apps/impress/src/stores/useSentryStore.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import * as Sentry from '@sentry/nextjs';
|
||||
import type { Client } from '@sentry/types';
|
||||
import { create } from 'zustand';
|
||||
|
||||
import packageJson from '../../package.json';
|
||||
|
||||
interface SentryState {
|
||||
sentry?: Client;
|
||||
setSentry: (dsn?: string, environment?: string) => void;
|
||||
}
|
||||
|
||||
export const useSentryStore = create<SentryState>((set, get) => ({
|
||||
sentry: undefined,
|
||||
setSentry: (dsn, environment) => {
|
||||
const sentry = get().sentry;
|
||||
if (sentry) {
|
||||
return;
|
||||
}
|
||||
|
||||
set({
|
||||
sentry: Sentry.init({
|
||||
dsn,
|
||||
environment,
|
||||
integrations: [Sentry.replayIntegration()],
|
||||
release: packageJson.version,
|
||||
replaysSessionSampleRate: 0.1,
|
||||
replaysOnErrorSampleRate: 1.0,
|
||||
tracesSampleRate: 1.0,
|
||||
}),
|
||||
});
|
||||
},
|
||||
}));
|
||||
Reference in New Issue
Block a user