Merge pull request #12998 from Budibase/chore/trace-js

Trace scriptRunner
This commit is contained in:
Adria Navarro 2024-02-09 13:29:49 +01:00 committed by GitHub
commit b0bffc2222
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import tracer, { Span } from "dd-trace"
import env from "../environment"
import { IsolatedVM } from "../jsRunner/vm"
@ -7,7 +8,11 @@ class ScriptRunner {
private code: string
private vm: IsolatedVM
private tracerSpan: Span
constructor(script: string, context: any, { parseBson = false } = {}) {
this.tracerSpan = tracer.startSpan("scriptRunner", { tags: { parseBson } })
this.code = `(() => {${script}})();`
this.vm = new IsolatedVM({
memoryLimit: env.JS_RUNNER_MEMORY_LIMIT,
@ -20,7 +25,15 @@ class ScriptRunner {
}
execute() {
const result = this.vm.execute(this.code)
const result = tracer.trace(
"scriptRunner.execute",
{ childOf: this.tracerSpan },
() => {
const result = this.vm.execute(this.code)
return result
}
)
this.tracerSpan.finish()
return result
}
}