Module Review: Testing & Verification

You've learned that observability isn't just a "nice to have"—it's a critical feature that requires testing. From unit testing individual spans to verifying distributed traces, you now have the tools to ensure your system is observable by design.

1. Key Takeaways

  1. Instrumentation as Code: Treat your tracing code with the same rigor as your business logic. If it breaks, you’re flying blind during an outage.
  2. The Test Pyramid:
    • Unit: Verify span names, attributes, and error handling using InMemoryExporter.
    • Integration: Verify traceparent header propagation across service boundaries.
    • E2E: Verify full trace assembly in the backend (optional but powerful).
  3. Status Codes: Understand that UNSET is the default for success, ERROR is for failures, and OK is rarely used (only to override errors).
  4. Context Propagation: A broken trace is often due to missing context injection/extraction in HTTP clients or async tasks.
  5. Testcontainers: Use containerized Jaeger/Collector instances for high-fidelity integration tests.

2. Interactive Flashcards

Test your recall of the core concepts. Click a card to flip it.

InMemoryExporter

What is its purpose?

It captures generated spans in a local list instead of sending them to a backend, allowing unit tests to assert on span properties.

UNSET vs OK

Why is UNSET the default success status?

OpenTelemetry spec defines UNSET as "success" to save bandwidth. OK is only explicitly set by the user to overwrite a previous ERROR status.

Context Propagation

What happens if you forget to inject context?

The trace chain is broken. The downstream service will start a NEW trace instead of continuing the existing one, resulting in two disconnected traces.

Baggage

How does Baggage differ from Attributes?

Attributes belong to a specific Span. Baggage travels with the Context across the entire request lifecycle (all services).


3. Testing Cheat Sheet

Quick reference for the methods you’ll use most often.

Concept Java (JUnit 5) Go (Testify)
Setup @RegisterExtension OpenTelemetryExtension tracetest.NewInMemoryExporter()
Get Spans otelTesting.getSpans() exporter.GetSpans()
Assert Count assertEquals(1, spans.size()) assert.Len(t, spans, 1)
Assert Name assertEquals("name", span.getName()) assert.Equal(t, "name", span.Name)
Assert Attr span.getAttributes().get(key) span.Attributes (iterate)
Status span.getStatus().getStatusCode() span.Status.Code

4. Next Steps

You are now ready to tackle the advanced topics.

  • Metrics Module: Learn how to test Counters, Gauges, and Histograms.
  • Logs Module: Correlate your logs with your traces.
  • Course Glossary: Review definitions for terms like Exporter, Processor, and Sampler.