HomeRoadmapsObservability Day 3
Observability-Driven QE Track Β· Day 3 Β· 20 min

Trace-Based Assertion DSL & Structural Invariants
Observability-Driven QE Sprint β€” Day 3

Design declarative, fluent trace assertion DSLs that validate distributed service topology, expected downstream DB queries, parent-child links, and error status boundaries.

⚑ Runtime: Node.js 22 LTS Β· VitestπŸ›‘οΈ Observability & Distributed Systems QE Architect
Trace-Based TestingAssertion DSLexpectTraceStructural InvariantsFluent API
About this lab

Traditional testing treats systems as a black box: trigger an HTTP request and assert on the HTTP 200 response body. Trace-based testing asserts on what happened under the hood: verifying that the API gateway correctly dispatched an async message to the order service, which invoked Stripe, which wrote to Postgres.

Interactive Lab Tool

πŸ”¬ OpenTelemetry Trace Waterfall & Assertion Simulator

Standard Async Distributed Trace (Healthy)
W3C TraceContext Header:Spec: RFC W3C Trace-Context
traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
Version: 00
Trace ID: 4bf92f3577...
Parent Span ID: 00f067aa0ba9
Sampled Flag: 01 (Active)
Span Hierarchy (Timeline: 0ms β†’ 165ms)Duration
POST /checkoutapi-gateway
165ms
OrderService.CreateOrderorder-service
120ms
PaymentService.Chargepayment-service
75ms
SELECT stock FROM inventorydb-inventory
50ms
Selected Span Metadata
Span Name: POST /checkout
Service: api-gateway
Duration: 165ms
Status: OK
Live Trace Assertion Rule
All spans recorded statusCode: OK (0 errors detected).PASS
πŸ“¦Sample Codebase & Working Solution (Day 3)Available Now
View on GitHub

The official reference codebase for Day 3 is hosted in the repository. Clone the repository and navigate to tests/day3-trace-assertions.spec.ts to run the working solution.

Git Clone β€” Working Solution
git clone https://github.com/777abhi/observability-qe-roadmap.git
cd observability-qe-roadmap/tests/day3-trace-assertions.spec.ts
🏭Production Context & Enterprise Implementation
πŸ’‘ Why We Are Doing This: A mock payment gateway returning a fake 200 might fool functional tests while hiding that the real payment service was never invoked. Trace assertions expose hidden bypassed services.
🏒 Real-World Production Usecase: Asserting that a checkout API call emits exactly 1 root gateway span, 1 order service span, and 1 client payment span with status OK.
βš™οΈ How Implemented in Production: A fluent TypeScript DSL with expectTrace(collector, traceId).hasRootSpan().withAttribute() and custom SpanMatchers.
Phase 1

Write Fluent Trace Assertions

Run Day 3 Vitest suites and inspect declarative structural invariants.

Step 3.1: Execute Day 3 Tests
Terminal β€” Run Day 3 Tests
npm run test:day3
Step 3.2: Sample Codebase & Working Solution (Day 3)
tests/day3-trace-assertions.spec.ts
expectTrace(collector, traceId)
  .hasSpanCount(2)
  .hasNoErrors()
  .hasRootSpan('checkout-service')
  .withAttribute('http.status_code', 200)
  .durationUnder(300)
  .hasChildSpan('StripeCharge')
  .withAttribute('payment.gateway', 'stripe')
  .hasStatus('OK');
Day 3 Key Learnings
  • Created declarative fluent assertion DSL (expectTrace) for validating distributed trace hierarchies.
  • Asserted on specific span attributes (HTTP status codes, payment amounts, database query text).
  • Enforced structural parent-child invariants and verified error-free execution across all trace spans.

🧠 Knowledge Check

Why is trace-based testing superior to traditional black-box API testing for microservices?