Skip to content

Commit

Permalink
Fix Sentry client setup
Browse files Browse the repository at this point in the history
  • Loading branch information
obulat committed Dec 20, 2024
1 parent 1086896 commit 8588c4c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
4 changes: 3 additions & 1 deletion frontend/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ export default defineNuxtConfig({
sentry: {
dsn: "",
environment: "local",
// Release is a build time variable, and as such, is defined in app.config.ts
},
// Release is a build time variable. However, due to the way Sentry is set up, setting it in app.config.ts
// does not work, so we set it here using `process.env` to bake in the value at build time.
sentryRelease: process.env.SEMANTIC_VERSION,
plausible: {
ignoredHostnames: ["localhost", "staging.openverse.org"],
logIgnoredEvents: true,
Expand Down
5 changes: 3 additions & 2 deletions frontend/sentry.client.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useAppConfig, useRuntimeConfig } from "#imports"
import { useRuntimeConfig } from "#imports"

import * as Sentry from "@sentry/nuxt"

Sentry.init({
dsn: useRuntimeConfig().public.sentry.dsn,
environment: useRuntimeConfig().public.sentry.environment,
release: useAppConfig().semanticVersion,
release: useRuntimeConfig().public.sentryRelease,
ignoreErrors: [
// Can be safely ignored, @see https://github.com/WICG/resize-observer/issues/38
/ResizeObserver loop limit exceeded/i,
Expand All @@ -14,3 +14,4 @@ Sentry.init({
tracesSampleRate: 1.0,
})
Sentry.setContext("render context", { platform: "client" })
Sentry.setTag("platform", "client")
1 change: 1 addition & 0 deletions frontend/sentry.server.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Sentry.init({
tracesSampleRate: 1.0,
})
Sentry.setContext("render context", { platform: "server" })
Sentry.setTag("platform", "server")
1 change: 1 addition & 0 deletions frontend/server/api/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const getSources = defineCachedFunction(
...getProxyRequestHeaders(event),
...userAgentHeader,
},
params: { format: "json" },
}
)
},
Expand Down
5 changes: 0 additions & 5 deletions frontend/src/app.config.ts

This file was deleted.

17 changes: 15 additions & 2 deletions frontend/src/pages/preferences.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { definePageMeta } from "#imports"
import { definePageMeta, useNuxtApp } from "#imports"
import { computed } from "vue"
import { SWITCHABLE, ON, OFF } from "#shared/constants/feature-flag"
Expand Down Expand Up @@ -51,7 +51,11 @@ const featureGroups = computed(() => {
return featureFlagStore.getFeatureGroups()
})
const doneHydrating = computed(() => useHydrating())
const { doneHydrating } = useHydrating()
const captureException = () => {
useNuxtApp().$captureException(new Error("Test Sentry Exception"))
}
</script>

<template>
Expand Down Expand Up @@ -133,5 +137,14 @@ const doneHydrating = computed(() => useHydrating())

<h2>{{ $t("prefPage.storeState") }}</h2>
<pre><code>{{ flags }}</code></pre>

<!-- eslint-disable @intlify/vue-i18n/no-raw-text -->
<VButton
v-if="$config.public.sentry.environment === 'local'"
variant="bordered-gray"
size="medium"
@click="captureException"
>Capture Sentry Exception</VButton
><!-- eslint-enable -->
</VContentPage>
</template>

0 comments on commit 8588c4c

Please sign in to comment.