fix: emit context attributes regardless of active span#575
Draft
jbachorik wants to merge 1 commit into
Draft
Conversation
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 <noreply@anthropic.com>
Contributor
CI Test ResultsRun: #26891493504 | Commit:
Status Overview
Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled Summary: Total: 32 | Passed: 32 | Failed: 0 Updated: 2026-06-03 14:46:47 UTC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?:
Context attributes (e.g.
llm.agent.phase) were silently dropped fromExecutionSampleevents when no span was active. InRecording::writeCurrentContext,ProfiledThreadwas only fetched whenhasContextwas true — buthasContextonly reflects whether a span is active, not whether thread-local context attributes exist.Motivation:
ProfiledThread::currentSignalSafe()is a pure TLS lookup: signal-safe, never allocates, returnsnullptrif the key is not yet initialized. It is safe to call unconditionally. The existing null-check in the attributes loop (thrd != nullptr ? thrd->getOtelTagEncoding(i) : 0) already handles the no-thread case correctly.Span IDs continue to be written as zero when no span is active —
ContextApi::getonly fills them on success, which is unaffected by this change.Additional Notes:
The old variable
hasContextwas renamed away (its return value is now discarded) because the name was misleading: LLM phase and other thread-local attributes ARE context, sohasContext = falsewhile attributes are set is a contradiction.How to test the change?:
AgentPhaseProfilingTestinddprof-testcovers the case: a worker thread setsllm.agent.phasewithout any active span and verifies thatExecutionSampleevents carry the value.For Datadog employees:
credentials of any kind, I've requested a review from
@DataDog/security-design-and-guidance.