feat(profiling): add AgentPhase enum and ContextSetter.readContextValue#573
Draft
jbachorik wants to merge 2 commits into
Draft
feat(profiling): add AgentPhase enum and ContextSetter.readContextValue#573jbachorik wants to merge 2 commits into
jbachorik wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2 tasks
Contributor
CI Test ResultsRun: #26822354954 | Commit:
Status Overview
Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled Summary: Total: 32 | Passed: 32 | Failed: 0 Updated: 2026-06-02 13:37:08 UTC |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds the public Java-side contract for LLM phase attribution and a small API extension to support reading back profiling context attributes (primarily for tests), plus a design spec documenting the intended end-to-end architecture between java-profiler and dd-trace-java.
Changes:
- Introduces
com.datadoghq.profiler.AgentPhasewith stable lowercase tokens and the shared attribute name (llm.agent.phase). - Adds
ContextSetter.readContextValue(int offset)to enable reading the current thread’s custom context attribute value. - Adds a design spec describing the hybrid representation (enum contract + existing dictionary-encoded context attribute slots).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| doc/specs/2026-06-02-llm-phase-attribution-design.md | Adds the LLM phase attribution design spec and integration references. |
| ddprof-lib/src/main/java/com/datadoghq/profiler/ContextSetter.java | Adds a readback method for context attributes to support validation in tests. |
| ddprof-lib/src/main/java/com/datadoghq/profiler/AgentPhase.java | Adds the shared phase enum contract (tokens + attribute name constant). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+148
to
+156
| | Concern | Location | | ||
| |---|---| | ||
| | Attribute slots, async-signal-safe read | `ddprof-lib/.../cpp/thread.h:250` (`getOtelTagEncoding`) | | ||
| | Tag encodings emitted on CPU samples | `ddprof-lib/.../cpp/flightRecorder.cpp:1700-1713` | | ||
| | Java attribute setter | `ddprof-lib/.../java/com/datadoghq/profiler/ContextSetter.java` | | ||
| | Startup attribute set | dd-trace-java `DatadogProfilerConfig.getContextAttributes` | | ||
| | ContextSetter wiring | dd-trace-java `DatadogProfiler.java:153` | | ||
| | Profiler context bridge | dd-trace-java `DatadogProfilingIntegration.java` | | ||
| | Profiling API surface | dd-trace-java `dd-trace-api/.../profiling/ProfilingContext.java` | |
Comment on lines
+65
to
+71
| public String readContextValue(int offset) { | ||
| if (offset < 0) { | ||
| return null; | ||
| } | ||
| ThreadContext ctx = profiler.getThreadContext(); | ||
| return ctx != null ? ctx.readContextAttribute(offset) : null; | ||
| } |
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?:
Adds the
AgentPhaseenum tocom.datadoghq.profiler— the contract between java-profiler and dd-trace-java for LLM pipeline phase attribution. Also addsContextSetter.readContextValueto enable test-time readback of custom attribute slots.AgentPhasedefines 9 phases with stable lowercase string tokens ("awaiting_inference","tool_execution", etc.) and the well-known attribute name constant ("llm.agent.phase"). Both sides of the integration agree on these tokens by depending on this enum.Motivation:
Part of the LLM profiling foundation (PROF-14858). Flamegraphs for LLM-based JVM services are undifferentiated — this is the first step toward phase-keyed CPU profiles.
Additional Notes:
doc/specs/2026-06-02-llm-phase-attribution-design.md(commit ebdb351, also in this PR).How to test the change?:
Full end-to-end test is in the next PR in the stack.
For Datadog employees: