2021-04-13 16:35:26 +00:00
|
|
|
import * as Sentry from "@sentry/browser";
|
|
|
|
import { Integrations } from "@sentry/tracing";
|
|
|
|
import { VERSION } from "../constants";
|
|
|
|
import { SentryIgnoredError } from "../common/errors";
|
|
|
|
import { me } from "./Users";
|
2021-04-22 21:49:30 +00:00
|
|
|
import { config } from "./Config";
|
2021-08-15 19:32:28 +00:00
|
|
|
import { Config } 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
|
|
|
|
2021-06-13 12:08:39 +00:00
|
|
|
export function configureSentry(canDoPpi: boolean = 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: [
|
2021-11-28 14:17:27 +00:00
|
|
|
/network/ig,
|
|
|
|
/fetch/ig,
|
2021-12-18 13:49:25 +00:00
|
|
|
// Error on edge on ios,
|
|
|
|
// https://stackoverflow.com/questions/69261499/what-is-instantsearchsdkjsbridgeclearhighlight
|
|
|
|
/instantSearchSDKJSBridgeClearHighlight/ig,
|
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,
|
2021-12-13 16:41:11 +00:00
|
|
|
beforeSend: async (event: Sentry.Event, hint: Sentry.EventHint | undefined): Promise<Sentry.Event | null> => {
|
|
|
|
if (!hint) {
|
|
|
|
return event;
|
|
|
|
}
|
2021-04-13 16:35:26 +00:00
|
|
|
if (hint.originalException instanceof SentryIgnoredError) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-08-21 12:17:31 +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/")) {
|
|
|
|
// Get the interface name from URL
|
2021-12-13 20:03:30 +00:00
|
|
|
const pathMatches = window.location.pathname.match(/.+if\/(\w+)\//);
|
2021-12-13 20:44:37 +00:00
|
|
|
let currentInterface = "unknown";
|
2021-12-13 20:03:30 +00:00
|
|
|
if (pathMatches && pathMatches.length >= 2) {
|
|
|
|
currentInterface = pathMatches[1];
|
|
|
|
}
|
|
|
|
Sentry.setTag(TAG_SENTRY_COMPONENT, `web/${currentInterface}`);
|
|
|
|
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) {
|
2021-04-13 16:35:26 +00:00
|
|
|
me().then(user => {
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|