Module Review: Testing & Verification
1. Key Takeaways
- 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.
- The Test Pyramid:
- Unit: Verify span names, attributes, and error handling using
InMemoryExporter. - Integration: Verify
traceparentheader propagation across service boundaries. - E2E: Verify full trace assembly in the backend (optional but powerful).
- Unit: Verify span names, attributes, and error handling using
- Status Codes: Understand that
UNSETis the default for success,ERRORis for failures, andOKis rarely used (only to override errors). - Context Propagation: A broken trace is often due to missing context injection/extraction in HTTP clients or async tasks.
- 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.