feat: disable sentry if telemetry is off

This commit is contained in:
Andrew Bastin
2021-12-16 18:02:01 +05:30
parent 29b5913fac
commit 1a1baa715d
5 changed files with 31 additions and 7 deletions

View File

@@ -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
}

View File

@@ -57,6 +57,7 @@ import { logPageView } from "~/helpers/fb/analytics"
import { hookKeybindingsListener } from "~/helpers/keybindings" import { hookKeybindingsListener } from "~/helpers/keybindings"
import { defineActionHandler } from "~/helpers/actions" import { defineActionHandler } from "~/helpers/actions"
import useWindowSize from "~/helpers/utils/useWindowSize" import useWindowSize from "~/helpers/utils/useWindowSize"
import { useSentry } from "~/helpers/sentry"
function appLayout() { function appLayout() {
const rightSidebar = useSetting("SIDEBAR") 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() { function updateThemes() {
const { $colorMode } = useContext() as any const { $colorMode } = useContext() as any
@@ -140,6 +158,7 @@ export default defineComponent({
updateThemes() updateThemes()
setupSentry()
return { return {
windowInnerWidth: useWindowSize(), windowInnerWidth: useWindowSize(),
ZEN_MODE: useSetting("ZEN_MODE"), ZEN_MODE: useSetting("ZEN_MODE"),

View File

@@ -202,7 +202,7 @@ export default {
// Sentry module configuration // Sentry module configuration
sentry: { sentry: {
dsn: process.env.SENTRY_DSN, dsn: process.env.SENTRY_DSN,
lazy: true, // lazy: true,
}, },
// Sitemap module configuration (https://github.com/nuxt-community/sitemap-module) // Sitemap module configuration (https://github.com/nuxt-community/sitemap-module)

View File

@@ -127,6 +127,7 @@
"@nuxtjs/stylelint-module": "^4.1.0", "@nuxtjs/stylelint-module": "^4.1.0",
"@nuxtjs/svg": "^0.3.0", "@nuxtjs/svg": "^0.3.0",
"@relmify/jest-fp-ts": "^1.1.1", "@relmify/jest-fp-ts": "^1.1.1",
"@sentry/browser": "^6.16.1",
"@testing-library/jest-dom": "^5.16.0", "@testing-library/jest-dom": "^5.16.0",
"@types/codemirror": "^5.60.5", "@types/codemirror": "^5.60.5",
"@types/cookie": "^0.4.1", "@types/cookie": "^0.4.1",

8
pnpm-lock.yaml generated
View File

@@ -93,6 +93,7 @@ importers:
'@nuxtjs/svg': ^0.3.0 '@nuxtjs/svg': ^0.3.0
'@nuxtjs/toast': ^3.3.1 '@nuxtjs/toast': ^3.3.1
'@relmify/jest-fp-ts': ^1.1.1 '@relmify/jest-fp-ts': ^1.1.1
'@sentry/browser': ^6.16.1
'@testing-library/jest-dom': ^5.16.0 '@testing-library/jest-dom': ^5.16.0
'@types/codemirror': ^5.60.5 '@types/codemirror': ^5.60.5
'@types/cookie': ^0.4.1 '@types/cookie': ^0.4.1
@@ -259,6 +260,7 @@ importers:
'@nuxtjs/stylelint-module': 4.1.0_stylelint@14.1.0 '@nuxtjs/stylelint-module': 4.1.0_stylelint@14.1.0
'@nuxtjs/svg': 0.3.0 '@nuxtjs/svg': 0.3.0
'@relmify/jest-fp-ts': 1.1.1_fp-ts@2.11.5+io-ts@2.2.16 '@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 '@testing-library/jest-dom': 5.16.1
'@types/codemirror': 5.60.5 '@types/codemirror': 5.60.5
'@types/cookie': 0.4.1 '@types/cookie': 0.4.1
@@ -4159,7 +4161,6 @@ packages:
'@sentry/types': 6.16.1 '@sentry/types': 6.16.1
'@sentry/utils': 6.16.1 '@sentry/utils': 6.16.1
tslib: 1.14.1 tslib: 1.14.1
dev: false
/@sentry/cli/1.71.0: /@sentry/cli/1.71.0:
resolution: {integrity: sha512-Z8TzH7PkiRfjWSzjXOfPWWp6wxjr+n39Jdrt26OcInVQZM1sx/gZULrDiQZ1L2dy9Fe9AR4SF4nt2/7h2GmLQQ==} resolution: {integrity: sha512-Z8TzH7PkiRfjWSzjXOfPWWp6wxjr+n39Jdrt26OcInVQZM1sx/gZULrDiQZ1L2dy9Fe9AR4SF4nt2/7h2GmLQQ==}
@@ -4186,7 +4187,6 @@ packages:
'@sentry/types': 6.16.1 '@sentry/types': 6.16.1
'@sentry/utils': 6.16.1 '@sentry/utils': 6.16.1
tslib: 1.14.1 tslib: 1.14.1
dev: false
/@sentry/hub/6.16.1: /@sentry/hub/6.16.1:
resolution: {integrity: sha512-4PGtg6AfpqMkreTpL7ymDeQ/U1uXv03bKUuFdtsSTn/FRf9TLS4JB0KuTZCxfp1IRgAA+iFg6B784dDkT8R9eg==} resolution: {integrity: sha512-4PGtg6AfpqMkreTpL7ymDeQ/U1uXv03bKUuFdtsSTn/FRf9TLS4JB0KuTZCxfp1IRgAA+iFg6B784dDkT8R9eg==}
@@ -4195,7 +4195,6 @@ packages:
'@sentry/types': 6.16.1 '@sentry/types': 6.16.1
'@sentry/utils': 6.16.1 '@sentry/utils': 6.16.1
tslib: 1.14.1 tslib: 1.14.1
dev: false
/@sentry/integrations/6.16.1: /@sentry/integrations/6.16.1:
resolution: {integrity: sha512-YobbH3jWMRJxCeFzr8USlju1Up0EJoxaAT4y+LQQ0ZLfyfOdPX0d0iFnWMCar8gwR1nRujFS0HM0BBKY3an0LA==} resolution: {integrity: sha512-YobbH3jWMRJxCeFzr8USlju1Up0EJoxaAT4y+LQQ0ZLfyfOdPX0d0iFnWMCar8gwR1nRujFS0HM0BBKY3an0LA==}
@@ -4214,7 +4213,6 @@ packages:
'@sentry/hub': 6.16.1 '@sentry/hub': 6.16.1
'@sentry/types': 6.16.1 '@sentry/types': 6.16.1
tslib: 1.14.1 tslib: 1.14.1
dev: false
/@sentry/node/6.16.1: /@sentry/node/6.16.1:
resolution: {integrity: sha512-SeDDoug2kUxeF1D7JGPa3h5EXxKtmA01mITBPYx5xbJ0sMksnv5I5bC1SJ8arRRzq6+W1C4IEeDBQtrVCk6ixA==} resolution: {integrity: sha512-SeDDoug2kUxeF1D7JGPa3h5EXxKtmA01mITBPYx5xbJ0sMksnv5I5bC1SJ8arRRzq6+W1C4IEeDBQtrVCk6ixA==}
@@ -4247,7 +4245,6 @@ packages:
/@sentry/types/6.16.1: /@sentry/types/6.16.1:
resolution: {integrity: sha512-Wh354g30UsJ5kYJbercektGX4ZMc9MHU++1NjeN2bTMnbofEcpUDWIiKeulZEY65IC1iU+1zRQQgtYO+/hgCUQ==} resolution: {integrity: sha512-Wh354g30UsJ5kYJbercektGX4ZMc9MHU++1NjeN2bTMnbofEcpUDWIiKeulZEY65IC1iU+1zRQQgtYO+/hgCUQ==}
engines: {node: '>=6'} engines: {node: '>=6'}
dev: false
/@sentry/utils/6.16.1: /@sentry/utils/6.16.1:
resolution: {integrity: sha512-7ngq/i4R8JZitJo9Sl8PDnjSbDehOxgr1vsoMmerIsyRZ651C/8B+jVkMhaAPgSdyJ0AlE3O7DKKTP1FXFw9qw==} resolution: {integrity: sha512-7ngq/i4R8JZitJo9Sl8PDnjSbDehOxgr1vsoMmerIsyRZ651C/8B+jVkMhaAPgSdyJ0AlE3O7DKKTP1FXFw9qw==}
@@ -4255,7 +4252,6 @@ packages:
dependencies: dependencies:
'@sentry/types': 6.16.1 '@sentry/types': 6.16.1
tslib: 1.14.1 tslib: 1.14.1
dev: false
/@sentry/webpack-plugin/1.18.3: /@sentry/webpack-plugin/1.18.3:
resolution: {integrity: sha512-Qk3Jevislc5DZK0X/WwRVcOtO7iatnWARsEgTV/TuXvDN+fUDDpD/2MytAWAbpLaLy3xEB/cXGeLsbv6d1XNkQ==} resolution: {integrity: sha512-Qk3Jevislc5DZK0X/WwRVcOtO7iatnWARsEgTV/TuXvDN+fUDDpD/2MytAWAbpLaLy3xEB/cXGeLsbv6d1XNkQ==}