Attach authenticated user to DataDog spans.

This commit is contained in:
Sam Rose 2024-01-05 11:37:10 +00:00
parent 66f040a295
commit 69bfd01bf0
No known key found for this signature in database
1 changed files with 15 additions and 0 deletions

View File

@ -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 })