Skip to content

Commit 98060a9

Browse files
committed
add APIs for llm obs
1 parent beb66e3 commit 98060a9

File tree

4 files changed

+175
-0
lines changed

4 files changed

+175
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package datadog.trace.api.llmobs;
2+
3+
import datadog.trace.api.llmobs.noop.NoOpLLMObsSpanFactory;
4+
import javax.annotation.Nullable;
5+
6+
public class LLMObs {
7+
private static LLMObsSpanFactory SPAN_FACTORY = NoOpLLMObsSpanFactory.INSTANCE;
8+
9+
public static LLMObsSpan startLLMSpan(
10+
String spanName,
11+
String modelName,
12+
String modelProvider,
13+
@Nullable String mlApp,
14+
@Nullable String sessionID) {
15+
16+
return SPAN_FACTORY.startLLMSpan(spanName, modelName, modelProvider, sessionID, mlApp);
17+
}
18+
19+
public static LLMObsSpan startAgentSpan(
20+
String spanName, @Nullable String mlApp, @Nullable String sessionID) {
21+
22+
return SPAN_FACTORY.startAgentSpan(spanName, sessionID, mlApp);
23+
}
24+
25+
public static LLMObsSpan startToolSpan(
26+
String spanName, @Nullable String mlApp, @Nullable String sessionID) {
27+
28+
return SPAN_FACTORY.startToolSpan(spanName, sessionID, mlApp);
29+
}
30+
31+
public static LLMObsSpan startTaskSpan(
32+
String spanName, @Nullable String mlApp, @Nullable String sessionID) {
33+
34+
return SPAN_FACTORY.startTaskSpan(spanName, sessionID, mlApp);
35+
}
36+
37+
public static LLMObsSpan startWorkflowSpan(
38+
String spanName, @Nullable String mlApp, @Nullable String sessionID) {
39+
40+
return SPAN_FACTORY.startWorkflowSpan(spanName, sessionID, mlApp);
41+
}
42+
43+
public interface LLMObsSpanFactory {
44+
LLMObsSpan startLLMSpan(
45+
String spanName,
46+
String modelName,
47+
String modelProvider,
48+
@Nullable String mlApp,
49+
@Nullable String sessionID);
50+
51+
LLMObsSpan startAgentSpan(String spanName, @Nullable String mlApp, @Nullable String sessionID);
52+
53+
LLMObsSpan startToolSpan(String spanName, @Nullable String mlApp, @Nullable String sessionID);
54+
55+
LLMObsSpan startTaskSpan(String spanName, @Nullable String mlApp, @Nullable String sessionID);
56+
57+
LLMObsSpan startWorkflowSpan(
58+
String spanName, @Nullable String mlApp, @Nullable String sessionID);
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package datadog.trace.api.llmobs;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
import javax.annotation.Nullable;
6+
7+
/** This interface represent an individual LLM Obs span. */
8+
public interface LLMObsSpan {
9+
10+
/**
11+
* Annotate spans with inputs, outputs, metadata, metrics, and tags.
12+
*
13+
* @param inputData The input data of the span in the form of a list, for example a list of input
14+
* messages
15+
* @param outputData The output data of the span in the form of a list, for example a list of
16+
* output messages
17+
* @param metadata A map of JSON serializable key-value pairs that contains metadata information
18+
* relevant to the input or output operation described by the span
19+
* @param metrics A map of JSON serializable keys and numeric values that users can add as metrics
20+
* relevant to the operation described by the span (input_tokens, output_tokens, total_tokens,
21+
* etc.).
22+
* @param tags An map of JSON serializable key-value pairs that users can add as tags regarding
23+
* the span’s context (session, environment, system, versioning, etc.).
24+
*/
25+
void annotate(
26+
@Nullable List<Map<String, Object>> inputData,
27+
@Nullable List<Map<String, Object>> outputData,
28+
@Nullable Map<String, Object> metadata,
29+
@Nullable Map<String, Number> metrics,
30+
@Nullable Map<String, Object> tags);
31+
32+
/**
33+
* Annotate spans with inputs, outputs, metadata, metrics, and tags.
34+
*
35+
* @param inputData The input data of the span in the form of a string
36+
* @param outputData The output data of the span in the form of a string
37+
* @param metadata A map of JSON serializable key-value pairs that contains metadata information
38+
* relevant to the input or output operation described by the span
39+
* @param metrics A map of JSON serializable keys and numeric values that users can add as metrics
40+
* relevant to the operation described by the span (input_tokens, output_tokens, total_tokens,
41+
* etc.).
42+
* @param tags An map of JSON serializable key-value pairs that users can add as tags regarding
43+
* the span’s context (session, environment, system, versioning, etc.).
44+
*/
45+
void annotate(
46+
@Nullable String inputData,
47+
@Nullable String outputData,
48+
@Nullable Map<String, Object> metadata,
49+
@Nullable Map<String, Number> metrics,
50+
@Nullable Map<String, Object> tags);
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package datadog.trace.api.llmobs.noop;
2+
3+
import datadog.trace.api.llmobs.LLMObsSpan;
4+
import java.util.List;
5+
import java.util.Map;
6+
import javax.annotation.Nullable;
7+
8+
public class NoOpLLMObsSpan implements LLMObsSpan {
9+
public static final LLMObsSpan INSTANCE = new NoOpLLMObsSpan();
10+
11+
@Override
12+
public void annotate(
13+
@Nullable List<Map<String, Object>> inputData,
14+
@Nullable List<Map<String, Object>> outputData,
15+
@Nullable Map<String, Object> metadata,
16+
@Nullable Map<String, Number> metrics,
17+
@Nullable Map<String, Object> tags) {}
18+
19+
@Override
20+
public void annotate(
21+
@Nullable String inputData,
22+
@Nullable String outputData,
23+
@Nullable Map<String, Object> metadata,
24+
@Nullable Map<String, Number> metrics,
25+
@Nullable Map<String, Object> tags) {}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package datadog.trace.api.llmobs.noop;
2+
3+
import datadog.trace.api.llmobs.LLMObs;
4+
import datadog.trace.api.llmobs.LLMObsSpan;
5+
import javax.annotation.Nullable;
6+
7+
public class NoOpLLMObsSpanFactory implements LLMObs.LLMObsSpanFactory {
8+
public static final NoOpLLMObsSpanFactory INSTANCE = new NoOpLLMObsSpanFactory();
9+
10+
public LLMObsSpan startLLMSpan(
11+
String spanName,
12+
String modelName,
13+
String modelProvider,
14+
@Nullable String mlApp,
15+
@Nullable String sessionID) {
16+
return NoOpLLMObsSpan.INSTANCE;
17+
}
18+
19+
public LLMObsSpan startAgentSpan(
20+
String spanName, @Nullable String mlApp, @Nullable String sessionID) {
21+
return NoOpLLMObsSpan.INSTANCE;
22+
}
23+
24+
public LLMObsSpan startToolSpan(
25+
String spanName, @Nullable String mlApp, @Nullable String sessionID) {
26+
return NoOpLLMObsSpan.INSTANCE;
27+
}
28+
29+
public LLMObsSpan startTaskSpan(
30+
String spanName, @Nullable String mlApp, @Nullable String sessionID) {
31+
return NoOpLLMObsSpan.INSTANCE;
32+
}
33+
34+
public LLMObsSpan startWorkflowSpan(
35+
String spanName, @Nullable String mlApp, @Nullable String sessionID) {
36+
return NoOpLLMObsSpan.INSTANCE;
37+
}
38+
}

0 commit comments

Comments
 (0)