From 141481df3aba2f442550f7a0812d718389194445 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 13 Dec 2021 17:41:11 +0100 Subject: [PATCH] web: send sentry-trace header in API requests Signed-off-by: Jens Langhammer --- web/src/api/Config.ts | 2 ++ web/src/api/Sentry.ts | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/web/src/api/Config.ts b/web/src/api/Config.ts index a8875d224..01568ae6d 100644 --- a/web/src/api/Config.ts +++ b/web/src/api/Config.ts @@ -3,6 +3,7 @@ import { getCookie } from "../utils"; import { APIMiddleware } from "../elements/notifications/APIDrawer"; import { MessageMiddleware } from "../elements/messages/Middleware"; import { VERSION } from "../constants"; +import { getMetaContent } from "@sentry/tracing/dist/browser/browsertracing"; export class LoggingMiddleware implements Middleware { @@ -53,6 +54,7 @@ export const DEFAULT_CONFIG = new Configuration({ basePath: process.env.AK_API_BASE_PATH + "/api/v3", headers: { "X-CSRFToken": getCookie("authentik_csrf"), + "sentry-trace": getMetaContent("sentry-trace") || "", }, middleware: [ new APIMiddleware(), diff --git a/web/src/api/Sentry.ts b/web/src/api/Sentry.ts index 210f54e40..4761d5524 100644 --- a/web/src/api/Sentry.ts +++ b/web/src/api/Sentry.ts @@ -27,7 +27,10 @@ export function configureSentry(canDoPpi: boolean = false): Promise { ], tracesSampleRate: config.errorReporting.tracesSampleRate, environment: config.errorReporting.environment, - beforeSend: async (event: Sentry.Event, hint: Sentry.EventHint): Promise => { + beforeSend: async (event: Sentry.Event, hint: Sentry.EventHint | undefined): Promise => { + if (!hint) { + return event; + } if (hint.originalException instanceof SentryIgnoredError) { return null; }