Merge pull request #12998 from Budibase/chore/trace-js
Trace scriptRunner
This commit is contained in:
commit
b0bffc2222
|
@ -1,3 +1,4 @@
|
||||||
|
import tracer, { Span } from "dd-trace"
|
||||||
import env from "../environment"
|
import env from "../environment"
|
||||||
import { IsolatedVM } from "../jsRunner/vm"
|
import { IsolatedVM } from "../jsRunner/vm"
|
||||||
|
|
||||||
|
@ -7,7 +8,11 @@ class ScriptRunner {
|
||||||
private code: string
|
private code: string
|
||||||
private vm: IsolatedVM
|
private vm: IsolatedVM
|
||||||
|
|
||||||
|
private tracerSpan: Span
|
||||||
|
|
||||||
constructor(script: string, context: any, { parseBson = false } = {}) {
|
constructor(script: string, context: any, { parseBson = false } = {}) {
|
||||||
|
this.tracerSpan = tracer.startSpan("scriptRunner", { tags: { parseBson } })
|
||||||
|
|
||||||
this.code = `(() => {${script}})();`
|
this.code = `(() => {${script}})();`
|
||||||
this.vm = new IsolatedVM({
|
this.vm = new IsolatedVM({
|
||||||
memoryLimit: env.JS_RUNNER_MEMORY_LIMIT,
|
memoryLimit: env.JS_RUNNER_MEMORY_LIMIT,
|
||||||
|
@ -20,7 +25,15 @@ class ScriptRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
execute() {
|
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
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue