Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isCpuProfilerEnabled;
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isLiveHeapSizeTrackingEnabled;
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isMemoryLeakProfilingEnabled;
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isLlmPhaseAttributeEnabled;
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isResourceNameContextAttributeEnabled;
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isSpanNameContextAttributeEnabled;
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isTrackingGenerations;
Expand Down Expand Up @@ -69,6 +70,7 @@ public final class DatadogProfiler {

private static final String OPERATION = "_dd.trace.operation";
private static final String RESOURCE = "_dd.trace.resource";
private static final String LLM_PHASE = "llm.agent.phase";

private static final int MAX_NUM_ENDPOINTS = 8192;

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

private final ContextSetter contextSetter;
private final int llmPhaseOffset;

private final List<String> orderedContextAttributes;

Expand Down Expand Up @@ -150,7 +153,11 @@ private DatadogProfiler(ConfigProvider configProvider) {
if (isResourceNameContextAttributeEnabled(configProvider)) {
orderedContextAttributes.add(RESOURCE);
}
if (isLlmPhaseAttributeEnabled(configProvider)) {
orderedContextAttributes.add(LLM_PHASE);
}
this.contextSetter = new ContextSetter(profiler, orderedContextAttributes);
this.llmPhaseOffset = contextSetter.offsetOf(LLM_PHASE);
this.queueTimeThresholdMillis =
configProvider.getLong(
PROFILING_QUEUEING_TIME_THRESHOLD_MILLIS,
Expand Down Expand Up @@ -408,6 +415,14 @@ public boolean clearContextValue(int offset) {
return false;
}

public boolean setAgentPhase(String phaseToken) {
return contextSetter.setContextValue(llmPhaseOffset, phaseToken);
}

public boolean clearAgentPhase() {
return contextSetter.clearContextValue(llmPhaseOffset);
}

private void debugLogging(long localRootSpanId) {
if (detailedDebugLogging && log.isDebugEnabled()) {
log.debug("localRootSpanId={}", localRootSpanId, new Throwable());
Expand Down
Loading