Troubleshoot app functions
Code written in app functions, Dynatrace Workflows, or Dynatrace Notebooks is executed within the Dynatrace JavaScript runtime. This page provides an overview of the issues that you might encounter while developing functions and suggested solutions.
Serialization errors
JSON serialization errors ("Failed to serialize result to JSON") might occur when returning a value from a function.
Whenever an app function returns a value, the runtime internally calls
JSON.stringify
to convert the given value to a JSON representation. Therefore, the same
limitations
also apply when returning a value from a function:
- The returned value must not contain a circular reference.
- The returned value must not be or contain a
BigInt
. Refer to the MDN documentation on how to useBigInt
within JSON for a workaround.
Event loop behavior
The behavior of deployed Dynatrace app functions differs from other JavaScript runtimes like Bun or Deno. Deployed Dynatrace app functions always wait for the JavaScript event loop to finish. Looking at the following example, you might expect your function invocation to finish immediately rather than waiting for five seconds. It isn't the case; the function runs until the timeout is finished.
export default function () {
setTimeout(() => {}, 5000);
}
Promises
that never resolve or reject can behave in a similar way. You might encounter issues with third-party packages that do work in the background if those background tasks are not gracefully shut down.
In such cases, your Dynatrace app function will appear stuck and eventually run into a timeout error if the event loop doesn't terminate.