diff --git a/ddprof-lib/src/main/cpp/flightRecorder.cpp b/ddprof-lib/src/main/cpp/flightRecorder.cpp index 3b788efc1..794e45ed7 100644 --- a/ddprof-lib/src/main/cpp/flightRecorder.cpp +++ b/ddprof-lib/src/main/cpp/flightRecorder.cpp @@ -1699,9 +1699,11 @@ void Recording::writeContextSnapshot(Buffer *buf, Context &context) { void Recording::writeCurrentContext(Buffer *buf) { u64 spanId = 0; u64 rootSpanId = 0; - bool hasContext = ContextApi::get(spanId, rootSpanId); // spanId/rootSpanId are initialized to 0 above; ContextApi::get() only updates them - // on success, so 0s are always written when there is no valid context. + // on success, so 0s are always written when there is no active span. + // hasContext gates sidecar reads: getOtelTagEncoding() must only be called + // when valid=1 (see thread.h read invariant). + bool hasContext = ContextApi::get(spanId, rootSpanId); buf->putVar64(spanId); buf->putVar64(rootSpanId);