|
| 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 | + /** |
| 10 | + * This a hook for injecting SpanFactory implementation. It should only be used internally by |
| 11 | + * the tracer logic |
| 12 | + * |
| 13 | + * @param spanFactory span factory instance |
| 14 | + */ |
| 15 | + public static void registerSpanFactory(LLMObsSpanFactory spanFactory) { |
| 16 | + SPAN_FACTORY = spanFactory; |
| 17 | + } |
| 18 | + |
| 19 | + public static LLMObsSpan startLLMSpan( |
| 20 | + String spanName,String modelName, String modelProvider, @Nullable String mlApp, @Nullable String sessionID) { |
| 21 | + |
| 22 | + return SPAN_FACTORY.startLLMSpan(spanName, modelName, modelProvider, sessionID, mlApp); |
| 23 | + } |
| 24 | + |
| 25 | + public static LLMObsSpan startAgentSpan( |
| 26 | + String spanName, @Nullable String mlApp, @Nullable String sessionID) { |
| 27 | + |
| 28 | + return SPAN_FACTORY.startAgentSpan(spanName, sessionID, mlApp); |
| 29 | + } |
| 30 | + |
| 31 | + public static LLMObsSpan startToolSpan( |
| 32 | + String spanName, @Nullable String mlApp, @Nullable String sessionID) { |
| 33 | + |
| 34 | + return SPAN_FACTORY.startToolSpan(spanName, sessionID, mlApp); |
| 35 | + } |
| 36 | + |
| 37 | + public static LLMObsSpan startTaskSpan( |
| 38 | + String spanName, @Nullable String mlApp, @Nullable String sessionID) { |
| 39 | + |
| 40 | + return SPAN_FACTORY.startTaskSpan(spanName, sessionID, mlApp); |
| 41 | + } |
| 42 | + |
| 43 | + public static LLMObsSpan startWorkflowSpan( |
| 44 | + String spanName, @Nullable String mlApp, @Nullable String sessionID) { |
| 45 | + |
| 46 | + return SPAN_FACTORY.startWorkflowSpan(spanName, sessionID, mlApp); |
| 47 | + } |
| 48 | + |
| 49 | + public interface LLMObsSpanFactory { |
| 50 | + LLMObsSpan startLLMSpan(String spanName, String modelName, String modelProvider, @Nullable String mlApp, @Nullable String sessionID); |
| 51 | + LLMObsSpan startAgentSpan(String spanName, @Nullable String mlApp, @Nullable String sessionID); |
| 52 | + LLMObsSpan startToolSpan(String spanName, @Nullable String mlApp, @Nullable String sessionID); |
| 53 | + LLMObsSpan startTaskSpan(String spanName, @Nullable String mlApp, @Nullable String sessionID); |
| 54 | + LLMObsSpan startWorkflowSpan(String spanName, @Nullable String mlApp, @Nullable String sessionID); |
| 55 | + } |
| 56 | +} |
0 commit comments