Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Sentry client setup #5297

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"npm-run-all2": "^7.0.0",
"nuxt": "^3.14.1592",
"rimraf": "^6.0.1",
"storybook": "^8.3.6",
"storybook": "8.3.6",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI was failing because it was using the latest Storybook version

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a weird error to have!

"talkback": "^4.2.0",
"typescript": "5.6.3",
"vitest": "^2.1.4",
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")
4 changes: 3 additions & 1 deletion frontend/server/api/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ const getSources = defineCachedFunction(
async (mediaType: SupportedMediaType, event: H3Event) => {
const apiUrl = useRuntimeConfig(event).public.apiUrl

consola.info(`Fetching sources for ${mediaType} media`)
consola.info(`Fetching ${mediaType} sources.`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the logs more grammatically correct 😁.


return await $fetch<MediaProvider[]>(
`${apiUrl}v1/${mediaSlug(mediaType)}/stats/`,
{
headers: {
...getProxyRequestHeaders(event),
...userAgentHeader,
"Content-Type": "application/json",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the headers to handle the fluke when sometimes the API returns HTML response.

Accept: "application/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>
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading