Files
rippled/include/xrpl/telemetry/DiscardFlag.h
Pratik Mankawde 4bb2030315 feat(telemetry): add FilteringSpanProcessor and SpanGuard::discard()
Add span discard mechanism that drops unwanted spans before they enter
the batch export queue, saving both network bandwidth and storage.

FilteringSpanProcessor is a custom SpanProcessor decorator that wraps
BatchSpanProcessor. SpanGuard::discard() sets a thread-local flag
(tl_discardCurrentSpan) before calling Span::End(). The OTel SDK calls
OnEnd() synchronously on the same thread, where the flag is checked and
cleared to drop the span.

New file: DiscardFlag.h — zero-dependency header for the thread-local
flag, avoiding transitive include bloat from Telemetry.h.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-28 14:25:31 +01:00

28 lines
1005 B
C++

#pragma once
/** Thread-local flag for span discard signaling.
SpanGuard::discard() sets tl_discardCurrentSpan to true before calling
Span::End(). The OTel SDK calls SpanProcessor::OnEnd() synchronously on
the same thread, so FilteringSpanProcessor checks and clears this flag
in OnEnd() to drop the span before it enters the batch export queue.
This side-channel avoids inspecting the Recordable's internals (which
vary by exporter type — SpanData vs OtlpRecordable).
Kept in a separate header to avoid transitive include bloat: SpanGuard.h
only needs this flag, not the full Telemetry.h with BasicConfig/Journal.
@see SpanGuard::discard(), FilteringSpanProcessor (Telemetry.cpp)
*/
namespace xrpl {
namespace telemetry {
/** When true, the FilteringSpanProcessor drops the current span in
OnEnd(). Set by SpanGuard::discard(), cleared by OnEnd(). */
inline thread_local bool tl_discardCurrentSpan = false;
} // namespace telemetry
} // namespace xrpl