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 { 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"),

View File

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

View File

@@ -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",