Skip to content

Added retrieval and embedding span methods #9269

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.lang.instrument.Instrumentation;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -189,6 +189,30 @@ public LLMObsSpan startWorkflowSpan(
Tags.LLMOBS_WORKFLOW_SPAN_KIND, spanName, getMLApp(mlApp), sessionId, serviceName);
}

@Override
public LLMObsSpan startEmbeddingSpan(
String spanName,
@Nullable String mlApp,
@Nullable String modelProvider,
@Nullable String modelName,
@Nullable String sessionId) {
if (modelProvider == null) {
modelProvider = "custom";
}
DDLLMObsSpan embeddingSpan =
new DDLLMObsSpan(
Tags.LLMOBS_EMBEDDING_SPAN_KIND, spanName, getMLApp(mlApp), sessionId, serviceName);
embeddingSpan.setTag(LLMObsTags.MODEL_PROVIDER, modelProvider);
embeddingSpan.setTag(LLMObsTags.MODEL_NAME, modelName);
return embeddingSpan;
}

public LLMObsSpan startRetrievalSpan(
String spanName, @Nullable String mlApp, @Nullable String sessionId) {
return new DDLLMObsSpan(
Tags.LLMOBS_RETRIEVAL_SPAN_KIND, spanName, getMLApp(mlApp), sessionId, serviceName);
}

private String getMLApp(String mlApp) {
if (mlApp == null || mlApp.isEmpty()) {
return defaultMLApp;
Expand Down
24 changes: 24 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
Expand Up @@ -46,6 +46,20 @@ public static LLMObsSpan startWorkflowSpan(
return SPAN_FACTORY.startWorkflowSpan(spanName, mlApp, sessionId);
}

public LLMObsSpan startEmbeddingSpan(
String spanName,
@Nullable String mlApp,
@Nullable String modelProvider,
@Nullable String modelName,
@Nullable String sessionId) {
return SPAN_FACTORY.startEmbeddingSpan(spanName, mlApp, modelProvider, modelName, sessionId);
}

public LLMObsSpan startRetrievalSpan(
String spanName, @Nullable String mlApp, @Nullable String sessionId) {
return SPAN_FACTORY.startRetrievalSpan(spanName, mlApp, sessionId);
}

public static void SubmitEvaluation(
LLMObsSpan llmObsSpan, String label, String categoricalValue, Map<String, Object> tags) {
EVAL_PROCESSOR.SubmitEvaluation(llmObsSpan, label, categoricalValue, tags);
Expand Down Expand Up @@ -90,6 +104,16 @@ LLMObsSpan startLLMSpan(

LLMObsSpan startWorkflowSpan(
String spanName, @Nullable String mlApp, @Nullable String sessionId);

LLMObsSpan startEmbeddingSpan(
String spanName,
@Nullable String mlApp,
@Nullable String modelProvider,
@Nullable String modelName,
@Nullable String sessionId);

LLMObsSpan startRetrievalSpan(
String spanName, @Nullable String mlApp, @Nullable String sessionId);
}

public interface LLMObsEvalProcessor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,18 @@ public LLMObsSpan startWorkflowSpan(
String spanName, @Nullable String mlApp, @Nullable String sessionId) {
return NoOpLLMObsSpan.INSTANCE;
}

public LLMObsSpan startEmbeddingSpan(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should be modelName and modelProvider param for this one, where modelProvider defaults to custom if a value is not provided

String spanName,
@Nullable String mlApp,
@Nullable String modelProvider,
@Nullable String modelName,
@Nullable String sessionId) {
return NoOpLLMObsSpan.INSTANCE;
}

public LLMObsSpan startRetrievalSpan(
String spanName, @Nullable String mlApp, @Nullable String sessionId) {
return NoOpLLMObsSpan.INSTANCE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,6 @@ public class Tags {
public static final String LLMOBS_TASK_SPAN_KIND = "task";
public static final String LLMOBS_AGENT_SPAN_KIND = "agent";
public static final String LLMOBS_TOOL_SPAN_KIND = "tool";
public static final String LLMOBS_EMBEDDING_SPAN_KIND = "embedding";
public static final String LLMOBS_RETRIEVAL_SPAN_KIND = "retrieval";
}