Header background

Automated scripted API monitoring with HTTP monitors

Lately, we’re seeing that automation is the main focus of IT, and microservice architectures are becoming increasingly common. This means that APIs are becoming more and more important to us and our customers. With the growing adoption of APIs, the complexity of use cases based on APIs is growing as well. This means that the monitoring of these APIs needs to reflect current developments and allow the monitoring of such use cases.

Just this summer, private synthetic multi-request HTTP monitors became publicly available. Right from the start of our HTTP monitors offering, we promised extensive scripting capabilities that further expand the already extensive monitoring capabilities of HTTP monitors, and that update is finally here.

Pre- and post-execution scripting enables sophisticated API monitoring use cases

Think of your API use cases, including the monitoring of services used by mobile apps, and consider when your use cases will include:

  • Complex authentication
  • Logic between requests
  • Passing of information between requests
  • The use of custom functions that perform response parsing
  • Other custom code

For such advanced scenarios, pre- and post-execution scripting is the solution.

Using an HTTP monitor to test the Dynatrace Synthetic API

Example use case

When you execute more complex API requests, the need for scripting may occur. Say you want to add logic between steps, skipping a request based directly on a response received from another request. To achieve this you need to:

  • Define a request.
  • In a post-execution script, verify the conditions based on the request.
  • If the conditions are met, skip the “Pre-execution scripts” step and proceed to the “Post-execution scripts” step.

For more examples with code snippets that show how the examples were implemented, see Dynatrace Help.

What’s available

With the release of ActiveGate version 1.173, it’s now possible to use:

  • Pre-execution scripts – to launch custom JavaScript code before an HTTP request is executed
  • Post-execution scripts – to launch custom JavaScript code after an HTTP request is executed
  • Variables – to pass information between requests

Head over to Dynatrace Help for more technical details, the list of available methods, and example HTTP monitors that are defined using pre- and post-execution scripts.

How to get started

To start using this feature, you only need a private synthetic location that is based on ActiveGate version 1.173+.

It’s not possible to assign monitors that use these features to locations with ActiveGates that are older than version 1.173; the locations must be upgraded to version 1.173+.

How to use this feature

You’ll see additional options when creating or configuring an HTTP monitor; it’s as simple as typing your JavaScript code directly into the browser.

Pre- and post-execution scripting is available when configuring the HTTP request

Hints are displayed as you type, providing easy access to syntax help for your JavaScript code.

Live hints make pre- and post-execution script writing easier.

The use of variables is now possible with the use of curly brackets as in other parts of Dynatrace. Use curly brackets ({ and }) to access the variables you’ve defined in your pre- and post-execution scripts.

Using a variable defined in a pre- or post-execution script

What’s next?

Stay tuned for the next set of Synthetic Monitoring features, including, but not limited to:

  • Credential Vault
  • New public locations
  • Support for new cloud vendors

Start a free trial!

Dynatrace is free to use for 15 days! The trial stops automatically, no credit card is required. Just enter your email address, choose your cloud location and install our agent.