From d3ac22600433d4985782e18eecb002dd627a48d1 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 23 Sep 2022 16:09:00 +0530 Subject: [PATCH 1/5] add sentry.properties --- sentry.properties | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 sentry.properties diff --git a/sentry.properties b/sentry.properties new file mode 100644 index 000000000..c5d0544d7 --- /dev/null +++ b/sentry.properties @@ -0,0 +1,3 @@ +defaults.url=https://sentry.ente.io/ +defaults.org=ente +defaults.project=bada-frame From 8e85c08645851f8ff83cb0d84762fca56d8e95c5 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 23 Sep 2022 16:09:44 +0530 Subject: [PATCH 2/5] make production the default environment --- src/constants/sentry/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants/sentry/index.ts b/src/constants/sentry/index.ts index 4e10419f4..e2e8b5a9d 100644 --- a/src/constants/sentry/index.ts +++ b/src/constants/sentry/index.ts @@ -3,7 +3,7 @@ export const getSentryDSN = () => 'https://60abb33b597c42f6a3fb27cd82c55101@sentry.ente.io/2'; export const getSentryENV = () => - process.env.NEXT_PUBLIC_SENTRY_ENV ?? 'development'; + process.env.NEXT_PUBLIC_SENTRY_ENV ?? 'production'; export const getSentryRelease = () => process.env.SENTRY_RELEASE; From 0de3f931d76f8256216f3dbf5390b9744ffad721 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 23 Sep 2022 16:09:57 +0530 Subject: [PATCH 3/5] only log to console if environment is explicity set to development --- src/utils/logging/index.ts | 4 ++-- src/utils/sentry/index.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/logging/index.ts b/src/utils/logging/index.ts index 9e12d6e12..4b337489e 100644 --- a/src/utils/logging/index.ts +++ b/src/utils/logging/index.ts @@ -4,7 +4,7 @@ import { formatDateTime } from 'utils/time'; import { saveLogLine, getLogs } from 'utils/storage'; export function addLogLine(log: string) { - if (!process.env.NEXT_PUBLIC_SENTRY_ENV) { + if (process.env.NEXT_PUBLIC_SENTRY_ENV === 'development') { console.log(log); } saveLogLine({ @@ -14,7 +14,7 @@ export function addLogLine(log: string) { } export const addLocalLog = (getLog: () => string) => { - if (!process.env.NEXT_PUBLIC_SENTRY_ENV) { + if (process.env.NEXT_PUBLIC_SENTRY_ENV === 'development') { console.log(getLog()); } }; diff --git a/src/utils/sentry/index.ts b/src/utils/sentry/index.ts index 35a4d873b..83f9682e2 100644 --- a/src/utils/sentry/index.ts +++ b/src/utils/sentry/index.ts @@ -16,7 +16,7 @@ export const logError = ( error?.stack } msg: ${msg} info: ${JSON.stringify(info)}` ); - if (!process.env.NEXT_PUBLIC_SENTRY_ENV) { + if (process.env.NEXT_PUBLIC_SENTRY_ENV === 'development') { console.log(error, { msg, info }); } Sentry.captureException(err, { From bfd49914e8db8d80dc3ddfec2495a74215263f9e Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 23 Sep 2022 16:22:47 +0530 Subject: [PATCH 4/5] make use environment constants --- sentryConfigUtil.js | 4 +++- src/constants/sentry/index.ts | 7 ++++++- src/utils/collection/index.ts | 3 ++- src/utils/logging/index.ts | 5 +++-- src/utils/sentry/index.ts | 3 ++- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/sentryConfigUtil.js b/sentryConfigUtil.js index 1b19f2f6b..3beac6a80 100644 --- a/sentryConfigUtil.js +++ b/sentryConfigUtil.js @@ -1,9 +1,11 @@ +const ENV_DEVELOPMENT = 'development'; + module.exports.getIsSentryEnabled = () => { if (process.env.NEXT_PUBLIC_IS_SENTRY_ENABLED) { return process.env.NEXT_PUBLIC_IS_SENTRY_ENABLED === 'yes'; } else { if (process.env.NEXT_PUBLIC_SENTRY_ENV) { - return process.env.NEXT_PUBLIC_SENTRY_ENV !== 'development'; + return process.env.NEXT_PUBLIC_SENTRY_ENV !== ENV_DEVELOPMENT; } } return false; diff --git a/src/constants/sentry/index.ts b/src/constants/sentry/index.ts index e2e8b5a9d..abce60083 100644 --- a/src/constants/sentry/index.ts +++ b/src/constants/sentry/index.ts @@ -1,10 +1,15 @@ +export const ENV_DEVELOPMENT = 'development'; +export const ENV_PRODUCTION = 'production'; + export const getSentryDSN = () => process.env.NEXT_PUBLIC_SENTRY_DSN ?? 'https://60abb33b597c42f6a3fb27cd82c55101@sentry.ente.io/2'; export const getSentryENV = () => - process.env.NEXT_PUBLIC_SENTRY_ENV ?? 'production'; + process.env.NEXT_PUBLIC_SENTRY_ENV ?? ENV_PRODUCTION; export const getSentryRelease = () => process.env.SENTRY_RELEASE; export { getIsSentryEnabled } from '../../../sentryConfigUtil'; + +export const isDEVSentryENV = () => getSentryENV() === ENV_DEVELOPMENT; diff --git a/src/utils/collection/index.ts b/src/utils/collection/index.ts index 1743e2c91..f51eda9de 100644 --- a/src/utils/collection/index.ts +++ b/src/utils/collection/index.ts @@ -33,6 +33,7 @@ import { VISIBILITY_STATE, } from 'types/magicMetadata'; import { IsArchived, updateMagicMetadataProps } from 'utils/magicMetadata'; +import { ENV_DEVELOPMENT } from 'constants/sentry'; export enum COLLECTION_OPS_TYPE { ADD, @@ -121,7 +122,7 @@ export function appendCollectionKeyToShareURL( } const bs58 = require('bs58'); const sharableURL = new URL(url); - if (process.env.NODE_ENV === 'development') { + if (process.env.NODE_ENV === ENV_DEVELOPMENT) { sharableURL.host = getAlbumSiteHost(); sharableURL.protocol = 'http'; } diff --git a/src/utils/logging/index.ts b/src/utils/logging/index.ts index 4b337489e..55d35339d 100644 --- a/src/utils/logging/index.ts +++ b/src/utils/logging/index.ts @@ -2,9 +2,10 @@ import { ElectronFile } from 'types/upload'; import { convertBytesToHumanReadable } from 'utils/file/size'; import { formatDateTime } from 'utils/time'; import { saveLogLine, getLogs } from 'utils/storage'; +import { isDEVSentryENV } from 'constants/sentry'; export function addLogLine(log: string) { - if (process.env.NEXT_PUBLIC_SENTRY_ENV === 'development') { + if (isDEVSentryENV()) { console.log(log); } saveLogLine({ @@ -14,7 +15,7 @@ export function addLogLine(log: string) { } export const addLocalLog = (getLog: () => string) => { - if (process.env.NEXT_PUBLIC_SENTRY_ENV === 'development') { + if (isDEVSentryENV()) { console.log(getLog()); } }; diff --git a/src/utils/sentry/index.ts b/src/utils/sentry/index.ts index 83f9682e2..19cbd6d15 100644 --- a/src/utils/sentry/index.ts +++ b/src/utils/sentry/index.ts @@ -1,4 +1,5 @@ import * as Sentry from '@sentry/nextjs'; +import { isDEVSentryENV } from 'constants/sentry'; import { addLogLine } from 'utils/logging'; import { getSentryUserID } from 'utils/user'; @@ -16,7 +17,7 @@ export const logError = ( error?.stack } msg: ${msg} info: ${JSON.stringify(info)}` ); - if (process.env.NEXT_PUBLIC_SENTRY_ENV === 'development') { + if (isDEVSentryENV()) { console.log(error, { msg, info }); } Sentry.captureException(err, { From 44e70f0703c1922127abdea30e0650314f60f553 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 23 Sep 2022 17:15:44 +0530 Subject: [PATCH 5/5] enabled by default --- sentryConfigUtil.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/sentryConfigUtil.js b/sentryConfigUtil.js index 3beac6a80..a7124cbe0 100644 --- a/sentryConfigUtil.js +++ b/sentryConfigUtil.js @@ -1,12 +1,11 @@ const ENV_DEVELOPMENT = 'development'; module.exports.getIsSentryEnabled = () => { - if (process.env.NEXT_PUBLIC_IS_SENTRY_ENABLED) { - return process.env.NEXT_PUBLIC_IS_SENTRY_ENABLED === 'yes'; + if (process.env.NEXT_PUBLIC_SENTRY_ENV === ENV_DEVELOPMENT) { + return false; + } else if (process.env.DISABLE_SENTRY === 'true') { + return false; } else { - if (process.env.NEXT_PUBLIC_SENTRY_ENV) { - return process.env.NEXT_PUBLIC_SENTRY_ENV !== ENV_DEVELOPMENT; - } + return true; } - return false; };