Skip to content

Commit

Permalink
write manual inputs and outputs on LLM spans (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinmukhamedm authored Nov 18, 2024
1 parent d538ad5 commit 13c7b5b
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions app-server/src/traces/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,20 +333,19 @@ impl Span {
false,
);
}
} else {
if let Some(serde_json::Value::String(s)) = attributes.get(INPUT_ATTRIBUTE_NAME) {
span.input = Some(
serde_json::from_str::<Value>(s)
.unwrap_or(serde_json::Value::String(s.clone())),
);
}

if let Some(serde_json::Value::String(s)) = attributes.get(OUTPUT_ATTRIBUTE_NAME) {
span.output = 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.
if let Some(serde_json::Value::String(s)) = attributes.get(INPUT_ATTRIBUTE_NAME) {
span.input = Some(
serde_json::from_str::<Value>(s).unwrap_or(serde_json::Value::String(s.clone())),
);
}
if let Some(serde_json::Value::String(s)) = attributes.get(OUTPUT_ATTRIBUTE_NAME) {
span.output = Some(
serde_json::from_str::<Value>(s).unwrap_or(serde_json::Value::String(s.clone())),
);
}

// Traceloop hard-codes these attributes to LangChain auto-instrumented spans.
Expand Down

0 comments on commit 13c7b5b

Please sign in to comment.