46 / 67 · 06 Observability-Driven Testing · Synthetic Monitoring← prev⊞ allnext →☰ Read as one page
7.4Running Synthetics as a Cron Job in CI
# .github/workflows/synthetic-monitor.yml
name: Synthetic Monitoring
on:
schedule:
- cron: '*/5 * * * *' # every 5 minutes
workflow_dispatch: {} # allow manual trigger
jobs:
synthetic-us-east:
runs-on: ubuntu-latest # GitHub-hosted runner (US East)
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- name: Install Playwright browsers
run: npx playwright install --with-deps chromium
- name: Run synthetic tests
run: npx playwright test synthetic/ --reporter=json
env:
BASE_URL: https://store.example.com
SYNTHETIC_MODE: true
- name: Push metrics to Datadog
if: always()
run: |
python scripts/push_synthetic_metrics.py \
--results playwright-report/results.json \
--region us-east-1 \
--datadog-api-key ${{ secrets.DATADOG_API_KEY }}
- name: Alert on failure
if: failure()
run: |
curl -X POST "${{ secrets.PAGERDUTY_EVENTS_URL }}" \
-H "Content-Type: application/json" \
-d '{
"routing_key": "${{ secrets.PD_ROUTING_KEY }}",
"event_action": "trigger",
"payload": {
"summary": "Synthetic checkout flow FAILED in us-east-1",
"severity": "critical",
"source": "github-actions-synthetic"
}
}'