Skip to content
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

Fix association properties bug and add prompt from ai sdk #291

Merged
merged 2 commits into from
Dec 25, 2024
Merged
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
20 changes: 15 additions & 5 deletions app-server/src/traces/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl SpanAttributes {
pub fn session_id(&self) -> Option<String> {
match self
.attributes
.get(format!("{ASSOCIATION_PROPERTIES_PREFIX}session_id").as_str())
.get(format!("{ASSOCIATION_PROPERTIES_PREFIX}.session_id").as_str())
{
Some(Value::String(s)) => Some(s.clone()),
_ => None,
Expand All @@ -69,7 +69,7 @@ impl SpanAttributes {
pub fn user_id(&self) -> Option<String> {
match self
.attributes
.get(format!("{ASSOCIATION_PROPERTIES_PREFIX}user_id").as_str())
.get(format!("{ASSOCIATION_PROPERTIES_PREFIX}.user_id").as_str())
{
Some(Value::String(s)) => Some(s.clone()),
_ => None,
Expand All @@ -78,7 +78,7 @@ impl SpanAttributes {

pub fn trace_type(&self) -> Option<TraceType> {
self.attributes
.get(format!("{ASSOCIATION_PROPERTIES_PREFIX}trace_type").as_str())
.get(format!("{ASSOCIATION_PROPERTIES_PREFIX}.trace_type").as_str())
.and_then(|s| serde_json::from_value(s.clone()).ok())
}

Expand Down Expand Up @@ -131,7 +131,7 @@ impl SpanAttributes {
if provider == "Langchain" {
let ls_provider = self
.attributes
.get(format!("{ASSOCIATION_PROPERTIES_PREFIX}ls_provider").as_str())
.get(format!("{ASSOCIATION_PROPERTIES_PREFIX}.ls_provider").as_str())
.and_then(|s| serde_json::from_value(s.clone()).ok());
if let Some(ls_provider) = ls_provider {
ls_provider
Expand Down Expand Up @@ -375,6 +375,16 @@ impl Span {
);
}
}

// Vercel AI SDK wraps "raw" LLM spans in an additional `ai.generateText` span.
// Which is not really an LLM span, but it has the prompt in its attributes.
// Set the input to the prompt.
if let Some(serde_json::Value::String(s)) = attributes.get("ai.prompt") {
span.input = Some(
serde_json::from_str::<Value>(s).unwrap_or(serde_json::Value::String(s.clone())),
);
}

// If an LLM span is sent manually, we prefer `lmnr.span.input` and `lmnr.span.output`
// attributes over gen_ai/vercel/LiteLLM attributes.
// Therefore this block is outside and after the LLM span type check.
Expand Down Expand Up @@ -453,7 +463,7 @@ impl Span {
};
let mut attributes = HashMap::new();
attributes.insert(
format!("{ASSOCIATION_PROPERTIES_PREFIX}trace_type",),
format!("{ASSOCIATION_PROPERTIES_PREFIX}.trace_type",),
json!(trace_type),
);
attributes.insert(SPAN_PATH.to_string(), json!(path));
Expand Down