Skip to content
Tutorials Center
My learning

Topics

Lesson 28 of 37 ยท Synthetics and Security

Synthetic Tests

Probe your service from outside with Datadog Synthetic tests: HTTP and multistep API tests, browser tests, locations, assertions, retries and CI integration.

Metrics and traces describe what real users already experienced. Synthetic Monitoring runs scripted checks on a schedule from locations around the world, so you learn about a broken login or an expired certificate before users do, even at 3 a.m. when traffic is low.

Datadog is not available on this site. Settings and menus below are described as they exist in the product, and the runnable code is a labelled stand-in for the logic of assertions and retries.

Test types

Type What it does
API test (HTTP, SSL, DNS, TCP, UDP, ICMP, WebSocket, gRPC) One request; checks status, headers, body, timing, certificate expiry
Multistep API test A chain of requests that pass values forward (log in, get a token, create an order)
Browser test A real browser replays recorded clicks, typing and assertions
Mobile app test Scripted flows on real or emulated mobile devices

Create one in Digital Experience > Synthetic Monitoring & Testing > New Test (menu names move between releases).

An API test

You set the URL, method, headers and body, then add assertions:

  • status code is 200,
  • response time is less than 800 ms,
  • header content-type contains application/json,
  • body contains "status":"ok", or a JSONPath such as $.items[0].id is not empty,
  • certificate expires in more than 14 days.

Choose locations (managed regions such as Frankfurt or Tokyo, or your own private locations), a frequency (from every minute up to weekly) and alerting conditions, for example "alert if the test fails from at least 2 of 3 locations for 3 minutes". Retries (fast retry after a failure) cut down false alarms caused by a single network blip.

Stand-in: assertion engine

This stand-in checks a fake response against a list of assertions, the same way a test result is computed.

JS Stand-in: evaluate API assertions

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The failing certificate assertion is useful: it warns two weeks early, long before browsers show errors.

Multistep API tests

A multistep test chains requests. A step can extract a value from a response (a token from JSON, a header, a regex match) into a variable, then use it as {{ TOKEN }} in later steps. A typical chain: POST /login extracts TOKEN; POST /cart with Authorization: Bearer {{ TOKEN }} extracts CART_ID; POST /checkout asserts status 201.

Store secrets in Global Variables marked secure, never in the test body. Create a dedicated synthetic user with minimal rights.

Stand-in: chaining requests

JS Stand-in: multistep chain with variables

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Browser tests

The Datadog Synthetics recorder is a Chrome or Edge extension. You click Start recording, use your site as a user would, add assertions (for example "element #order-confirmation is present", "text contains Thank you"), then save. The test replays in managed browsers (desktop and mobile viewport sizes). Each step captures a screenshot and the result page links to the RUM session and, if present, the backend trace of the request, so a failing step can be debugged end to end.

Tips for stable browser tests:

  • Use stable selectors: add data-testid attributes instead of relying on CSS classes that change.
  • Keep tests short and focused (login, search, checkout) rather than one giant journey.
  • Use a test account and test payment mode; never run purchases against live payment providers.
  • Handle cookie banners and A/B variants explicitly.

Locations and private locations

Managed locations cover many regions. To test an internal service, run a private location: a small container (the Synthetics Private Location worker) inside your network that polls Datadog for work and runs tests locally, so you can check intranet apps without opening ports.

CI/CD and alerts

The datadog-ci command line can trigger Synthetic tests in a pipeline (datadog-ci synthetics run-tests --public-id abc-123-def), so a deploy fails when the critical journey breaks. A synthetic test also creates an automatic monitor, and you can add it to SLOs and dashboards.

flowchart LR
  S["Scheduler"] --> L1["Frankfurt"]
  S --> L2["Tokyo"]
  S --> L3["Private location"]
  L1 --> R["Results & alerts"]
  L2 --> R
  L3 --> R

Several locations tell a regional outage from a global one.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the main benefit of synthetic tests over real-user data?

    Scripted checks run on a schedule regardless of traffic.
  2. 2. In a multistep API test, how is a token from step 1 used in step 2?

    Extracted values become variables available to later steps.
  3. 3. When do you need a private location?

    A private location worker runs tests from inside your network.
  4. 4. Why configure retries on a synthetic test?

    A quick retry confirms a failure before alerting.

Summary

  • Synthetics run API, multistep, browser and mobile checks from many locations.
  • Assertions on status, time, headers, body and certificates decide pass or fail.
  • Multistep tests pass values between steps; keep secrets in secure variables.
  • Private locations reach internal systems; datadog-ci runs tests in pipelines.

Next: Real User Monitoring