Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion litellm-rust/crates/python-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ mod _native {
#[pymodule_export]
use crate::routes::token_counter::TokenCounter;
#[pymodule_export]
use crate::routes::traces::{NativeTraceStorage, trace_decode_otlp};
use crate::routes::traces::{
NativeTraceStorage, trace_decode_otlp, trace_normalized_field_definitions,
};
#[cfg(feature = "huggingface")]
#[pymodule_export]
use crate::tokenizer::HuggingFaceEncoding;
Expand Down Expand Up @@ -111,6 +113,7 @@ mod tests {
"NativeDiagnosticProcessor",
"NativeTraceStorage",
"trace_decode_otlp",
"trace_normalized_field_definitions",
"TokenCounter",
"Tokenizer",
"gil_stats",
Expand Down
5 changes: 5 additions & 0 deletions litellm-rust/crates/python-bridge/src/routes/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,8 @@ pub fn trace_decode_otlp<'py>(
})?;
litellm_host_python::Pythonized(spans).into_pyobject(py)
}

#[pyfunction]
pub fn trace_normalized_field_definitions<'py>(py: Python<'py>) -> PyResult<Bound<'py, PyAny>> {
litellm_host_python::Pythonized(litellm_traces::NORMALIZED_FIELD_DEFINITIONS).into_pyobject(py)
}
4 changes: 4 additions & 0 deletions litellm-rust/crates/traces/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
mod error;
mod insert;
mod normalize;
mod otlp;
mod schema;
mod sql;

pub use error::{DecodeError, Error};
pub use insert::{InsertTable, encode_rows, insert_rows};
pub use normalize::{
NORMALIZED_FIELD_DEFINITIONS, NormalizedFieldDefinition, NormalizedSpan, ObservationType,
};
pub use otlp::{DecodedSpan, decode_otlp};
pub use schema::{ensure_schema, schema_statements};
pub use sql::{LensQuery, Parameter, ReadQuery, execute_named_read, execute_read};
Expand Down
46 changes: 46 additions & 0 deletions litellm-rust/crates/traces/src/normalize/genai.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use std::collections::BTreeMap;

use super::{NormalizedSpan, ObservationType, SpanNormalizer, attr, first};

pub(super) struct GenAiNormalizer;

impl SpanNormalizer for GenAiNormalizer {
fn matches(&self, _scope_name: &str, _attributes: &BTreeMap<String, String>) -> bool {
true
}

fn normalize(
&self,
_name: &str,
parent_span_id: &str,
attributes: &BTreeMap<String, String>,
) -> NormalizedSpan {
let observation_type = match attr(attributes, "gen_ai.operation.name") {
"invoke_agent" => ObservationType::Agent,
_ if parent_span_id.is_empty() => ObservationType::Agent,
"chat" | "text_completion" | "generate_content" => ObservationType::Llm,
"execute_tool" => ObservationType::Tool,
_ => ObservationType::Chain,
};
NormalizedSpan {
observation_type,
agent_name: attr(attributes, "gen_ai.agent.name").to_owned(),
litellm_request_id: attr(attributes, "gen_ai.response.id").to_owned(),
model: first(attributes, "gen_ai.request.model", "gen_ai.response.model").to_owned(),
input_tokens: 0,
output_tokens: 0,
input: first(
attributes,
"gen_ai.input.messages",
"gen_ai.tool.call.arguments",
)
.to_owned(),
output: first(
attributes,
"gen_ai.output.messages",
"gen_ai.tool.call.result",
)
.to_owned(),
}
}
}
Loading
Loading