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.
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.
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 https://github.com/777abhi/observability-qe-roadmap.git
cd observability-qe-roadmap/tests/day2-in-memory-collector.spec.tsInspect In-Memory Collector & DAG Builder
Run Day 2 test suites and observe parent-child relationship reconstruction.
npm run test:day2export 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),
};
}
}- 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?