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

write manual inputs and outputs on LLM spans #220

Merged
merged 1 commit into from
Nov 18, 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
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