PronounsPage/plugins/sentry.client.ts
Adaline Simonian 23a3862ca0
test: introduce snapshot-based smoke tests
- Adds a new test suite with Docker-based smoke tests for all locales.
  Can be run using the ./smoketest.sh script.
- Replaces all calls to Math.random() with a new helper that returns 0.5
  in snapshot testing mode, ensuring deterministic snapshots.
- Similarly replaces all calls to new Date() and Date.now() with new
  helpers that return a fixed date in snapshot testing mode.
- Replaces checks against NODE_ENV with APP_ENV, to ensure that the
  bundles can be built with Nuxt for testing without losing code that
  would otherwise be stripped out by production optimizations.
- Adds a database init script that can be used to initialize the
  database with a single admin user and a long-lived JWT token for use
  in automation tests.
- Adds a JWT decoding/encoding CLI tool for debugging JWTs.

Note: Snapshots are not checked in, and must be generated manually. See
test/__snapshots__/.gitignore for more information.
2025-02-02 23:11:19 -08:00

74 lines
2.7 KiB
TypeScript

import * as Sentry from '@sentry/vue';
import { defineNuxtPlugin, useRouter, useRuntimeConfig } from 'nuxt/app';
export default defineNuxtPlugin((nuxtApp) => {
const router = useRouter();
const { public: { env, sentry } } = useRuntimeConfig();
if (!sentry.dsn) {
return;
}
if (import.meta.env?.APP_ENV !== 'development') {
// remove original error handler as this causes full-screen error pages
nuxtApp.vueApp.config.errorHandler = undefined;
}
Sentry.init({
app: nuxtApp.vueApp,
dsn: sentry.dsn,
environment: env,
integrations: [
Sentry.browserTracingIntegration({ router, enableInp: true }),
],
tracesSampleRate: 0.1,
attachStacktrace: true,
tunnel: '/api/sentry/tunnel',
beforeSend(event) {
const denyUrls = [
'chrome-extension://',
'moz-extension://',
'webkit-masked-url://',
'https://s0.2mdn.net',
'https://j.adlooxtracking.com',
'https://c.amazon-adsystem.com',
'https://assets.a-mo.net',
'https://btloader.com',
'https://challenges.cloudflare.com',
'https://static.criteo.net',
'https://securepubads.g.doubleclick.net',
'https://cdn.flashtalking.com',
'https://ajs-assets.ftstatic.com',
'https://cdn.fuseplatform.net',
'https://cmp.inmobi.com',
'https://cdn.js7k.com',
'https://z.moatads.com',
'https://ced-ns.sascdn.com',
'https://a.teads.tv',
'https://s.yimg.com',
];
// filter out exceptions originating from third party
for (const exception of event.exception?.values || []) {
for (const frame of exception.stacktrace?.frames || []) {
const originatingFromThirdParty = denyUrls.some((denyUrl) => {
return frame.abs_path?.startsWith(denyUrl) || frame.filename?.startsWith(denyUrl);
});
if (originatingFromThirdParty) {
return null;
}
}
}
// do not send user information as Sentry somehow automatically detects username, email and user id
// https://docs.sentry.io/platforms/javascript/data-management/sensitive-data/
delete event.user;
return event;
},
beforeSendTransaction(event) {
// see comment on beforeSend
delete event.user;
return event;
},
});
});