From 1a1baa715d38042bcddd3304f1b27e20f300724d Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Thu, 16 Dec 2021 18:02:01 +0530 Subject: [PATCH] feat: disable sentry if telemetry is off --- packages/hoppscotch-app/helpers/sentry.ts | 8 ++++++++ packages/hoppscotch-app/layouts/default.vue | 19 +++++++++++++++++++ packages/hoppscotch-app/nuxt.config.js | 2 +- packages/hoppscotch-app/package.json | 1 + pnpm-lock.yaml | 8 ++------ 5 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 packages/hoppscotch-app/helpers/sentry.ts diff --git a/packages/hoppscotch-app/helpers/sentry.ts b/packages/hoppscotch-app/helpers/sentry.ts new file mode 100644 index 000000000..18c17afa4 --- /dev/null +++ b/packages/hoppscotch-app/helpers/sentry.ts @@ -0,0 +1,8 @@ +import { useContext } from "@nuxtjs/composition-api" +import * as Sentry from "@sentry/browser" + +export function useSentry() { + // TODO: Make Sentry load lazy at some point ? (see nuxt/sentry) + const { $sentry } = useContext() + return $sentry as any as typeof Sentry +} diff --git a/packages/hoppscotch-app/layouts/default.vue b/packages/hoppscotch-app/layouts/default.vue index 72e8460da..0be719766 100644 --- a/packages/hoppscotch-app/layouts/default.vue +++ b/packages/hoppscotch-app/layouts/default.vue @@ -57,6 +57,7 @@ import { logPageView } from "~/helpers/fb/analytics" import { hookKeybindingsListener } from "~/helpers/keybindings" import { defineActionHandler } from "~/helpers/actions" import useWindowSize from "~/helpers/utils/useWindowSize" +import { useSentry } from "~/helpers/sentry" function appLayout() { const rightSidebar = useSetting("SIDEBAR") @@ -80,6 +81,23 @@ function appLayout() { }) } +function setupSentry() { + const sentry = useSentry() + const telemetryEnabled = useSetting("TELEMETRY_ENABLED") + + // Disable sentry error reporting if no telemetry allowed + watch( + telemetryEnabled, + () => { + const client = sentry.getCurrentHub()?.getClient() + if (!client) return + + client.getOptions().enabled = telemetryEnabled.value + }, + { immediate: true } + ) +} + function updateThemes() { const { $colorMode } = useContext() as any @@ -140,6 +158,7 @@ export default defineComponent({ updateThemes() + setupSentry() return { windowInnerWidth: useWindowSize(), ZEN_MODE: useSetting("ZEN_MODE"), diff --git a/packages/hoppscotch-app/nuxt.config.js b/packages/hoppscotch-app/nuxt.config.js index 8558cd4f0..7a1255eda 100644 --- a/packages/hoppscotch-app/nuxt.config.js +++ b/packages/hoppscotch-app/nuxt.config.js @@ -202,7 +202,7 @@ export default { // Sentry module configuration sentry: { dsn: process.env.SENTRY_DSN, - lazy: true, + // lazy: true, }, // Sitemap module configuration (https://github.com/nuxt-community/sitemap-module) diff --git a/packages/hoppscotch-app/package.json b/packages/hoppscotch-app/package.json index 13cdcf1d6..6bc503fe6 100644 --- a/packages/hoppscotch-app/package.json +++ b/packages/hoppscotch-app/package.json @@ -127,6 +127,7 @@ "@nuxtjs/stylelint-module": "^4.1.0", "@nuxtjs/svg": "^0.3.0", "@relmify/jest-fp-ts": "^1.1.1", + "@sentry/browser": "^6.16.1", "@testing-library/jest-dom": "^5.16.0", "@types/codemirror": "^5.60.5", "@types/cookie": "^0.4.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 452ef8da7..ee5b8d5c6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -93,6 +93,7 @@ importers: '@nuxtjs/svg': ^0.3.0 '@nuxtjs/toast': ^3.3.1 '@relmify/jest-fp-ts': ^1.1.1 + '@sentry/browser': ^6.16.1 '@testing-library/jest-dom': ^5.16.0 '@types/codemirror': ^5.60.5 '@types/cookie': ^0.4.1 @@ -259,6 +260,7 @@ importers: '@nuxtjs/stylelint-module': 4.1.0_stylelint@14.1.0 '@nuxtjs/svg': 0.3.0 '@relmify/jest-fp-ts': 1.1.1_fp-ts@2.11.5+io-ts@2.2.16 + '@sentry/browser': 6.16.1 '@testing-library/jest-dom': 5.16.1 '@types/codemirror': 5.60.5 '@types/cookie': 0.4.1 @@ -4159,7 +4161,6 @@ packages: '@sentry/types': 6.16.1 '@sentry/utils': 6.16.1 tslib: 1.14.1 - dev: false /@sentry/cli/1.71.0: resolution: {integrity: sha512-Z8TzH7PkiRfjWSzjXOfPWWp6wxjr+n39Jdrt26OcInVQZM1sx/gZULrDiQZ1L2dy9Fe9AR4SF4nt2/7h2GmLQQ==} @@ -4186,7 +4187,6 @@ packages: '@sentry/types': 6.16.1 '@sentry/utils': 6.16.1 tslib: 1.14.1 - dev: false /@sentry/hub/6.16.1: resolution: {integrity: sha512-4PGtg6AfpqMkreTpL7ymDeQ/U1uXv03bKUuFdtsSTn/FRf9TLS4JB0KuTZCxfp1IRgAA+iFg6B784dDkT8R9eg==} @@ -4195,7 +4195,6 @@ packages: '@sentry/types': 6.16.1 '@sentry/utils': 6.16.1 tslib: 1.14.1 - dev: false /@sentry/integrations/6.16.1: resolution: {integrity: sha512-YobbH3jWMRJxCeFzr8USlju1Up0EJoxaAT4y+LQQ0ZLfyfOdPX0d0iFnWMCar8gwR1nRujFS0HM0BBKY3an0LA==} @@ -4214,7 +4213,6 @@ packages: '@sentry/hub': 6.16.1 '@sentry/types': 6.16.1 tslib: 1.14.1 - dev: false /@sentry/node/6.16.1: resolution: {integrity: sha512-SeDDoug2kUxeF1D7JGPa3h5EXxKtmA01mITBPYx5xbJ0sMksnv5I5bC1SJ8arRRzq6+W1C4IEeDBQtrVCk6ixA==} @@ -4247,7 +4245,6 @@ packages: /@sentry/types/6.16.1: resolution: {integrity: sha512-Wh354g30UsJ5kYJbercektGX4ZMc9MHU++1NjeN2bTMnbofEcpUDWIiKeulZEY65IC1iU+1zRQQgtYO+/hgCUQ==} engines: {node: '>=6'} - dev: false /@sentry/utils/6.16.1: resolution: {integrity: sha512-7ngq/i4R8JZitJo9Sl8PDnjSbDehOxgr1vsoMmerIsyRZ651C/8B+jVkMhaAPgSdyJ0AlE3O7DKKTP1FXFw9qw==} @@ -4255,7 +4252,6 @@ packages: dependencies: '@sentry/types': 6.16.1 tslib: 1.14.1 - dev: false /@sentry/webpack-plugin/1.18.3: resolution: {integrity: sha512-Qk3Jevislc5DZK0X/WwRVcOtO7iatnWARsEgTV/TuXvDN+fUDDpD/2MytAWAbpLaLy3xEB/cXGeLsbv6d1XNkQ==}