2022-06-27 19:31:54 +00:00
|
|
|
import { SentryIgnoredError } from "@goauthentik/web/common/errors";
|
|
|
|
import { VERSION } from "@goauthentik/web/constants";
|
2021-04-13 16:35:26 +00:00
|
|
|
import * as Sentry from "@sentry/browser";
|
|
|
|
import { Integrations } from "@sentry/tracing";
|
2022-06-27 19:31:54 +00:00
|
|
|
|
2021-08-15 19:32:28 +00:00
|
|
|
import { Config } from "@goauthentik/api";
|
2021-04-13 16:35:26 +00:00
|
|
|
|
2022-06-27 19:31:54 +00:00
|
|
|
import { config } from "./Config";
|
|
|
|
import { me } from "./Users";
|
|
|
|
|
2021-06-06 12:51:43 +00:00
|
|
|
export const TAG_SENTRY_COMPONENT = "authentik.component";
|
2021-06-13 12:08:39 +00:00
|
|
|
export const TAG_SENTRY_CAPABILITIES = "authentik.capabilities";
|
2021-05-15 17:53:43 +00:00
|
|
|
|
2022-06-01 09:15:52 +00:00
|
|
|
export function configureSentry(canDoPpi = false): Promise<Config> {
|
2021-04-22 21:49:30 +00:00
|
|
|
return config().then((config) => {
|
2021-11-29 12:58:00 +00:00
|
|
|
if (config.errorReporting.enabled) {
|
2021-04-13 16:35:26 +00:00
|
|
|
Sentry.init({
|
|
|
|
dsn: "https://a579bb09306d4f8b8d8847c052d3a1d3@sentry.beryju.org/8",
|
2021-09-09 17:58:43 +00:00
|
|
|
ignoreErrors: [
|
2022-06-27 19:31:54 +00:00
|
|
|
/network/gi,
|
|
|
|
/fetch/gi,
|
2021-12-18 13:49:25 +00:00
|
|
|
// Error on edge on ios,
|
|
|
|
// https://stackoverflow.com/questions/69261499/what-is-instantsearchsdkjsbridgeclearhighlight
|
2022-06-27 19:31:54 +00:00
|
|
|
/instantSearchSDKJSBridgeClearHighlight/gi,
|
2022-01-17 21:05:23 +00:00
|
|
|
// Seems to be an issue in Safari and Firefox
|
2022-06-27 19:31:54 +00:00
|
|
|
/MutationObserver.observe/gi,
|
2021-09-09 17:58:43 +00:00
|
|
|
],
|
2021-04-13 16:35:26 +00:00
|
|
|
release: `authentik@${VERSION}`,
|
2021-09-02 15:40:02 +00:00
|
|
|
tunnel: "/api/v3/sentry/",
|
2021-04-13 16:35:26 +00:00
|
|
|
integrations: [
|
|
|
|
new Integrations.BrowserTracing({
|
|
|
|
tracingOrigins: [window.location.host, "localhost"],
|
|
|
|
}),
|
|
|
|
],
|
2021-11-29 12:58:00 +00:00
|
|
|
tracesSampleRate: config.errorReporting.tracesSampleRate,
|
|
|
|
environment: config.errorReporting.environment,
|
2022-06-27 19:31:54 +00:00
|
|
|
beforeSend: async (
|
|
|
|
event: Sentry.Event,
|
|
|
|
hint: Sentry.EventHint | undefined,
|
|
|
|
): Promise<Sentry.Event | null> => {
|
2021-12-13 16:41:11 +00:00
|
|
|
if (!hint) {
|
|
|
|
return event;
|
|
|
|
}
|
2021-04-13 16:35:26 +00:00
|
|
|
if (hint.originalException instanceof SentryIgnoredError) {
|
|
|
|
return null;
|
|
|
|
}
|
2022-06-27 19:31:54 +00:00
|
|
|
if (
|
|
|
|
hint.originalException instanceof Response ||
|
|
|
|
hint.originalException instanceof DOMException
|
|
|
|
) {
|
2021-07-28 10:26:50 +00:00
|
|
|
return null;
|
2021-04-20 15:32:38 +00:00
|
|
|
}
|
2021-04-13 16:35:26 +00:00
|
|
|
return event;
|
|
|
|
},
|
|
|
|
});
|
2021-06-13 12:08:39 +00:00
|
|
|
Sentry.setTag(TAG_SENTRY_CAPABILITIES, config.capabilities.join(","));
|
2021-05-15 17:53:43 +00:00
|
|
|
if (window.location.pathname.includes("if/")) {
|
2021-12-24 19:04:21 +00:00
|
|
|
Sentry.setTag(TAG_SENTRY_COMPONENT, `web/${currentInterface()}`);
|
2022-06-27 19:31:54 +00:00
|
|
|
Sentry.configureScope((scope) =>
|
|
|
|
scope.setTransactionName(`authentik.web.if.${currentInterface()}`),
|
|
|
|
);
|
2021-05-15 17:53:43 +00:00
|
|
|
}
|
2021-11-29 12:58:00 +00:00
|
|
|
if (config.errorReporting.sendPii && canDoPpi) {
|
2022-06-27 19:31:54 +00:00
|
|
|
me().then((user) => {
|
2021-04-13 16:35:26 +00:00
|
|
|
Sentry.setUser({ email: user.user.email });
|
|
|
|
console.debug("authentik/config: Sentry with PII enabled.");
|
|
|
|
});
|
2021-10-20 09:46:02 +00:00
|
|
|
} else {
|
|
|
|
console.debug("authentik/config: Sentry enabled.");
|
2021-04-13 16:35:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return config;
|
|
|
|
});
|
|
|
|
}
|
2021-12-24 19:04:21 +00:00
|
|
|
|
|
|
|
// Get the interface name from URL
|
|
|
|
export function currentInterface(): string {
|
|
|
|
const pathMatches = window.location.pathname.match(/.+if\/(\w+)\//);
|
|
|
|
let currentInterface = "unknown";
|
|
|
|
if (pathMatches && pathMatches.length >= 2) {
|
|
|
|
currentInterface = pathMatches[1];
|
|
|
|
}
|
|
|
|
return currentInterface;
|
|
|
|
}
|