NoopTracerProvider silently drops spans in unit tests
0 reputation · 09 Jun 2022, 12:22 UTC
NoopTracerProvider silently drops spans in unit tests
Goal
Validate that instrumentation code produces trace data when no production credentials or exporter are configured.
Uncertainty
When GlobalOpenTelemetry.getTracer() is used without a prior explicit TracerProvider, the SDK falls back to NoopTracerProvider, returning NoopTracer instances that create NoopSpan objects. These spans are created but never recorded or exported, and no error or warning is emitted. Tests that rely on span collection may therefore pass silently while producing no telemetry.
Questions
- Should test frameworks supply a zero‑config InMemorySpanExporter and SimpleSpanProcessor via a JUnit 5 Extension to avoid the Noop fallback?
- What is the recommended pattern for ensuring spans are captured in short‑lived test processes that do not call SdkTracerProvider.shutdown()?
- How can we detect accidental use of NoopTracerProvider in a CI pipeline without inspecting test code?