Merge branch 'master' into remove-vm2-from-stringtemplates

This commit is contained in:
Adria Navarro 2024-02-09 13:41:15 +01:00 committed by GitHub
commit 72802961ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View File

@ -1,5 +1,5 @@
{
"version": "2.18.0",
"version": "2.18.1",
"npmClient": "yarn",
"packages": [
"packages/*",

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,9 +25,17 @@ class ScriptRunner {
}
execute() {
const result = tracer.trace(
"scriptRunner.execute",
{ childOf: this.tracerSpan },
() => {
const result = this.vm.execute(this.code)
return result
}
)
this.tracerSpan.finish()
return result
}
}
export default ScriptRunner