Merge pull request #12725 from Budibase/run-js-traces
Add some more spans to the JS runner
This commit is contained in:
commit
84d9a69cdf
|
@ -12,9 +12,13 @@ export function init() {
|
|||
const perRequestLimit = env.JS_PER_REQUEST_TIME_LIMIT_MS
|
||||
let track: TrackerFn = f => f()
|
||||
if (perRequestLimit) {
|
||||
tracer.trace<any>("runJS.setupTracker", {}, span => {
|
||||
const bbCtx = context.getCurrentContext()
|
||||
if (bbCtx) {
|
||||
if (!bbCtx.jsExecutionTracker) {
|
||||
span?.addTags({
|
||||
createdExecutionTracker: true,
|
||||
})
|
||||
bbCtx.jsExecutionTracker =
|
||||
timers.ExecutionTimeTracker.withLimit(perRequestLimit)
|
||||
}
|
||||
|
@ -27,22 +31,33 @@ export function init() {
|
|||
// We call checkLimit() here to prevent paying the cost of creating
|
||||
// a new VM context below when we don't need to.
|
||||
bbCtx.jsExecutionTracker.checkLimit()
|
||||
track = bbCtx.jsExecutionTracker.track.bind(bbCtx.jsExecutionTracker)
|
||||
track = bbCtx.jsExecutionTracker.track.bind(
|
||||
bbCtx.jsExecutionTracker
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
ctx = {
|
||||
ctx = tracer.trace("runJS.ctxClone", {}, span => {
|
||||
return {
|
||||
...ctx,
|
||||
alert: undefined,
|
||||
setInterval: undefined,
|
||||
setTimeout: undefined,
|
||||
}
|
||||
})
|
||||
|
||||
tracer.trace("runJS.vm.createContext", {}, span => {
|
||||
vm.createContext(ctx)
|
||||
})
|
||||
|
||||
return track(() =>
|
||||
tracer.trace("runJS.vm.runInNewContext", {}, span =>
|
||||
vm.runInNewContext(js, ctx, {
|
||||
timeout: env.JS_PER_EXECUTION_TIME_LIMIT_MS,
|
||||
})
|
||||
)
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue