Skip to content

Generate a Synthetic Monitoring Scenario with AI

Performance TestingUpdated 2026-10-21intermediate
TL;DR

Reads a critical user journey and returns a Playwright-based synthetic monitoring script with business-step checkpoints, failure-screenshot capture, an alerting threshold tied to a stated SLO/SLI, and a recommended run frequency.

When to use it

  • Setting up uptime monitoring for a customer-facing critical path.
  • Migrating from a click-record-replay tool (Pingdom) to code-based synthetic monitoring.
  • Tying synthetic checks to SLOs so alert noise has business meaning.
  • Adding a smoke test that runs post-deploy in production safely.

The prompt

XML-tagged: works best with Claude
synthetic-monitoring-scenario.claude.mdprompt
<role>You are an SRE who writes synthetic monitoring as code. You distinguish synthetic monitoring (probes that fire periodically against production) from E2E tests (verify behavior pre-release). You map every alert to an SLO so noise has business meaning.</role> <context>Synthetic monitoring runs as code in production. Each run is fast (< 30s), captures evidence on failure (screenshot, console, network), and pages a human only when a stated SLO is breached. Tools: Datadog Synthetic, Checkly, Grafana Synthetic Monitoring, custom Playwright + cron.</context> <task>For the journey below, produce:1. A Playwright synthetic monitoring script (TypeScript) that walks the journey2. Business-step CHECKPOINTS: each business milestone (logged in, item added, payment shown) is an assertion, not an implementation detail3. Failure capture: on failure, take screenshot, save trace, log console4. SLO mapping: alert ONLY when failure rate crosses a threshold tied to a stated SLO (e.g., 99.9% over 30 days means a 43.2 min/month error budget; 99.99% means 4.3 min)5. Recommended frequency: based on the SLO budget and detection-time goal</task> <input>Critical user journey description: {journey}SLO target (e.g., 99.9% uptime, 95% successful purchases): {slo}What's "down" mean for this journey (any step fails, only checkout fails, etc.): {down_definition}</input> <constraints>- Checkpoints are BUSINESS milestones, not "step 1 / step 2".- SLO mapping is explicit (target % → budget in minutes/month → alerting rule).- Frequency tied to detection-time goal (e.g., 5-min frequency = max 10-min detection of breach).- Failure capture is automatic, not optional: show the playwright.config `use` block (trace, screenshot) and a console listener.- No `page.waitForTimeout`: use auto-waiting.- Production-safe: no destructive operations (no real charges, no real account deletion). Any test-only bypass (free promo code, confirm endpoint) must be locked server-side to synthetic accounts.- Alert rule must be consistent with the frequency and detection goal (e.g., 5-min runs + 10-min detection = page after 2 consecutive failures).</constraints> <output_format>Four sections:1. **Playwright script**: TypeScript code block2. **SLO mapping**: table: SLO target | Budget | Alert threshold | Page-after-N-failures rule3. **Frequency recommendation**: paragraph with reasoning4. **Production-safety notes**: bullets on what NOT to do (real charges, etc.)</output_format> <approach>Before writing, identify the 3-5 business milestones in the journey that an alert SHOULD fire on if they fail.</approach>

Example

Input
Critical user journey: New user signs up → confirms email → adds a $10 item to cart → completes checkout → receives order confirmation.
SLO target: 99.9% of synthetic runs successful (≈ 43 min/month budget)
What's "down" mean: ANY step fails to complete in < 60 seconds (the journey end-to-end should normally take 30 seconds).
Output
## 1. Playwright script

```typescript
import { test, expect, type Page } from '@playwright/test';

const SYNTHETIC_TEST_PREFIX = 'synthetic_';
const SYNTHETIC_PROMO_CODE = 'SYNTHETIC_FREE';

test('purchase journey: synthetic monitor', async ({ page, context }) => {
  // Production-safe: use a known synthetic test account and a promo code that zeros out price
  const testEmail = `${SYNTHETIC_TEST_PREFIX}${Date.now()}@synthetic.example.com`;

  test.setTimeout(60_000);  // total budget per run
  await context.setExtraHTTPHeaders({ 'X-Synthetic-Source': 'monitor-v1' });
  page.on('console', (msg) => {
    if (msg.type() === 'error') console.log(`[browser] ${msg.text()}`);
  });

  await test.step('signup completes', async () => {
    await page.goto('https://example.com/signup');
    await page.getByLabel('Email').fill(testEmail);
    await page.getByLabel('Password').fill('SyntheticTestPass123');
    await page.getByRole('button', { name: 'Sign up' }).click();
    await expect(page.getByRole('heading', { name: 'Check your email' })).toBeVisible();
  });

  await test.step('email confirmed (via API)', async () => {
    // Production-safe: call internal confirm endpoint with synthetic account creds
    const response = await page.request.post('https://api.example.com/internal/synthetic/confirm', {
      data: { email: testEmail },
      headers: { 'X-Synthetic-Secret': process.env.SYNTHETIC_SECRET! },
    });
    expect(response.status()).toBe(200);
  });

  await test.step('item added to cart', async () => {
    await page.goto('https://example.com/products/synthetic-monitor-item');
    await page.getByRole('button', { name: 'Add to cart' }).click();
    await expect(page.getByRole('heading', { name: /Cart \(1\)/ })).toBeVisible();
  });

  await test.step('checkout completes with synthetic promo', async () => {
    await page.goto('https://example.com/checkout');
    await page.getByLabel('Promo code').fill(SYNTHETIC_PROMO_CODE);
    await page.getByRole('button', { name: 'Apply' }).click();
    await expect(page.getByText('Total: $0.00')).toBeVisible();
    await page.getByRole('button', { name: 'Place order' }).click();
  });

  await test.step('order confirmation visible', async () => {
    await expect(page.getByRole('heading', { name: 'Order confirmed' })).toBeVisible({ timeout: 15_000 });
    await expect(page.getByText(/Order #\d+/)).toBeVisible();
  });

});
```

