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-04-13 16:35:26 +00:00
|
|
|
if (config.errorReportingEnabled) {
|
|
|
|
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-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"],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
tracesSampleRate: 0.6,
|
|
|
|
environment: config.errorReportingEnvironment,
|
2021-04-20 15:32:38 +00:00
|
|
|
beforeSend: async (event: Sentry.Event, hint: Sentry.EventHint): Promise<Sentry.Event | null> => {
|
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
|
|
|
|
const intf = window.location.pathname.replace(/.+if\/(.+)\//, "$1");
|
|
|
|
Sentry.setTag(TAG_SENTRY_COMPONENT, `web/${intf}`);
|
|
|
|
}
|
2021-04-26 15:45:09 +00:00
|
|
|
if (config.errorReportingSendPii && 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;
|
|
|
|
});
|
|
|
|
}
|