Skip to content

Commit f4b6093

Browse files
committed
feat: register llm.agent.phase slot and add phase set/clear API
1 parent 999dc00 commit f4b6093

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

  • dd-java-agent/agent-profiling/profiling-ddprof/src/main/java/com/datadog/profiling/ddprof

dd-java-agent/agent-profiling/profiling-ddprof/src/main/java/com/datadog/profiling/ddprof/DatadogProfiler.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isCpuProfilerEnabled;
1818
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isLiveHeapSizeTrackingEnabled;
1919
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isMemoryLeakProfilingEnabled;
20+
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isLlmPhaseAttributeEnabled;
2021
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isResourceNameContextAttributeEnabled;
2122
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isSpanNameContextAttributeEnabled;
2223
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isTrackingGenerations;
@@ -69,6 +70,7 @@ public final class DatadogProfiler {
6970

7071
private static final String OPERATION = "_dd.trace.operation";
7172
private static final String RESOURCE = "_dd.trace.resource";
73+
private static final String LLM_PHASE = "llm.agent.phase";
7274

7375
private static final int MAX_NUM_ENDPOINTS = 8192;
7476

@@ -105,6 +107,7 @@ public static DatadogProfiler newInstance(ConfigProvider configProvider) {
105107
private final Set<ProfilingMode> profilingModes = EnumSet.noneOf(ProfilingMode.class);
106108

107109
private final ContextSetter contextSetter;
110+
private final int llmPhaseOffset;
108111

109112
private final List<String> orderedContextAttributes;
110113

@@ -150,7 +153,11 @@ private DatadogProfiler(ConfigProvider configProvider) {
150153
if (isResourceNameContextAttributeEnabled(configProvider)) {
151154
orderedContextAttributes.add(RESOURCE);
152155
}
156+
if (isLlmPhaseAttributeEnabled(configProvider)) {
157+
orderedContextAttributes.add(LLM_PHASE);
158+
}
153159
this.contextSetter = new ContextSetter(profiler, orderedContextAttributes);
160+
this.llmPhaseOffset = contextSetter.offsetOf(LLM_PHASE);
154161
this.queueTimeThresholdMillis =
155162
configProvider.getLong(
156163
PROFILING_QUEUEING_TIME_THRESHOLD_MILLIS,
@@ -408,6 +415,14 @@ public boolean clearContextValue(int offset) {
408415
return false;
409416
}
410417

418+
public boolean setAgentPhase(String phaseToken) {
419+
return contextSetter.setContextValue(llmPhaseOffset, phaseToken);
420+
}
421+
422+
public boolean clearAgentPhase() {
423+
return contextSetter.clearContextValue(llmPhaseOffset);
424+
}
425+
411426
private void debugLogging(long localRootSpanId) {
412427
if (detailedDebugLogging && log.isDebugEnabled()) {
413428
log.debug("localRootSpanId={}", localRootSpanId, new Throwable());

0 commit comments

Comments
 (0)