Assertion

An assertion is a condition in a Datadog Synthetic Monitoring API test (the HTTP test being the typical example) that determines what the response must look like for the test to be considered successful. In an HTTP test, you can combine five types, such as body and status code, with conditions written in JavaScript.

Overview

In an API test for synthetic monitoring, sending a request alone does not decide success or failure. An assertion is the expectation "this response means healthy" written as a condition, and if even one is not met, the test fails. The times to care about it are when a test stayed successful even though an outage was happening, when failures keep coming and notifications fire even though things are healthy, and when you cannot trace the cause of a failure on the results screen. A condition that looks only at the status code and a condition that checks even the body differ in the range of outages they can catch. The amount of information left on the results screen also changes depending on which types you set.

The definition of success written as conditions

An assertion is a condition that defines the result a test expects. You need at least one to start monitoring. In an HTTP test, pressing Test URL fills in three conditions based on the response obtained: response time, status code, and headercontent-type (as of October 2026; Source: HTTP Testing). A test fails (FAILED) when one or more conditions are not met and when the request fails partway through. In the latter case, the failure may be decided before the conditions are checked. The overall picture of API tests and browser tests is summarized in the Synthetics explanation.

There are five types, and how values are compared differs by type

There are five types of conditions you can choose in an HTTP test, and the operators available are fixed for each type.

Assertion types and operators in HTTP tests
TypeMain operatorsKind of value
Bodycontains / is / matches / jsonpath / xpath / jsonschema and othersString / Regular expression
Body hashmd5 / sha1 / sha256String
Headercontains / is / matches / does not exist / is less than and othersString / Regular expression / Integer
Response timeis less thanInteger (milliseconds)
Status codeis / is not / matches / does not matchInteger / Regular expression
Source: The Define assertions section of HTTP Testing (as of October 2026)

The only operator for response time is is less than. An OR condition such as "success if 200 or 302" is written as a regular expression like (200|302) using the matches regex comparison, and the same style can be used for the body and headers. Checks that the types in the table cannot cover go to JavaScript assertions, written with dd.expect(), dd.should, and dd.assert() from the Chai library. When examining a JSON response, whichever style you use, first parse the body with JSON.parse(dd.response.body).

The three filled in automatically do not look at the content of the body

The three conditions filled in by Test URL are the status code, response time, and content-type, and they include no condition that checks what is written in the body. As one way to proceed, if you add one body contains or jsonpath condition for a word or JSON value that always appears in a healthy response, you can also catch as failures responses whose status code is healthy but whose content is wrong. On the side where notifications fire even though things are healthy, look at how notifications are decided alongside the conditions. A notification is sent when some location failed within the last X minutes and, at some point within those X minutes, n or more locations were failing at the same time (as of October 2026; Source: HTTP Testing). There is also Fast retry, which retries a failed result X times after Y milliseconds, and the interval can be adjusted to match the sensitivity of notifications. Notification recipients and messages are configured in the same way as for a Monitor, and are varied according to the state of the Alert.

The body is kept only when the test fails

In a test without a body condition, the response body is discarded and only the response time is returned. Even with a body condition, the body is discarded on successful runs and only the first 50 characters are displayed. The body is returned as is only on runs where a body condition is set and that condition failed (all as of October 2026; Source: HTTP Testing). You can set up to 20 conditions in one API test (as of October 2026). If the response may contain personal information or similar data, use Do not save response body under Privacy in Advanced Options. When enabled, the body is not saved, and the error messages of JavaScript assertions are also truncated. The official documentation also notes that this setting can make it harder to investigate failures.

Trace back the conditions from outages that did not trigger an alert

You find gaps and excesses in the conditions by matching them against outages that actually happened rather than by looking over the settings screen. Choose one outage where a user report arrived first, and if the test results for that time period stayed successful, map what was different from usual in that response onto a condition type. If a word in the body was different, a body condition is the candidate; if it was slow, a response time value is. Conversely, for a test that showed a string of failures even though things were healthy, compare on the results screen the type of the condition that failed and the number of locations that triggered the notification. From those two, you can choose whether to add conditions or change how notifications are decided.

Share