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

Two fetch API call under one JavaScript event of browser click path

AK
Pro

Hello Folks,

Can we have two fetch API under one JavaScript event of browser click path?

My use case is to monitor extension 2.0 endpoints.

The high-level code under JavaScript event will look like below,

 

 

fetch(https://{environmentid}.live.dynatrace.com/api/v2/extensions/<extension-name>/monitoringConfigurations?version=1.0)
{
get all endpoint name and respective endpointID
}
fetch(https://{environmentid}.live.dynatrace.com/api/v2/extensions/<extension-name>/monitoringConfigurations/<endpointID>/status)
{
code to iterate through each endpoint URL to get individual status
}

 

 

 

Is it something that is doable or I need to add separate JavaScript for each one of above.

Regards,

AK

7 REPLIES 7

HannahM
Dynatrace Leader
Dynatrace Leader

If you're just calling and checking APIs an HTTP Monitor would probably be a better option. But either way, using requests in an HTTP Monitor or JavaScript events in a Browser Monitor, you would want to split them out into separate events

Synthetic SME and community advocate.

Hi @HannahM,

Thanks for quick response on this.

APIs for hub extensions are bit tricky. We won't get Endpoint status information in "monitoringConfigurations" API hence to see status of each endpoints, we have to utilize another API and pass endpoint ID in that API URL (received from previous API call) for all endpoints.

For extensions/plugins other that extension 2.0, I'm successfully able use HTTP monitor.

As we have to pass endpoint ID each time to get status of each endpoint, I was not able to use HTTP monitor hence thought to use Browser monitor where we can play around inside JS code to make it happen.

I developed the code (for my above requirement) via developer console and it is working pretty well there however, most of functions are not working when I paste that code under JS event of browser clickpath monitor hence the questions.

Regards,

AK

HannahM
Dynatrace Leader
Dynatrace Leader

The solution would be similar for both monitor types. You'll need to store the endpointIDs, api.setValue(key, value), and then use them as placeholders in later requests. Is it a fixed number of endpoints? Both monitor types have fixed numbers of events/ requests so you would need to create the max number of events and then use one of the api.skip methods to skip any extra ones not needed. 

Synthetic SME and community advocate.

Hi @HannahM,

Describing my issue in more detail,

For HTTP monitor (extensions other than 2.0/custom plugins)

Request 1 - Get endpoints ID and status (no endpoint names available)
All endpoints will be reported here
Apply the logic to filter on endpoints which are in error
Store those endpoints in one variable

Request 2 - Get endpoint names
All endpoints with ID and names will be reported here
Apply the logic to map endpoint names to the endpoints(endpoints which are in error) received from previous request
Store those endpoint ID, associated name and associated status in one variable

Request 3 - (Ingest API call)
Post an event to same HTTP monitor and event will have details of endpoints in error

Problem with extension 2.0 (hub extensions)

Endpoint ID and names are available in one API and to get status of each endpoint, we have to put ID of each and every endpoint in API URL
Even though, it is possible to pass endpoint ID in the request of HTTP monitor but how we can iterate for each endpoint.
And we cant add fix number of requests under HTTP monitor, because the end result is dynamic i.e. names of an endpoints which are in error

That's why I chose browser click path (specifically JavaScript event) so that, I can iterate through multiple URLs using "for loop" and "if statement" to get desired output

HannahM
Dynatrace Leader
Dynatrace Leader

A Browser monitor will have the same issue as an HTTP Monitor that only 1 request can be made per event. 

You will need to add the max number of requests/ fetches that you expect as requests/ events and then when you make the call and get the actual number can then skip the extra ones you don't need. 

Synthetic SME and community advocate.

@HannahM,

Max number is request can not fixed because that will increase in future hence we cant look every time to update a configuration of monitor.

Shall I share whole code I developed for browser click-path JScript event. I tested it successfully on developed console however, it seems JavaScript doesn't support advance script.

@HannahM, I'm able to resolve it. Thank you for your suggestions and taking a time to respond.

Featured Posts