-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de6194d
commit a55367c
Showing
15 changed files
with
790 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
classpath group: 'org.jetbrains.kotlin', name: 'kotlin-gradle-plugin', version: libs.versions.kotlin.get() | ||
} | ||
} | ||
|
||
plugins { | ||
id 'com.github.johnrengelman.shadow' | ||
id 'java-test-fixtures' | ||
} | ||
|
||
apply from: "$rootDir/gradle/java.gradle" | ||
apply from: "$rootDir/gradle/version.gradle" | ||
apply from: "$rootDir/gradle/test-with-kotlin.gradle" | ||
|
||
minimumBranchCoverage = 0.0 | ||
minimumInstructionCoverage = 0.0 | ||
|
||
dependencies { | ||
api libs.slf4j | ||
|
||
implementation project(':communication') | ||
implementation project(':components:json') | ||
implementation project(':internal-api') | ||
|
||
testImplementation project(":utils:test-utils") | ||
|
||
testFixturesApi project(':dd-java-agent:testing') | ||
testFixturesApi project(':utils:test-utils') | ||
} | ||
|
||
shadowJar { | ||
dependencies deps.excludeShared | ||
} | ||
|
||
jar { | ||
archiveClassifier = 'unbundled' | ||
} |
22 changes: 22 additions & 0 deletions
22
dd-java-agent/agent-llmobs/src/main/java/datadog/trace/llmobs/LLMObsServices.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package datadog.trace.llmobs; | ||
|
||
import datadog.communication.BackendApi; | ||
import datadog.communication.BackendApiFactory; | ||
import datadog.communication.ddagent.SharedCommunicationObjects; | ||
import datadog.trace.api.Config; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class LLMObsServices { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(LLMObsServices.class); | ||
|
||
final Config config; | ||
final BackendApi backendApi; | ||
|
||
LLMObsServices(Config config, SharedCommunicationObjects sco) { | ||
this.config = config; | ||
this.backendApi = | ||
new BackendApiFactory(config, sco).createBackendApi(BackendApiFactory.Intake.LLMOBS_API); | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
dd-java-agent/agent-llmobs/src/main/java/datadog/trace/llmobs/LLMObsSystem.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package datadog.trace.llmobs; | ||
|
||
import datadog.communication.ddagent.SharedCommunicationObjects; | ||
import datadog.trace.api.Config; | ||
import datadog.trace.api.llmobs.LLMObs; | ||
import datadog.trace.api.llmobs.LLMObsSpan; | ||
import datadog.trace.api.llmobs.LLMObsTags; | ||
import datadog.trace.bootstrap.instrumentation.api.Tags; | ||
import datadog.trace.llmobs.domain.DDLLMObsSpan; | ||
import datadog.trace.llmobs.domain.LLMObsInternal; | ||
import java.lang.instrument.Instrumentation; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class LLMObsSystem { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(LLMObsSystem.class); | ||
|
||
public static void start(Instrumentation inst, SharedCommunicationObjects sco) { | ||
Config config = Config.get(); | ||
if (!config.isLlmObsEnabled()) { | ||
LOGGER.debug("LLM Observability is disabled"); | ||
return; | ||
} | ||
|
||
sco.createRemaining(config); | ||
|
||
LLMObsServices llmObsServices = new LLMObsServices(config, sco); | ||
LLMObsInternal.setLLMObsSpanFactory( | ||
new LLMObsManualSpanFactory( | ||
config.getLlmObsMlApp(), config.getServiceName(), llmObsServices)); | ||
} | ||
|
||
private static class LLMObsManualSpanFactory implements LLMObs.LLMObsSpanFactory { | ||
|
||
private final LLMObsServices llmObsServices; | ||
private final String serviceName; | ||
private final String defaultMLApp; | ||
|
||
public LLMObsManualSpanFactory( | ||
String defaultMLApp, String serviceName, LLMObsServices llmObsServices) { | ||
this.defaultMLApp = defaultMLApp; | ||
this.llmObsServices = llmObsServices; | ||
this.serviceName = serviceName; | ||
} | ||
|
||
@Override | ||
public LLMObsSpan startLLMSpan( | ||
String spanName, | ||
String modelName, | ||
String modelProvider, | ||
@Nullable String mlApp, | ||
@Nullable String sessionID) { | ||
|
||
DDLLMObsSpan span = | ||
new DDLLMObsSpan( | ||
Tags.LLMOBS_LLM_SPAN_KIND, spanName, getMLApp(mlApp), sessionID, serviceName); | ||
|
||
span.setTag(LLMObsTags.MODEL_NAME, modelName); | ||
span.setTag(LLMObsTags.MODEL_PROVIDER, modelProvider); | ||
return span; | ||
} | ||
|
||
@Override | ||
public LLMObsSpan startAgentSpan( | ||
String spanName, @Nullable String mlApp, @Nullable String sessionID) { | ||
return new DDLLMObsSpan( | ||
Tags.LLMOBS_AGENT_SPAN_KIND, spanName, getMLApp(mlApp), sessionID, serviceName); | ||
} | ||
|
||
@Override | ||
public LLMObsSpan startToolSpan( | ||
String spanName, @Nullable String mlApp, @Nullable String sessionID) { | ||
return new DDLLMObsSpan( | ||
Tags.LLMOBS_TOOL_SPAN_KIND, spanName, getMLApp(mlApp), sessionID, serviceName); | ||
} | ||
|
||
@Override | ||
public LLMObsSpan startTaskSpan( | ||
String spanName, @Nullable String mlApp, @Nullable String sessionID) { | ||
return new DDLLMObsSpan( | ||
Tags.LLMOBS_TASK_SPAN_KIND, spanName, getMLApp(mlApp), sessionID, serviceName); | ||
} | ||
|
||
@Override | ||
public LLMObsSpan startWorkflowSpan( | ||
String spanName, @Nullable String mlApp, @Nullable String sessionID) { | ||
return new DDLLMObsSpan( | ||
Tags.LLMOBS_WORKFLOW_SPAN_KIND, spanName, getMLApp(mlApp), sessionID, serviceName); | ||
} | ||
|
||
private String getMLApp(String mlApp) { | ||
if (mlApp == null || mlApp.isEmpty()) { | ||
return defaultMLApp; | ||
} | ||
return mlApp; | ||
} | ||
} | ||
} |
Oops, something went wrong.