|
1 | | -import { useState } from 'react'; |
| 1 | +import { useState, useEffect } from 'react'; |
2 | 2 | import * as Sentry from '@sentry/react'; |
3 | 3 | import { useFeature } from './useFeature'; |
4 | 4 |
|
5 | | -export function useSentry() { |
6 | | - const [dsn, setDsn] = useState(); |
7 | | - |
8 | | - const initSentry = dsn => { |
9 | | - Sentry.init({ |
10 | | - dsn, |
11 | | - release: 'busola', |
12 | | - integrations: [new Sentry.browserTracingIntegration()], |
13 | | - tracesSampleRate: 1.0, |
14 | | - }); |
15 | | - }; |
| 5 | +const initSentry = dsn => { |
| 6 | + Sentry.init({ |
| 7 | + dsn, |
| 8 | + release: 'busola', |
| 9 | + integrations: [ |
| 10 | + new Sentry.browserTracingIntegration(), |
| 11 | + new Sentry.replayIntegration(), |
| 12 | + ], |
| 13 | + tracesSampleRate: 1.0, |
| 14 | + // Session Replay |
| 15 | + replaysSessionSampleRate: 0.1, |
| 16 | + replaysOnErrorSampleRate: 1.0, |
| 17 | + }); |
| 18 | +}; |
16 | 19 |
|
17 | | - try { |
18 | | - const feature = useFeature('SENTRY') || {}; |
19 | | - if (feature.isEnabled && feature.config?.dsn) { |
20 | | - const nextDsn = feature.config.dsn; |
| 20 | +export function useSentry() { |
| 21 | + const [dsn, setDsn] = useState(null); |
| 22 | + const feature = useFeature('SENTRY'); |
21 | 23 |
|
22 | | - if (nextDsn !== dsn) { |
23 | | - setDsn(nextDsn); |
24 | | - initSentry(nextDsn); |
| 24 | + useEffect(() => { |
| 25 | + try { |
| 26 | + if (feature?.isEnabled && feature?.config?.dsn) { |
| 27 | + const nextDsn = feature.config.dsn; |
| 28 | + if (nextDsn !== dsn) { |
| 29 | + setDsn(nextDsn); |
| 30 | + initSentry(nextDsn); |
| 31 | + } |
25 | 32 | } |
| 33 | + } catch (e) { |
| 34 | + console.warn('Sentry not enabled due to error', e); |
26 | 35 | } |
27 | | - } catch (e) { |
28 | | - console.warn('Sentry not enabled due to error', e); |
29 | | - } |
| 36 | + }, [feature, dsn]); |
30 | 37 | } |
0 commit comments