Instrument formula processing in DataDog.
This commit is contained in:
parent
e7606125b6
commit
0d3ea23301
|
@ -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,33 +51,40 @@ export function processFormulas<T extends Row | Row[]>(
|
||||||
inputRows: T,
|
inputRows: T,
|
||||||
{ dynamic, contextRows }: FormulaOpts = { dynamic: true }
|
{ dynamic, contextRows }: FormulaOpts = { dynamic: true }
|
||||||
): T {
|
): T {
|
||||||
const rows = Array.isArray(inputRows) ? inputRows : [inputRows]
|
return tracer.trace("processFormulas", {}, span => {
|
||||||
if (rows)
|
span?.addTags({ tableId: table._id })
|
||||||
for (let [column, schema] of Object.entries(table.schema)) {
|
const rows = Array.isArray(inputRows) ? inputRows : [inputRows]
|
||||||
if (schema.type !== FieldTypes.FORMULA) {
|
if (rows) {
|
||||||
continue
|
for (let [column, schema] of Object.entries(table.schema)) {
|
||||||
}
|
if (schema.type !== FieldTypes.FORMULA) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
const isStatic = schema.formulaType === FormulaTypes.STATIC
|
const isStatic = schema.formulaType === FormulaTypes.STATIC
|
||||||
|
|
||||||
if (
|
if (
|
||||||
schema.formula == null ||
|
schema.formula == null ||
|
||||||
(dynamic && isStatic) ||
|
(dynamic && isStatic) ||
|
||||||
(!dynamic && !isStatic)
|
(!dynamic && !isStatic)
|
||||||
) {
|
) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// iterate through rows and process formula
|
// iterate through rows and process formula
|
||||||
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
|
||||||
rows[i] = {
|
let formula = schema.formula
|
||||||
...row,
|
rows[i] = {
|
||||||
[column]: processStringSync(schema.formula, context),
|
...row,
|
||||||
|
[column]: tracer.trace("processStringSync", {}, () =>
|
||||||
|
processStringSync(formula, context)
|
||||||
|
),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Array.isArray(inputRows) ? rows : rows[0]
|
return Array.isArray(inputRows) ? rows : rows[0]
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue