Instrument formula processing in DataDog.

This commit is contained in:
Sam Rose 2023-12-14 16:52:47 +00:00
parent e7606125b6
commit 0d3ea23301
No known key found for this signature in database
1 changed files with 30 additions and 22 deletions

View File

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