From 69bfd01bf039d422dd86124566a4453da61dadd8 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Fri, 5 Jan 2024 11:37:10 +0000 Subject: [PATCH 1/2] Attach authenticated user to DataDog spans. --- .../backend-core/src/middleware/authenticated.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/backend-core/src/middleware/authenticated.ts b/packages/backend-core/src/middleware/authenticated.ts index 16f658b90a..cfdb7bafed 100644 --- a/packages/backend-core/src/middleware/authenticated.ts +++ b/packages/backend-core/src/middleware/authenticated.ts @@ -15,6 +15,7 @@ import * as identity from "../context/identity" import env from "../environment" import { Ctx, EndpointMatcher, SessionCookie } from "@budibase/types" import { InvalidAPIKeyError, ErrorCode } from "../errors" +import tracer from "dd-trace" const ONE_MINUTE = env.SESSION_UPDATE_PERIOD ? parseInt(env.SESSION_UPDATE_PERIOD) @@ -166,6 +167,20 @@ export default function ( if (!authenticated) { authenticated = false } + + if (user) { + tracer.setUser({ + id: user?.id, + email: user?.email, + tenantId: user?.tenantId, + admin: user?.admin, + builder: user?.builder, + budibaseAccess: user?.budibaseAccess, + status: user?.status, + roles: user?.roles, + }) + } + // isAuthenticated is a function, so use a variable to be able to check authed state finalise(ctx, { authenticated, user, internal, version, publicEndpoint }) From b3cd74e8774fa1c5deb2ed0b97684fdd85b40f44 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Fri, 5 Jan 2024 13:49:01 +0000 Subject: [PATCH 2/2] Remove user email from DataDog user info. --- packages/backend-core/src/middleware/authenticated.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/backend-core/src/middleware/authenticated.ts b/packages/backend-core/src/middleware/authenticated.ts index cfdb7bafed..8885e5c996 100644 --- a/packages/backend-core/src/middleware/authenticated.ts +++ b/packages/backend-core/src/middleware/authenticated.ts @@ -171,7 +171,6 @@ export default function ( if (user) { tracer.setUser({ id: user?.id, - email: user?.email, tenantId: user?.tenantId, admin: user?.admin, builder: user?.builder,