Skip to content

Commit

Permalink
fix: disable sentry if widget is not mounted
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Jul 18, 2022
1 parent bc1799b commit cccb78d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/widget/src/config/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const initSentry = (enabled?: boolean) => {
],
sampleRate: 1,
tracesSampleRate: 0.2,
enabled: enabled && process.env.NODE_ENV === 'production',
enabled,
environment: process.env.NODE_ENV,
release: version,
});
Expand Down
9 changes: 7 additions & 2 deletions packages/widget/src/hooks/useTelemetry.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
/* eslint-disable consistent-return */
import { useEffect } from 'react';
import { initSentry } from '../config/sentry';

export const useTelemetry = (disabled?: boolean) => {
useEffect(() => {
if (process.env.NODE_ENV === 'production' && disabled) {
if (disabled) {
console.warn(
'Enable crash reports and diagnostic data to be collected. This helps us to better understand how the widget is performing and where improvements need to be made.',
);
initSentry(false);
} else {
initSentry(true);
return () => {
initSentry(false);
};
}
}, [disabled]);
};
2 changes: 0 additions & 2 deletions packages/widget/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { App } from './App';
import { AppDrawer } from './AppDrawer';
import { initSentry } from './config/sentry';
import './fonts/inter.css';
import { configureReactI18next } from './i18n';

export * from './types';

initSentry(true);
configureReactI18next();
// ClassNameGenerator.configure((componentName) => componentName.replace('Mui', ''));

Expand Down

0 comments on commit cccb78d

Please sign in to comment.