-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
14 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
import * as Sentry from "@sentry/electron/main"; | ||
import logger from "@shared/utils/Logger"; | ||
let enabledReporting = true; | ||
const sentryLog = logger.child("Sentry"); | ||
export const setSentryEnabled = (enable: boolean) => { | ||
if (enabledReporting !== enable) enabledReporting = enable; | ||
if (!enable) logger.child("Sentry").warn("Sentry has been disabled"); | ||
else logger.child("Sentry").warn("Sentry has been enabled"); | ||
if (!enable) sentryLog.warn("Sentry has been disabled"); | ||
else sentryLog.warn("Sentry has been enabled"); | ||
}; | ||
|
||
if (import.meta.env.VITE_SENTRY_DSN) { | ||
Sentry && | ||
!Sentry.isInitialized && | ||
if (import.meta.env.VITE_SENTRY_DSN && Sentry && !Sentry.isInitialized) { | ||
try { | ||
Sentry.init({ | ||
dsn: import.meta.env.VITE_SENTRY_DSN, | ||
enabled: true, | ||
onFatalError(error) { | ||
if (enabledReporting) sentryLog.error(error); | ||
}, | ||
beforeSend: (ev) => { | ||
if (!enabledReporting) return null; | ||
return ev; | ||
}, | ||
}); | ||
logger.child("Sentry").info("Sentry has been initialized"); | ||
} else logger.child("Sentry").warn("Sentry is not enabled"); | ||
} catch { | ||
sentryLog.warn("Sentry has failed to initialize, server may not be reachable."); | ||
} finally { | ||
sentryLog.info("Sentry has been initialized"); | ||
} | ||
} else if (!Sentry || !Sentry.isInitialized) sentryLog.warn("Sentry is not enabled"); | ||
export { Sentry }; |