Also instrument appId

This commit is contained in:
Sam Rose 2023-12-14 17:26:48 +00:00
parent 899b6707e7
commit 5b880f1d9b
No known key found for this signature in database
1 changed files with 92 additions and 83 deletions

View File

@ -12,14 +12,20 @@ import { getCachedSelf } from "../utilities/global"
import env from "../environment"
import { isWebhookEndpoint } from "./utils"
import { UserCtx, ContextUser } from "@budibase/types"
import tracer from "dd-trace"
export default async (ctx: UserCtx, next: any) => {
return tracer.trace("currentapp middleware", {}, async span => {
// try to get the appID from the request
let requestAppId = await utils.getAppIdFromCtx(ctx)
if (!requestAppId) {
return next()
}
if (requestAppId) {
span?.addTags({ appId: requestAppId })
}
// deny access to application preview
if (!env.isTest()) {
if (
@ -57,7 +63,9 @@ export default async (ctx: UserCtx, next: any) => {
roleId = roleHeader
// Delete admin and builder flags so that the specified role is honoured
ctx.user = users.removePortalUserPermissions(ctx.user) as ContextUser
ctx.user = users.removePortalUserPermissions(
ctx.user
) as ContextUser
}
} catch (error) {
// Swallow error and do nothing
@ -111,4 +119,5 @@ export default async (ctx: UserCtx, next: any) => {
return next()
})
})
}