Tweak newly added spans to track formula processing.

This commit is contained in:
Sam Rose 2023-12-15 11:10:23 +00:00
parent 2dd07b9768
commit 7a11c5be92
No known key found for this signature in database
2 changed files with 97 additions and 99 deletions

View File

@ -15,7 +15,6 @@ 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) {
@ -23,6 +22,7 @@ export default async (ctx: UserCtx, next: any) => {
}
if (requestAppId) {
const span = tracer.scope().active()
span?.addTags({ app_id: requestAppId })
}
@ -63,9 +63,7 @@ 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
@ -119,5 +117,4 @@ export default async (ctx: UserCtx, next: any) => {
return next()
})
})
}

View File

@ -52,7 +52,8 @@ export function processFormulas<T extends Row | Row[]>(
{ dynamic, contextRows }: FormulaOpts = { dynamic: true }
): T {
return tracer.trace("processFormulas", {}, span => {
span?.addTags({ table_id: table._id })
const numRows = Array.isArray(inputRows) ? inputRows.length : 1
span?.addTags({ table_id: table._id, dynamic, numRows })
const rows = Array.isArray(inputRows) ? inputRows : [inputRows]
if (rows) {
for (let [column, schema] of Object.entries(table.schema)) {
@ -77,7 +78,7 @@ export function processFormulas<T extends Row | Row[]>(
rows[i] = {
...row,
[column]: tracer.trace("processStringSync", {}, span => {
span?.addTags({ column })
span?.addTags({ table_id: table._id, column, statis: isStatic })
return processStringSync(formula, context)
}),
}