8000 Gary/llmobs java sdk integration by gary-huang · Pull Request #8519 · DataDog/dd-trace-java · GitHub
[go: up one dir, main page]

Skip to content

Gary/llmobs java sdk integration #8519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 37 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5134311
add APIs for llm obs
gary-huang Sep 19, 2024
b5c7a0a
add llm message class to support llm spans
gary-huang Mar 6, 2025
7f8f586
add llm message class to support llm spans
gary-huang Mar 6, 2025
9206dbe
impl llmobs agent and llmobs apis
gary-huang Jan 27, 2025
f5efd26
support llm messages with tool calls
gary-huang Mar 6, 2025
76740e9
handle default model name and provider
gary-huang Mar 26, 2025
5e66a2f
rm unneeded file
gary-huang Apr 11, 2025
75290af
impl llmobs agent and llmobs apis
gary-huang Jan 27, 2025
7b2db7c
impl llmobs agent
gary-huang Jan 27, 2025
d76c94d
working writer
gary-huang Feb 7, 2025
e0b4510
add support for llm message and tool calls
gary-huang Mar 6, 2025
87cdaf1
impl llmobs agent and llmobs apis
gary-huang Jan 27, 2025
f78b2c5
use new ctx api to track parent span
gary-huang Apr 1, 2025
5fc9069
add api for evals
gary-huang Mar 5, 2025
a74e456
working impl supporting both agentless and agent
gary-huang Mar 6, 2025
19d95d7
handle null tags and default to default ml app if null or empty strin…
gary-huang Apr 21, 2025
f1481ac
spotless
gary-huang Apr 23, 2025
de0d5a5
spotless
gary-huang Apr 23, 2025
82b8418
add APIs for llm obs sdk (#8135)
gary-huang May 7, 2025
f1d9d17
Merge branch 'gary/llmobs-sdk-merge' into gary/impl-llm-obs-api
gary-huang May 7, 2025
0a790c3
rename ID to Id according to java naming conventions
gary-huang May 7, 2025
d68665d
Merge branch 'gary/impl-llm-obs-api' into gary/add-llm-obs-writer
gary-huang May 7, 2025
0d77da2
Merge branch 'master' into gary/impl-llm-obs-api
gary-huang May 14, 2025
c1c38e4
Undo change to integrations-core submodule
gary-huang May 14, 2025
2be1b73
add APIs for llm obs sdk (#8135)
gary-huang May 7, 2025
d01034a
fix build gradle
gary-huang May 14, 2025
7a74cf6
Merge branch 'gary/llmobs-sdk-merge' into gary/impl-llm-obs-api
gary-huang May 14, 2025
23d6923
rm empty line
gary-huang May 14, 2025
9ac1ab7
fix test
gary-huang May 14, 2025
e382f22
wip add test
gary-huang May 14, 2025
613e6c2
Merge branch 'gary/impl-llm-obs-api' into gary/add-llm-obs-writer
gary-huang May 14, 2025
77291d8
implement LLM Obs SDK spans APIs (#8390)
gary-huang Jun 4, 2025
4739666
use proper convention like Id instead of ID
gary-huang Jun 11, 2025
993cdbe
Merge branch 'master' into gary/llmobs-sdk-merge
gary-huang Jun 11, 2025
20d2760
Merge branch 'gary/add-llm-obs-writer' into gary/llmobs-java-sdk-inte…
gary-huang Jun 11, 2025
8a9d17d
Merge branch 'gary/use-ctx-api' into gary/llmobs-java-sdk-integration
gary-huang Jun 11, 2025
8659686
Merge branch 'gary/submit-evals-2' into gary/llmobs-java-sdk-integration
gary-huang Jun 11, 2025
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
Next Next commit
add APIs for llm obs
  • Loading branch information
gary-huang committed Apr 10, 2025
commit 51343114a4d5cdfaead724f329853dce5ac0ec90
4 changes: 4 additions & 0 deletions dd-trace-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ excludedClassesCoverage += [
'datadog.trace.api.profiling.ProfilingScope',
'datadog.trace.api.profiling.ProfilingContext',
'datadog.trace.api.profiling.ProfilingContextAttribute.NoOp',
'datadog.trace.api.llmobs.LLMObs',
'datadog.trace.api.llmobs.LLMObsSpan',
'datadog.trace.api.llmobs.noop.NoOpLLMObsSpan',
'datadog.trace.api.llmobs.noop.NoOpLLMObsSpanFactory',
'datadog.trace.api.experimental.DataStreamsCheckpointer',
'datadog.trace.api.experimental.DataStreamsCheckpointer.NoOp',
'datadog.trace.api.experimental.DataStreamsContextCarrier',
Expand Down
60 changes: 60 additions & 0 deletions dd-trace-api/src/main/java/datadog/trace/api/llmobs/LLMObs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package datadog.trace.api.llmobs;

import datadog.trace.api.llmobs.noop.NoOpLLMObsSpanFactory;
import javax.annotation.Nullable;

public class LLMObs {
private static LLMObsSpanFactory SPAN_FACTORY = NoOpLLMObsSpanFactory.INSTANCE;

public static LLMObsSpan startLLMSpan(
String spanName,
String modelName,
String modelProvider,
@Nullable String mlApp,
@Nullable String sessionID) {

return SPAN_FACTORY.startLLMSpan(spanName, modelName, modelProvider, mlApp, sessionID);
}

public static LLMObsSpan startAgentSpan(
String spanName, @Nullable String mlApp, @Nullable String sessionID) {

return SPAN_FACTORY.startAgentSpan(spanName, mlApp, sessionID);
}

public static LLMObsSpan startToolSpan(
String spanName, @Nullable String mlApp, @Nullable String sessionID) {

return SPAN_FACTORY.startToolSpan(spanName, mlApp, sessionID);
}

public static LLMObsSpan startTaskSpan(
String spanName, @Nullable String mlApp, @Nullable String sessionID) {

return SPAN_FACTORY.startTaskSpan(spanName, mlApp, sessionID);
}

public static LLMObsSpan startWorkflowSpan(
String spanName, @Nullable String mlApp, @Nullable String sessionID) {

return SPAN_FACTORY.startWorkflowSpan(spanName, mlApp, sessionID);
}

public interface LLMObsSpanFactory {
LLMObsSpan startLLMSpan(
String spanName,
String modelName,
String modelProvider,
@Nullable String mlApp,
@Nullable String sessionID);

LLMObsSpan startAgentSpan(String spanName, @Nullable String mlApp, @Nullable String sessionID);

LLMObsSpan startToolSpan(String spanName, @Nullable String mlApp, @Nullable String sessionID);

LLMObsSpan startTaskSpan(String spanName, @Nullable String mlApp, @Nullable String sessionID);

LLMObsSpan startWorkflowSpan(
String spanName, @Nullable String mlApp, @Nullable String sessionID);
}
}
147 changes: 147 additions & 0 deletions dd-trace-api/src/main/java/datadog/trace/api/llmobs/LLMObsSpan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package datadog.trace.api.llmobs;

import java.util.List;
import java.util.Map;

/** This interface represent an individual LLM Obs span. */
public interface LLMObsSpan {

/**
* Annotate the span with inputs and outputs
*
* @param inputData The input data of the span in the form of a list, for example a list of input
* messages
* @param outputData The output data of the span in the form of a list, for example a list of
* output messages
*/
void annotateIO(List<Map<String, Object>> inputData, List<Map<String, Object>> outputData);

/**
* Annotate the span with inputs and outputs
*
* @param inputData The input data of the span in the form of a string
* @param outputData The output data of the span in the form of a string
*/
void annotateIO(String inputData, String outputData);

/**
* Annotate the span with metadata
*
* @param metadata A map of JSON serializable key-value pairs that contains metadata information
* relevant to the input or output operation described by the span
*/
void setMetadata(Map<String, Object> metadata);

/**
* Annotate the span with metrics
*
* @param metrics A map of JSON serializable keys and numeric values that users can add as metrics
* relevant to the operation described by the span (input_tokens, output_tokens, total_tokens,
* etc.).
*/
void setMetrics(Map<String, Number> metrics);

/**
* Annotate the span with a single metric key value pair for the span’s context (number of tokens
* document length, etc).
*
* @param key the name of the metric
* @param value the value of the metric
*/
void setMetric(CharSequence key, int value);

/**
* Annotate the span with a single metric key value pair for the span’s context (number of tokens
* document length, etc).
*
* @param key the name of the metric
* @param value the value of the metric
*/
void setMetric(CharSequence key, long value);

/**
* Annotate the span with a single metric key value pair for the span’s context (number of tokens
* document length, etc).
*
* @param key the name of the metric
* @param value the value of the metric
*/
void setMetric(CharSequence key, double value);

/**
* Annotate the span with tags
*
* @param tags An map of JSON serializable key-value pairs that users can add as tags regarding
* the span’s context (session, environment, system, versioning, etc.).
*/
void setTags(Map<String, Object> tags);

/**
* Annotate the span with a single tag key value pair as a tag regarding the span’s context
* (session, environment, system, versioning, etc.).
*
* @param key the key of the tag
* @param value the value of the tag
*/
void setTag(String key, String value);

/**
* Annotate the span with a single tag key value pair as a tag regarding the span’s context
* (session, environment, system, versioning, etc.).
*
* @param key the key of the tag
* @param value the value of the tag
*/
void setTag(String key, boolean value);

/**
* Annotate the span with a single tag key value pair as a tag regarding the span’s context
* (session, environment, system, versioning, etc.).
*
* @param key the key of the tag
* @param value the value of the tag
*/
void setTag(String key, int value);

/**
* Annotate the span with a single tag key value pair as a tag regarding the span’s context
* (session, environment, system, versioning, etc.).
*
* @param key the key of the tag
* @param value the value of the tag
*/
void setTag(String key, long value);

/**
* Annotate the span with a single tag key value pair as a tag regarding the span’s context
* (session, environment, 628C system, versioning, etc.).
*
* @param key the key of the tag
* @param value the value of the tag
*/
void setTag(String key, double value);

/**
* Annotate the span to indicate that an error occurred
*
* @param error whether an error occurred
*/
void setError(boolean error);

/**
* Annotate the span with an error message
*
* @param errorMessage the message of the error
*/
void setErrorMessage(String errorMessage);

/**
* Annotate the span with a throwable
*
* @param throwable the errored throwable
*/
void addThrowable(Throwable throwable);

/** Finishes (closes) a span */
void finish();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package datadog.trace.api.llmobs.noop;

import datadog.trace.api.llmobs.LLMObsSpan;
import java.util.List;
import java.util.Map;

public class NoOpLLMObsSpan implements LLMObsSpan {
public static final LLMObsSpan INSTANCE = new NoOpLLMObsSpan();

@Override
public void annotateIO(
List<Map<String, Object>> inputData, List<Map<String, Object>> outputData) {}

@Override
public void annotateIO(String inputData, String outputData) {}

@Override
public void setMetadata(Map<String, Object> metadata) {}

@Override
public void setMetrics(Map<String, Number> metrics) {}

@Override
public void setMetric(CharSequence key, int value) {}

@Override
public void setMetric(CharSequence key, long value) {}

@Override
public void setMetric(CharSequence key, double value) {}

@Override
public void setTags(Map<String, Object> tags) {}

@Override
public void setTag(String key, String value) {}

@Override
public void setTag(String key, boolean value) {}

@Override
public void setTag(String key, int value) {}

@Override
public void setTag(String key, long value) {}

@Override
public void setTag(String key, double value) {}

@Override
public void setError(boolean error) {}

@Override
public void setErrorMessage(String errorMessage) {}

@Override
public void addThrowable(Throwable throwable) {}

@Override
public void finish() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package datadog.trace.api.llmobs.noop;

import datadog.trace.api.llmobs.LLMObs;
import datadog.trace.api.llmobs.LLMObsSpan;
import javax.annotation.Nullable;

public class NoOpLLMObsSpanFactory implements LLMObs.LLMObsSpanFactory {
public static final NoOpLLMObsSpanFactory INSTANCE = new NoOpLLMObsSpanFactory();

public LLMObsSpan startLLMSpan(
String spanName,
String modelName,
String modelProvider,
@Nullable String mlApp,
@Nullable String sessionID) {
return NoOpLLMObsSpan.INSTANCE;
}

public LLMObsSpan startAgentSpan(
String spanName, @Nullable String mlApp, @Nullable String sessionID) {
return NoOpLLMObsSpan.INSTANCE;
}

public LLMObsSpan startToolSpan(
String spanName, @Nullable String mlApp, @Nullable String sessionID) {
return NoOpLLMObsSpan.INSTANCE;
}

public LLMObsSpan startTaskSpan(
String spanName, @Nullable String mlApp, @Nullable String sessionID) {
return NoOpLLMObsSpan.INSTANCE;
}

public LLMObsSpan startWorkflowSpan(
String spanName, @Nullable String mlApp, @Nullable String sessionID) {
return NoOpLLMObsSpan.INSTANCE;
}
}
0