2022-09-14 22:05:21 +00:00
|
|
|
import { config } from "@goauthentik/common/api/config";
|
|
|
|
import { VERSION } from "@goauthentik/common/constants";
|
|
|
|
import { SentryIgnoredError } from "@goauthentik/common/errors";
|
|
|
|
import { me } from "@goauthentik/common/users";
|
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
|
|
|
|
2022-07-01 14:49:37 +00:00
|
|
|
import { Config, ResponseError } from "@goauthentik/api";
|
2021-04-13 16:35:26 +00:00
|
|
|
|
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-07-01 14:49:37 +00:00
|
|
|
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,
|
|
|
|
// Seems to be an issue in Safari and Firefox
|
|
|
|
/MutationObserver.observe/gi,
|
|
|
|
],
|
|
|
|
release: `authentik@${VERSION}`,
|
|
|
|
tunnel: "/api/v3/sentry/",
|
|
|
|
integrations: [
|
|
|
|
new Integrations.BrowserTracing({
|
|
|
|
tracingOrigins: [window.location.host, "localhost"],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
tracesSampleRate: cfg.errorReporting.tracesSampleRate,
|
|
|
|
environment: cfg.errorReporting.environment,
|
|
|
|
beforeSend: async (
|
|
|
|
event: Sentry.Event,
|
|
|
|
hint: Sentry.EventHint | undefined,
|
|
|
|
): Promise<Sentry.Event | null> => {
|
|
|
|
if (!hint) {
|
2021-04-13 16:35:26 +00:00
|
|
|
return event;
|
2022-07-01 14:49:37 +00:00
|
|
|
}
|
|
|
|
if (hint.originalException instanceof SentryIgnoredError) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
hint.originalException instanceof ResponseError ||
|
|
|
|
hint.originalException instanceof DOMException
|
|
|
|
) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return event;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
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 (cfg.errorReporting.sendPii && canDoPpi) {
|
|
|
|
me().then((user) => {
|
|
|
|
Sentry.setUser({ email: user.user.email });
|
|
|
|
console.debug("authentik/config: Sentry with PII enabled.");
|
2021-04-13 16:35:26 +00:00
|
|
|
});
|
2022-07-01 14:49:37 +00:00
|
|
|
} else {
|
|
|
|
console.debug("authentik/config: Sentry enabled.");
|
2021-04-13 16:35:26 +00:00
|
|
|
}
|
2022-07-01 14:49:37 +00:00
|
|
|
}
|
|
|
|
return cfg;
|
2021-04-13 16:35:26 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|