- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
",t};e.buildCustomizationMenuUi=t;function n(e){let t='
",t}function s(e){let n=e.filter.currentValue||e.filter.defaultValue,t='${e.filter.label}
`,e.filter.options.forEach(s=>{let o=s.id===n;t+=``}),t+="${e.filter.label}
`,t+=`The LLM Observability SDK for Java (BETA) enhances the observability of your Java-based LLM applications. The SDK supports Java versions 8 and newer. For information about LLM Observability’s integration support, see Auto Instrumentation.
You can install and configure tracing of various operations such as workflows, tasks, and API calls with wrapped functions or traced blocks. You can also annotate these traces with metadata for deeper insights into the performance and behavior of your applications, supporting multiple LLM services or models from the same environment.
The beta dd-trace-java
JAR must be downloaded to a folder that is accessible by your Datadog user, please contact our team for access.
LLM Observability requires a Datadog API key (see the instructions for creating an API key).
DD_SITE=
DD_API_KEY=<YOUR_API_KEY> \
java -javaagent:path/to/your/dd-trace-java-jar/dd-java-agent-SNAPSHOT.jar \
-Ddd.service=my-app -Ddd.llmobs.enabled=true -Ddd.llmobs.ml.app=my-ml-app -jar path/to/your/app.jar
Environment Variable | System Property | Description |
---|---|---|
DD_SITE | dd.site | The Datadog site to submit your LLM data. Your site is . |
DD_LLMOBS_ENABLED | dd.llmobs.enabled | Toggle to enable submitting data to LLM Observability. Should be set to true . |
DD_LLMOBS_ML_APP | dd.llmobs.ml.app | The name of your LLM application, service, or project, under which all traces and spans are grouped. This helps distinguish between different applications or experiments. See Application naming guidelines for allowed characters and other constraints. |
DD_SERVICE | dd.service | The name of a set of processes that do the same job. Used for grouping stats for your application. |
DD_LLMOBS_AGENTLESS_ENABLED | dd.llmobs.agentless.enabled | Only required if you are not using the Datadog Agent, in which case this should be set to true . Defaults to false . |
DD_API_KEY | dd.api.key | Your Datadog API key. Only required if you are not using the Datadog Agent. |
Your application name (the value of DD_LLMOBS_ML_APP
or dd.llmobs.ml.app
) must be a lowercase Unicode string. It may contain the characters listed below:
The name can be up to 193 characters long and may not contain contiguous or trailing underscores.
There are several different methods to start a span, based on the kind of span that you are starting. See the Span Kinds documentation for a list of supported span kinds.
All spans are started as an object instance of LLMObsSpan
. And spans have methods that you can use to interact with and record data with.
Spans must be finished for the trace to be submitted and visible in the Datadog app.
Spans can be finished by calling finish()
on a span object instance. It is recommended, if possible, to wrap the span with a try/finally
block, to ensure the span is submitted in case of exceptions.
try {
LLMObsSpan workflowSpan = LLMObs.startWorkflowSpan("my-workflow-span-name", "ml-app-override", "session-141");
// user logic
// interact with started span
} finally {
workflowSpan.finish();
}
To trace an LLM span, import and call the following method with the arguments listed below
import datadog.trace.api.llmobs.LLMObs;
LLMObs.startLLMSpan(spanName, modelName, modelProvider, mlApp, sessionID);
spanName
spanName
defaults to the kind of the span.modelName
"custom"
modelProvider
"custom"
mlApp
sessionId
import datadog.trace.api.llmobs.LLMObs;
public class MyJavaClass {
public String invokeModel() {
LLMObsSpan llmSpan = LLMObs.startLLMSpan("my-llm-span-name", "my-llm-model", "my-company", "maybe-ml-app-override", "session-141");
String inference = ... // user application logic to invoke LLM
llmSpan.annotateIO(...); // record the input and output
llmSpan.finish();
return inference;
}
}
To trace a workflow span, import and call the following method with the arguments listed below
import datadog.trace.api.llmobs.LLMObs;
LLMObs.startWorkflowSpan(spanName, mlApp, sessionID);
spanName
spanName
defaults to the kind of the span.mlApp
sessionId
import datadog.trace.api.llmobs.LLMObs;
public class MyJavaClass {
public String executeWorkflow() {
LLMObsSpan workflowSpan = LLMObs.startWorkflowSpan("my-workflow-span-name", null, "session-141");
String workflowResult = workflowFn(); // user application logic
workflowSpan.annotateIO(...); // record the input and output
workflowSpan.finish();
return workflowResult;
}
}
To trace an agent span, import and call the following method with the arguments listed below
import datadog.trace.api.llmobs.LLMObs;
LLMObs.startAgentSpan(spanName, mlApp, sessionID);
spanName
spanName
defaults to the name of the traced function.mlApp
sessionId
To trace a tool span, import and call the following method with the arguments listed below
import datadog.trace.api.llmobs.LLMObs;
LLMObs.startToolSpan(spanName, mlApp, sessionID);
spanName
spanName
defaults to the name of the traced function.mlApp
sessionId
To trace a task span, import and call the following method with the arguments listed below
import datadog.trace.api.llmobs.LLMObs;
LLMObs.startTaskSpan(spanName, mlApp, sessionID);
spanName
spanName
defaults to the name of the traced function.mlApp
sessionId
Session tracking allows you to associate multiple interactions with a given user. When starting a root span for a new trace or span in a new process, specify the sessionId
argument with the string ID of the underlying user session:
import datadog.trace.api.llmobs.LLMObs;
public class MyJavaClass {
public String processChat(int userID) {
LLMObsSpan workflowSpan = LLMObs.startWorkflowSpan("incoming-chat", null, "session-" + System.currentTimeMillis() + "-" + userID);
String chatResponse = answerChat(); // user application logic
workflowSpan.annotateIO(...); // record the input and output
workflowSpan.finish();
return chatResponse;
}
}
The SDK provides several methods to annotate spans with inputs, outputs, metrics, and metadata.
The annotateIO()
member method of a span (specifically the LLMObsSpan
interface) accepts the following arguments:
If any of these arguments are null or empty, nothing will happen. For example, if inputData
is a non empty string while outputData
is null, then only the inputData
will be recorded.
inputData
String
or List<LLMObs.LLMMessage>
LLMObs.LLMMessage
’s for LLM spans.outputData
String
or List<LLMObs.LLMMessage>
LLMObs.LLMMessage
’s for LLM spans.LLM spans must be annotated with LLM Messages using the LLMObs.LLMMessage
object.
The LLMObs.LLMMessage
object can be instantiated by callling LLMObs.LLMMessage.from()
with the following arguments:
role
content
import datadog.trace.api.llmobs.LLMObs;
public class MyJavaClass {
public String invokeChat(String userInput) {
LLMObsSpan llmSpan = LLMObs.startLLMSpan("my-llm-span-name", "my-llm-model", "my-company", "maybe-ml-app-override", "session-141");
String systemMessage = "You are a helpful assistant";
Response chatResponse = ... // user application logic to invoke LLM
llmSpan.annotateIO(
Arrays.asList(
LLMObs.LLMMessage.from("user", userInput),
LLMObs.LLMMessage.from("system", systemMessage)
),
Arrays.asList(
LLMObs.LLMMessage.from(chatResponse.role, chatResponse.content)
)
);
llmSpan.finish();
return chatResponse;
}
}
The setMetrics()
member method of a span (specifically the LLMObsSpan
interface) accepts the following arguments to attach multiple metrics in bulk:
metrics
Map<String, Number>
The setMetric()
member method of a span (specifically the LLMObsSpan
interface) accepts the following arguments to attach a single metric:
key
CharSequence
value
int
, long
, double
import datadog.trace.api.llmobs.LLMObs;
public class MyJavaClass {
public String invokeChat(String userInput) {
LLMObsSpan llmSpan = LLMObs.startLLMSpan("my-llm-span-name", "my-llm-model", "my-company", "maybe-ml-app-override", "session-141");
String chatResponse = ... // user application logic to invoke LLM
llmSpan.setMetrics(Map.of(
"input_tokens", 617,
"output_tokens", 338,
"time_per_output_token", 0.1773
));
llmSpan.setMetric("total_tokens", 955);
llmSpan.setMetric("time_to_first_token", 0.23);
llmSpan.finish();
return chatResponse;
}
}
For more information about tags, see Getting Started with Tags.
The setTags()
member method of a span (specifically the LLMObsSpan
interface) accepts the following arguments to attach multiple tags in bulk:
tags
Map<String, Object>
The setTag()
member method of a span (specifically the LLMObsSpan
interface) accepts the following arguments to attach a single tag:
key
String
value
int
, long
, double
, boolean
, String
import datadog.trace.api.llmobs.LLMObs;
public class MyJavaClass {
public String invokeChat(String userInput) {
LLMObsSpan llmSpan = LLMObs.startLLMSpan("my-llm-span-name", "my-llm-model", "my-company", "maybe-ml-app-override", "session-141");
String chatResponse = ... // user application logic to invoke LLM
llmSpan.setTags(Map.of(
"chat_source", "web",
"users_in_chat", 3
));
llmSpan.setTag("is_premium_user", true);
llmSpan.finish();
return chatResponse;
}
}
The addThrowable()
member method of a span (specifically the LLMObsSpan
interface) accepts the following argument to attach a throwable with a stack trace:
throwable
Throwable
The setErrorMessage()
member method of a span (specifically the LLMObsSpan
interface) accepts the following argument to attach an error string:
errorMessage
String
The setError()
member method of a span (specifically the LLMObsSpan
interface) accepts the following argument to indicate an error with the operation:
error
boolean
true
if the span erroredimport datadog.trace.api.llmobs.LLMObs;
public class MyJavaClass {
public String invokeChat(String userInput) {
LLMObsSpan llmSpan = LLMObs.startLLMSpan("my-llm-span-name", "my-llm-model", "my-company", "maybe-ml-app-override", "session-141");
String chatResponse = "N/A";
try {
chatResponse = ... // user application logic to invoke LLM
} catch (Exception e) {
llmSpan.addThrowable(e);
throw new RuntimeException(e);
} finally {
llmSpan.finish();
}
return chatResponse;
}
}
The setMetadata()
member method of the LLMObsSpan
interface accepts the following arguments:
metadata
import datadog.trace.api.llmobs.LLMObs;
public class MyJavaClass {
public String invokeChat(String userInput) {
LLMObsSpan llmSpan = LLMObs.startLLMSpan("my-llm-span-name", "my-llm-model", "my-company", "maybe-ml-app-override", "session-141");
llmSpan.setMetadata(
Map.of(
"temperature", 0.5,
"is_premium_member", true,
"class", "e1"
)
);
String chatResponse = ... // user application logic to invoke LLM
return chatResponse;
}
}
The LLM Observability SDK provides the methods LLMObs.SubmitEvaluation()
to help your traced LLM application submit evaluations to LLM Observability.
LLMObs.SubmitEvaluation()
can be used to submit your custom evaluation associated with a given span.
The LLMObs.SubmitEvaluation()
method accepts the following arguments:
llmObsSpan
label
categoricalValue
or scoreValue
tags
import datadog.trace.api.llmobs.LLMObs;
public class MyJavaClass {
public String invokeChat(String userInput) {
LLMObsSpan llmSpan = LLMObs.startLLMSpan("my-llm-span-name", "my-llm-model", "my-company", "maybe-ml-app-override", "session-141");
String chatResponse = "N/A";
try {
chatResponse = ... // user application logic to invoke LLM
} catch (Exception e) {
llmSpan.addThrowable(e);
throw new RuntimeException(e);
} finally {
llmSpan.finish();
// submit evaluations
LLMObs.SubmitEvaluation(llmSpan, "toxicity", "toxic", Map.of("language", "english"));
LLMObs.SubmitEvaluation(llmSpan, "f1-similarity", 0.02, Map.of("provider", "f1-calculator"));
}
return chatResponse;
}
}