Skip to content

feat(profiling): add AgentPhase enum and ContextSetter.readContextValue#573

Draft
jbachorik wants to merge 2 commits into
mainfrom
jb/llm-jp-1-enum
Draft

feat(profiling): add AgentPhase enum and ContextSetter.readContextValue#573
jbachorik wants to merge 2 commits into
mainfrom
jb/llm-jp-1-enum

Conversation

@jbachorik
Copy link
Copy Markdown
Collaborator

@jbachorik jbachorik commented Jun 2, 2026

What does this PR do?:
Adds the AgentPhase enum to com.datadoghq.profiler — the contract between java-profiler and dd-trace-java for LLM pipeline phase attribution. Also adds ContextSetter.readContextValue to enable test-time readback of custom attribute slots.

AgentPhase defines 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:

  • No native changes; no new JNI setters.
  • Spec: doc/specs/2026-06-02-llm-phase-attribution-design.md (commit ebdb351, also in this PR).
  • Stacked on: base (main). Next: [jp-2-test] adds the ddprof-test unit test.

How to test the change?:

./gradlew :ddprof-lib:compileJava

Full end-to-end test is in the next PR in the stack.

For Datadog employees:

  • This PR doesn't touch any of that.
  • JIRA: PROF-14859

@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented Jun 2, 2026

CI Test Results

Run: #26822354954 | Commit: 8a29393 | Duration: 15m 18s (longest job)

All 32 test jobs passed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
8 - - -
8-ibm - - -
8-j9 - -
8-librca - -
8-orcl - - -
11 - - -
11-j9 - -
11-librca - -
17 - -
17-graal - -
17-j9 - -
17-librca - -
21 - -
21-graal - -
21-librca - -
25 - -
25-graal - -
25-librca - -

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

Summary: Total: 32 | Passed: 32 | Failed: 0


Updated: 2026-06-02 13:37:08 UTC

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.AgentPhase with 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants