|
17 | 17 | import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isCpuProfilerEnabled; |
18 | 18 | import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isLiveHeapSizeTrackingEnabled; |
19 | 19 | import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isMemoryLeakProfilingEnabled; |
| 20 | +import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isLlmPhaseAttributeEnabled; |
20 | 21 | import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isResourceNameContextAttributeEnabled; |
21 | 22 | import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isSpanNameContextAttributeEnabled; |
22 | 23 | import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isTrackingGenerations; |
@@ -69,6 +70,7 @@ public final class DatadogProfiler { |
69 | 70 |
|
70 | 71 | private static final String OPERATION = "_dd.trace.operation"; |
71 | 72 | private static final String RESOURCE = "_dd.trace.resource"; |
| 73 | + private static final String LLM_PHASE = "llm.agent.phase"; |
72 | 74 |
|
73 | 75 | private static final int MAX_NUM_ENDPOINTS = 8192; |
74 | 76 |
|
@@ -105,6 +107,7 @@ public static DatadogProfiler newInstance(ConfigProvider configProvider) { |
105 | 107 | private final Set<ProfilingMode> profilingModes = EnumSet.noneOf(ProfilingMode.class); |
106 | 108 |
|
107 | 109 | private final ContextSetter contextSetter; |
| 110 | + private final int llmPhaseOffset; |
108 | 111 |
|
109 | 112 | private final List<String> orderedContextAttributes; |
110 | 113 |
|
@@ -150,7 +153,11 @@ private DatadogProfiler(ConfigProvider configProvider) { |
150 | 153 | if (isResourceNameContextAttributeEnabled(configProvider)) { |
151 | 154 | orderedContextAttributes.add(RESOURCE); |
152 | 155 | } |
| 156 | + if (isLlmPhaseAttributeEnabled(configProvider)) { |
| 157 | + orderedContextAttributes.add(LLM_PHASE); |
| 158 | + } |
153 | 159 | this.contextSetter = new ContextSetter(profiler, orderedContextAttributes); |
| 160 | + this.llmPhaseOffset = contextSetter.offsetOf(LLM_PHASE); |
154 | 161 | this.queueTimeThresholdMillis = |
155 | 162 | configProvider.getLong( |
156 | 163 | PROFILING_QUEUEING_TIME_THRESHOLD_MILLIS, |
@@ -408,6 +415,14 @@ public boolean clearContextValue(int offset) { |
408 | 415 | return false; |
409 | 416 | } |
410 | 417 |
|
| 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 | + |
411 | 426 | private void debugLogging(long localRootSpanId) { |
412 | 427 | if (detailedDebugLogging && log.isDebugEnabled()) { |
413 | 428 | log.debug("localRootSpanId={}", localRootSpanId, new Throwable()); |
|
0 commit comments