web: ignore module load errors

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-07-01 16:49:37 +02:00
parent 90e3ae9457
commit e758c434ea
2 changed files with 60 additions and 60 deletions

View File

@ -74,7 +74,7 @@ class ConfigView(APIView):
config = ConfigSerializer(
{
"error_reporting": {
"enabled": CONFIG.y("error_reporting.enabled") and not settings.DEBUG,
"enabled": CONFIG.y("error_reporting.enabled"),
"environment": CONFIG.y("error_reporting.environment"),
"send_pii": CONFIG.y("error_reporting.send_pii"),
"traces_sample_rate": float(CONFIG.y("error_reporting.sample_rate", 0.4)),

View File

@ -3,7 +3,7 @@ import { VERSION } from "@goauthentik/web/constants";
import * as Sentry from "@sentry/browser";
import { Integrations } from "@sentry/tracing";
import { Config } from "@goauthentik/api";
import { Config, ResponseError } from "@goauthentik/api";
import { config } from "./Config";
import { me } from "./Users";
@ -11,14 +11,15 @@ import { me } from "./Users";
export const TAG_SENTRY_COMPONENT = "authentik.component";
export const TAG_SENTRY_CAPABILITIES = "authentik.capabilities";
export function configureSentry(canDoPpi = false): Promise<Config> {
return config().then((config) => {
if (config.errorReporting.enabled) {
export async function configureSentry(canDoPpi = false): Promise<Config> {
const cfg = await config();
if (cfg.errorReporting.enabled) {
Sentry.init({
dsn: "https://a579bb09306d4f8b8d8847c052d3a1d3@sentry.beryju.org/8",
ignoreErrors: [
/network/gi,
/fetch/gi,
/module/gi,
// Error on edge on ios,
// https://stackoverflow.com/questions/69261499/what-is-instantsearchsdkjsbridgeclearhighlight
/instantSearchSDKJSBridgeClearHighlight/gi,
@ -32,8 +33,8 @@ export function configureSentry(canDoPpi = false): Promise<Config> {
tracingOrigins: [window.location.host, "localhost"],
}),
],
tracesSampleRate: config.errorReporting.tracesSampleRate,
environment: config.errorReporting.environment,
tracesSampleRate: cfg.errorReporting.tracesSampleRate,
environment: cfg.errorReporting.environment,
beforeSend: async (
event: Sentry.Event,
hint: Sentry.EventHint | undefined,
@ -45,7 +46,7 @@ export function configureSentry(canDoPpi = false): Promise<Config> {
return null;
}
if (
hint.originalException instanceof Response ||
hint.originalException instanceof ResponseError ||
hint.originalException instanceof DOMException
) {
return null;
@ -53,14 +54,14 @@ export function configureSentry(canDoPpi = false): Promise<Config> {
return event;
},
});
Sentry.setTag(TAG_SENTRY_CAPABILITIES, config.capabilities.join(","));
Sentry.setTag(TAG_SENTRY_CAPABILITIES, cfg.capabilities.join(","));
if (window.location.pathname.includes("if/")) {
Sentry.setTag(TAG_SENTRY_COMPONENT, `web/${currentInterface()}`);
Sentry.configureScope((scope) =>
scope.setTransactionName(`authentik.web.if.${currentInterface()}`),
);
}
if (config.errorReporting.sendPii && canDoPpi) {
if (cfg.errorReporting.sendPii && canDoPpi) {
me().then((user) => {
Sentry.setUser({ email: user.user.email });
console.debug("authentik/config: Sentry with PII enabled.");
@ -69,8 +70,7 @@ export function configureSentry(canDoPpi = false): Promise<Config> {
console.debug("authentik/config: Sentry enabled.");
}
}
return config;
});
return cfg;
}
// Get the interface name from URL