```typescript
// playwright.config.ts (synthetic project): evidence is captured on every failure
use: {
  trace: 'retain-on-failure',
  screenshot: 'only-on-failure',
  video: 'retain-on-failure',
},
retries: 0, // a retry would hide the very failure the SLO counts
```

## 2. SLO mapping

| SLO target | Budget per month | Alert threshold | Page-after-N rule |
|------------|------------------|-----------------|-------------------|
| 99.9% successful runs | 43.2 min (with 5-min runs: 8,640 runs/month, ≈ 8 failed runs allowed) | 2 consecutive failed runs, confirmed from a second location | Page after 2 consecutive failures (≤ 10 min detection); open a ticket, not a page, when the 6-hour budget burn rate exceeds 2x |

## 3. Frequency recommendation

**Every 5 minutes** matches a 99.9% SLO with a goal of detecting breaches within 10 minutes. Each 5-min run consumes one chance to detect a regression; a failure-rate sustained over 2 runs = detection in < 10 min, room within the SLO budget.

If the journey takes 30-60 seconds end-to-end and the script runs 12 times/hour, runtime cost is up to ~12 minutes/hour of synthetic activity per location. Multiply by the number of locations and check it against your vendor's per-run pricing before adding geos.

Drop frequency to 10 min if running multiple monitors with a constrained budget. Increase to 1 min only when the SLO is 99.99%+ and detection within 1-2 min is a business requirement.

## 4. Production-safety notes

- **Use a synthetic account and promo code** (`SYNTHETIC_FREE` zeros out price): never real charges.
- **Synthetic email domain** (`@synthetic.example.com`, use a domain you own) so the account is identifiable for cleanup and exclusion from analytics.
- **Lock the bypasses server-side**: `SYNTHETIC_FREE` and the confirm endpoint must only work for synthetic accounts, or they become a free-order hole in production.
- **Cleanup job** runs daily, deleting synthetic accounts older than 24 hours. Synthetic orders auto-cancelled.
- **Confirm-email step** uses an INTERNAL endpoint (`X-Synthetic-Secret` header): does NOT verify real email delivery. Add a separate, less-frequent monitor for actual email delivery.
- **No production data mutation**: synthetic accounts cannot create state visible to real customers.
- **Tag all synthetic traffic** with header `X-Synthetic-Source: monitor-v1` so it's excluded from real-user analytics dashboards.

Common pitfalls

  • Model produces an E2E test, not a synthetic monitor: E2E asserts UI details that don't matter for SLO. Force business-milestone checkpoints.
  • SLO mapping gets glossed over with 'alert on failures'. Demand the budget math.
  • Frequency defaults to '1 min' without considering cost or SLO match: re-prompt for justified frequency.
  • Production safety gets forgotten: without a synthetic promo code and account, the monitor will create real orders.

Tips

  • Tag synthetic traffic with a header so it's excluded from RUM/analytics dashboards.
  • Run from multiple geos: single-geo monitors miss regional CDN / network issues.
  • Pair with real-user monitoring (RUM): synthetic catches uptime; RUM catches performance variance from real client conditions.
  • Re-evaluate SLO and frequency quarterly; they drift as traffic patterns change.

FAQ

Synthetic vs RUM, which do I need?

Both. Synthetic provides predictable uptime signal at known intervals; RUM provides truth from real users. Synthetic catches outages; RUM catches degradation. Most teams should have synthetic for critical paths + RUM for everything else.

How do I tune frequency?

Start from the SLO. 99.9% with detection-in-10-min → 5-min frequency. 99.99% with detection-in-2-min → 1-min frequency. Then check costs; many synthetic-monitoring tools price per check, so dial back to match budget.

What's the false-positive cost?

Synthetic monitors page humans. A noisy monitor erodes trust. Budget tolerance for false positives: ~2% of alerts per month. Higher noise = teams ignore the page. Tune by being explicit about "down" definitions in the prompt.

Can I run synthetic monitors from CI?

No. CI-triggered checks aren't independent of deploy state. Synthetic monitoring must run on a separate cron / scheduler, independent of any deploy pipeline.