From c55f2ad10acc3e9414dadb19f85ed132257cb405 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 15 May 2021 19:53:43 +0200 Subject: [PATCH] root: set additional sentry tags Signed-off-by: Jens Langhammer --- authentik/root/settings.py | 6 ++++++ web/src/api/Sentry.ts | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/authentik/root/settings.py b/authentik/root/settings.py index 5060215fe..0c5eff2fa 100644 --- a/authentik/root/settings.py +++ b/authentik/root/settings.py @@ -20,6 +20,7 @@ from time import time import structlog from celery.schedules import crontab from sentry_sdk import init as sentry_init +from sentry_sdk.api import set_tag from sentry_sdk.integrations.celery import CeleryIntegration from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.integrations.redis import RedisIntegration @@ -354,6 +355,11 @@ if _ERROR_REPORTING: environment=CONFIG.y("error_reporting.environment", "customer"), send_default_pii=CONFIG.y_bool("error_reporting.send_pii", False), ) + set_tag("authentik:build_hash", os.environ.get(ENV_GIT_HASH_KEY, "")) + set_tag( + "authentik:env", "kubernetes" if "KUBERNETES_PORT" in os.environ else "compose" + ) + set_tag("authentik:component", "backend") j_print( "Error reporting is enabled", env=CONFIG.y("error_reporting.environment", "customer"), diff --git a/web/src/api/Sentry.ts b/web/src/api/Sentry.ts index 7f0f39847..6668d862c 100644 --- a/web/src/api/Sentry.ts +++ b/web/src/api/Sentry.ts @@ -6,7 +6,9 @@ import { me } from "./Users"; import { config } from "./Config"; import { Config } from "authentik-api"; -export function configureSentry(canDoPpi: boolean = false): Promise { +export const TAG_SENTRY_COMPONENT = "authentik:component"; + +export function configureSentry(canDoPpi: boolean = false, tags: { [key: string]: string; } = {}): Promise { return config().then((config) => { if (config.errorReportingEnabled) { Sentry.init({ @@ -51,6 +53,12 @@ export function configureSentry(canDoPpi: boolean = false): Promise { return event; }, }); + Sentry.setTags(tags); + 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}`); + } console.debug("authentik/config: Sentry enabled."); if (config.errorReportingSendPii && canDoPpi) { me().then(user => {