11 Jun 2024 11:25 AM
After deploying my appFn to dynatrace platform I've received this error:
An error of type UNCAUGHT_EXCEPTION occurred in an imported library: SyntaxError: Unexpected end of JSON input
at parse (<anonymous>)
at packageData (ext:deno_fetch/22_body.js:370:14)
at consumeBody (ext:deno_fetch/22_body.js:247:12)
at eventLoopTick (ext:core/01_core.js:169:7)
at async default (file:///script.ts:5:10)
I didn't expect that deno is the default appFn runTime. There's no mention of that in the docs, also local development works 100% on nodeJS, and deno is not even mentioned in the lock file.
Is there any chance to deploy appFn on nodeJS runtime? If not I'll need to rewrite all this code to be deno-compatible. Also, you have to change the:
dt-app dev
command, appFn can not be run on two different JS runtimes. Also mention in the docs that default runTime is mandatory.
Solved! Go to Solution.
11 Jun 2024 12:54 PM
Hi,
Dynatrace Serverless functions run on the Dynatrace JavaScript runtime, which is a custom-made runtime for the Dynatrace AppEngine needs. Internally, we build on a fork of Deno which is mostly to ensure WebAPI compatibility (with WebAPI we mean the subset that is the de-facto standard for all back-end JavaScript runtimes like Node.js, Deno, Cloudflare workers, LLRT, Bun, and many others).
To ensure maximum compatibility with third-party libraries we are not only supporting reasonable WebAPIs, but also a subset of Node.js features. You can find out more about the compatibility features in our documentation: https://developer.dynatrace.com/reference/javascript-runtime/
The TL;DR: We support everything but features related to file access, raw network connections, or multi-process handling, simply because of the way the infrastructure works and the way functions are deployed. For fetching data from an endpoint, you wouldn't need more, though.
It would be interesting to know how your code looks like to see if this is a compatibility error or something else. Judging from the error message, you call `fetch` somewhere and expect a JSON file, but don't get a JSON file (see SyntaxError: Unexpected end of JSON input).
Do you have more information?
11 Jun 2024 01:33 PM - edited 11 Jun 2024 01:39 PM
There's 2 erorrs: SyntaxError and this:
n error of type UNCAUGHT_EXCEPTION occurred in an imported library
The problem was not about any missing WebAPI but with the compilation of the lib: issue
We wanted to have more control of the workflows and with Effect.ts was able to move a lot of logic from workflow to AppFn.
Unfortunately Effect.ts team is not able to make this lib a module (.mjs) so there's no chance to use it 😕
Btw are there any DT tools to run AppFn on Deno locally? Right now is one package (API and app). Also a plugin (or predefined rule) for Eslint will be nice.
11 Jun 2024 01:47 PM
The most important thing: The Dynatrace JS Runtime isn't Deno. Are you working with the Dynatrace App Toolkit? The App Toolkit ships the Dynatrace JS Runtime so everything you develop locally in /api should work on the App Engine as well.
If you have a library that relies on CommonJS rather than EcmaScript modules it wouldn't matter. The App Toolkit's bundler creates one file to deploy and run regardless.
11 Jun 2024 01:49 PM
I'm using
dt-app dev
then test AppFn by call to localhost:3000/api
11 Jun 2024 02:52 PM
Alright, you use the Dynatrace App Toolkit. Do you have some sample code that showcases your app function? Doesn't need to be the full thing, just to get an idea of how you use EffectTS so we can try to replicate your code and check for potential compatibility issues.
13 Jun 2024 08:38 AM
Simple functions with EffectTS like:
import { Effect, pipe } from "effect";
// /api/debug.ts
export default async function () {
const program = pipe(
Effect.succeed(42),
);
Effect.runSync(program);
}
gonna work well on localhost and throws the same error executed from the workflow.
Effect is in version 3.1.4
13 Jun 2024 01:48 PM
Hi!
I tried your code snippet and can't reproduce your errors neither within app functions nor locally. You say you execute them from the workflow, do you package your functions as actions?
You can also try to execute your code within an Ad-Hoc function in Notebooks to see if everything works out. You can load Effect from a JavaScript CDN like esm.sh and test which one of the pieces of Effect break, e.g..
import { Effect, pipe } from "https://esm.sh/effect@3.1.4";
export default async function () {
const program = pipe(Effect.succeed(42));
return Effect.runSync(program);
}
All you need to do is make sure that esm.sh is allow-listed from your tenant
(Also note that esm.sh might possibly contain malicious code so I would just turn it on if you know how that CDN is used within your organisation)