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

In-Memory OTLP Collector & DAG Reconstruction
Observability-Driven QE Sprint β€” Day 2

Capture OpenTelemetry spans in-memory during test runs, reconstruct the distributed execution tree (DAG), and detect orphaned spans and asynchronous drops.

⚑ Runtime: Node.js 22 LTS Β· VitestπŸ›‘οΈ Observability & Distributed Systems QE Architect
OTLP CollectorSpan BufferingDAG ReconstructionCritical PathOrphan Spans
About this lab

Sending traces to third-party SaaS platforms in automated unit and integration tests introduces external network latency and flakiness. Instead, learn to embed a lightweight In-Memory Span Collector that captures spans synchronously, computes execution depth, reconstructs parent-child DAGs, and detects orphaned spans.

πŸ“¦Sample Codebase & Working Solution (Day 2)Available Now
View on GitHub

The official reference codebase for Day 2 is hosted in the repository. Clone the repository and navigate to tests/day2-in-memory-collector.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/day2-in-memory-collector.spec.ts
🏭Production Context & Enterprise Implementation
πŸ’‘ Why We Are Doing This: Integration tests run 50x faster when telemetry spans are captured in-memory rather than posted over HTTP to remote collectors.
🏒 Real-World Production Usecase: Capturing 100% of telemetry emitted during end-to-end user journeys to assert all downstream database, cache, and HTTP spans fired.
βš™οΈ How Implemented in Production: An in-memory span buffer and DAG builder in src/collector/traceGraph.ts calculating critical path durations in milliseconds.
Phase 1

Inspect In-Memory Collector & DAG Builder

Run Day 2 test suites and observe parent-child relationship reconstruction.

Step 2.1: Run Day 2 Vitest Suite
Terminal β€” Run Day 2 Tests
npm run test:day2
Step 2.2: Sample Codebase & Working Solution (Day 2)
src/collector/traceGraph.ts
export class TraceGraphBuilder {
  static buildTree(spans: TraceSpanRecord[]): TraceGraphAnalysis {
    const spanMap = new Map<string, TraceSpanRecord>();
    const childrenMap = new Map<string, TraceSpanRecord[]>();

    for (const span of spans) {
      spanMap.set(span.spanId, span);
      const parent = span.parentSpanId || '__root__';
      const existing = childrenMap.get(parent) || [];
      existing.push(span);
      childrenMap.set(parent, existing);
    }

    const orphanedSpans = spans.filter((s) => {
      if (!s.parentSpanId) return false;
      return !spanMap.has(s.parentSpanId);
    });

    return {
      traceId: spans[0]?.traceId || '',
      totalSpans: spans.length,
      rootNodes: (childrenMap.get('__root__') || []).map(buildNode),
      orphanedSpans,
      criticalPathSpanIds: computeLongestChain(roots),
    };
  }
}
Day 2 Key Learnings
  • Built an in-memory span buffer that decouples testing from heavy external OTel collector daemons.
  • Reconstructed hierarchical parent-child DAGs from flat span streams.
  • Identified critical path chains and isolated orphaned spans resulting from dropped contexts.

🧠 Knowledge Check

What constitutes an 'orphaned span' in a distributed trace?