17 Jan 2024 06:40 PM - edited 17 Jan 2024 08:52 PM
Hello development team!
The last time I read about JS runtime limitations, I remember the ability to import third-party modules for use in applications and/or workflow tasks. Reading again, https://developer.dynatrace.com/reference/javascript-runtime/ seems like there is much more limited support for importing third party modules.
My use case is to use cheerio to extract information from a scrap via fetch and send the value to a metric. Is something like that not possible? Since the moment that I call the cheerio function I get the following error:
An error occurred: {"code": 541, "message": "Execution crashed.", "details": {"type": "BAD_REQUEST", "message": "<stripped secret anyhow::Error>"}}
Thanks in advance 🙂
Solved! Go to Solution.
18 Jan 2024 01:10 PM
Yes the JS runtime has some limitations when it comes to 3rd party modules.
I have tried to reproduce your problem. loading data via fetch and using cheerio to extract it. This is my code snippet, it works without any problems
import * as cheerio from "cheerio";
export default async function (payload: unknown = undefined) {
const resp = await fetch("https://example.com/");
const txt = await resp.text();
const $ = cheerio.load(txt);
console.log($("title").text());
return $("h1").text();
}
Maybe you can share your AppFunction code with us?
Best,
Sini
18 Jan 2024 01:29 PM - edited 18 Jan 2024 01:33 PM
If I'm interpreting the error@DantePaoloni shared correctly, he might be using the "Run Javascript" action in Workflows, which currently doesn't support 3rd party libraries.
18 Jan 2024 01:53 PM - edited 18 Jan 2024 01:58 PM
Hey, I was re checking again just in case. Indeed is a JS Action in a workflow.
Will eventually be supported? Or this is be something to create in an AppFunction and call it throught a workflow like in https://developer.dynatrace.com/develop/functions/create-function/#from-notebooks-or-workflows ? Im asking in this case the "right" way to handle it.
18 Jan 2024 02:00 PM
Yes, as of now that would be the workaround.
There have been plans to add 3rd packages support for functions in workflows and notebooks but I don't have any further details on that.