From 179048dc738d4f7dd2cd4bca153cae9567a59192 Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Wed, 3 Jun 2026 16:28:10 +0200 Subject: [PATCH] fix: emit context attributes regardless of active span MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Context attributes (e.g. llm.agent.phase) were silently dropped from ExecutionSample events when no span was active, because ProfiledThread was only fetched when hasContext was true. ProfiledThread::currentSignalSafe() is a pure TLS lookup — signal-safe, never allocates — and is safe to call unconditionally. Span IDs are still zeroed when no span is active (ContextApi::get fills them only on success). Co-Authored-By: Claude Sonnet 4.6 --- ddprof-lib/src/main/cpp/flightRecorder.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ddprof-lib/src/main/cpp/flightRecorder.cpp b/ddprof-lib/src/main/cpp/flightRecorder.cpp index 3b788efc1..7d4591b5e 100644 --- a/ddprof-lib/src/main/cpp/flightRecorder.cpp +++ b/ddprof-lib/src/main/cpp/flightRecorder.cpp @@ -1699,14 +1699,14 @@ 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. + ContextApi::get(spanId, rootSpanId); buf->putVar64(spanId); buf->putVar64(rootSpanId); size_t numAttrs = Profiler::instance()->numContextAttributes(); - ProfiledThread* thrd = hasContext ? ProfiledThread::currentSignalSafe() : nullptr; + ProfiledThread* thrd = ProfiledThread::currentSignalSafe(); for (size_t i = 0; i < numAttrs; i++) { buf->putVar32(thrd != nullptr ? thrd->getOtelTagEncoding(i) : 0); }