cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

App functions - how to debug with VS code

Zoltan
Helper

Hi,

I am curious if it's possible to debug app functions with breakpoint pauses.

So far, when I try to fix something that's not working, either I deploy a test version of my app function to dyna could, then call it, and try to make sense of the logs, or run it locally with jest. But in the latter case, I can't call dynatrace callbacks, as when executed with yest, the client library is not initialized.

Ok, I can mock, but the whole point would be to debug with live data.

Any suggestions?
Thanks,
Zoltan

this is an example I want to call and step by step debug:

Zoltan_0-1751623979337.png

 

3 REPLIES 3

dani_coll
Dynatrace Helper
Dynatrace Helper

Hi Zoltan,

If you created the project through the dt-app CLI you should have a .vscode/launch.json file that includes debugging settings. By running that configuration you can debug your app function using breakpoints

dani_coll_0-1751627078574.png

 

Hi Dani,

Indeed, it works as you described (on a note - I had my project generated way back, where the launch.json generated didn't have this run config.
Also, what was confusing a bit was that the breakpoint is only shown as active during a request. When you set it, it appears as to be inactive - don't know why, perhaps it's my vs code setup...

While we are here one more question:
How do I pass the payload param to the function via a plain http request? Can't find an example in the docs.
Is the json post body what becomes the payload param of the function?
export default async function (payload: unknown = undefined)

Thanks,

Zoltan

dani_coll
Dynatrace Helper
Dynatrace Helper

Yes, it should be the body. Using the fetch command it's something like this

const method = options?.data ? 'POST' : 'GET';
const body = options?.data ? JSON.stringify(options.data) : undefined;

const response = await fetch(`/api/${functionName}`, { body, method });

 

Featured Posts