mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Refactor and export const/func
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
This commit is contained in:
parent
73abc6837b
commit
a48dbe36bf
@ -27,11 +27,13 @@ import logger from "../main/logger";
|
|||||||
|
|
||||||
// https://www.electronjs.org/docs/api/process#processtype-readonly
|
// https://www.electronjs.org/docs/api/process#processtype-readonly
|
||||||
const electronProcessType = ["browser", "renderer", "worker"] as const;
|
const electronProcessType = ["browser", "renderer", "worker"] as const;
|
||||||
const integrations = [
|
|
||||||
|
export const integrations = [
|
||||||
new CaptureConsole({ levels: ["error"] }),
|
new CaptureConsole({ levels: ["error"] }),
|
||||||
new Dedupe(),
|
new Dedupe(),
|
||||||
new Offline()
|
new Offline()
|
||||||
];
|
];
|
||||||
|
|
||||||
const initialScope = (processType: typeof electronProcessType[number]) => {
|
const initialScope = (processType: typeof electronProcessType[number]) => {
|
||||||
return {
|
return {
|
||||||
tags: {
|
tags: {
|
||||||
@ -41,10 +43,25 @@ const initialScope = (processType: typeof electronProcessType[number]) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const environment = isProduction ? "production" : "development";
|
export const environment = isProduction ? "production" : "development";
|
||||||
|
|
||||||
const logInitError = (reason: string) => {
|
const logInitError = (reason: string) => {
|
||||||
logger.warn(`⚠️ [SENTRY-INIT]: ${reason}, Sentry is not initialized.`);
|
logger.warn(`⚠️ [SENTRY-INIT]: ${reason}, Sentry is not initialized.`);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const beforeSend = (event: SentryEvent) => {
|
||||||
|
const allowErrorReporting = UserStore.getInstance().allowErrorReporting;
|
||||||
|
|
||||||
|
if (allowErrorReporting) return event;
|
||||||
|
|
||||||
|
logger.info(`🔒 [SENTRY-BEFORE-SEND-HOOK]: allowErrorReporting: ${allowErrorReporting}. Sentry event is caught but not sent to server.`);
|
||||||
|
logger.info("🔒 [SENTRY-BEFORE-SEND-HOOK]: === START OF SENTRY EVENT ===");
|
||||||
|
logger.info(event);
|
||||||
|
logger.info("🔒 [SENTRY-BEFORE-SEND-HOOK]: === END OF SENTRY EVENT ===");
|
||||||
|
|
||||||
|
// if return null, the event won't be sent
|
||||||
|
// ref https://github.com/getsentry/sentry-javascript/issues/2039
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SentryInit = () => {
|
export const SentryInit = () => {
|
||||||
@ -83,25 +100,13 @@ export const SentryInit = () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Sentry.init({
|
Sentry.init({
|
||||||
beforeSend(event: SentryEvent) {
|
beforeSend,
|
||||||
const allowErrorReporting = UserStore.getInstance().allowErrorReporting;
|
|
||||||
|
|
||||||
if (allowErrorReporting) return event;
|
|
||||||
|
|
||||||
logger.info(`🔒 [SENTRY-BEFORE-SEND-HOOK]: allowErrorReporting: ${allowErrorReporting}. Sentry event is caught but not sent to server.`);
|
|
||||||
logger.info("🔒 [SENTRY-BEFORE-SEND-HOOK]: === START OF SENTRY EVENT ===");
|
|
||||||
logger.info(event);
|
|
||||||
logger.info("🔒 [SENTRY-BEFORE-SEND-HOOK]: === END OF SENTRY EVENT ===");
|
|
||||||
|
|
||||||
// if return null, the event won't be sent
|
|
||||||
// ref https://github.com/getsentry/sentry-javascript/issues/2039
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
dsn: sentryDsn,
|
dsn: sentryDsn,
|
||||||
integrations,
|
integrations,
|
||||||
initialScope: initialScope(processType),
|
initialScope: initialScope(processType),
|
||||||
environment
|
environment
|
||||||
});
|
});
|
||||||
|
logger.info(`✔️ [SENTRY-INIT]: Sentry for ${processType} is initialized.`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logInitError(`Sentry.init() error ${error?.message}`);
|
logInitError(`Sentry.init() error ${error?.message}`);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user