1
0
Fork 0
mirror of synced 2024-07-08 07:46:10 +12:00

Merge pull request #12587 from Budibase/instrument-formula-processing

Instrument formula processing in DataDog.
This commit is contained in:
Sam Rose 2023-12-15 09:31:05 +00:00 committed by GitHub
commit 2dd07b9768
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 123 additions and 105 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({ app_id: 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()
})
})
}

View file

@ -11,6 +11,7 @@ import {
Row,
Table,
} from "@budibase/types"
import tracer from "dd-trace"
interface FormulaOpts {
dynamic?: boolean
@ -50,8 +51,10 @@ export function processFormulas<T extends Row | Row[]>(
inputRows: T,
{ dynamic, contextRows }: FormulaOpts = { dynamic: true }
): T {
return tracer.trace("processFormulas", {}, span => {
span?.addTags({ table_id: table._id })
const rows = Array.isArray(inputRows) ? inputRows : [inputRows]
if (rows)
if (rows) {
for (let [column, schema] of Object.entries(table.schema)) {
if (schema.type !== FieldTypes.FORMULA) {
continue
@ -70,13 +73,19 @@ export function processFormulas<T extends Row | Row[]>(
for (let i = 0; i < rows.length; i++) {
let row = rows[i]
let context = contextRows ? contextRows[i] : row
let formula = schema.formula
rows[i] = {
...row,
[column]: processStringSync(schema.formula, context),
[column]: tracer.trace("processStringSync", {}, span => {
span?.addTags({ column })
return processStringSync(formula, context)
}),
}
}
}
}
return Array.isArray(inputRows) ? rows : rows[0]
})
}
/**