Repository navigation
feat: improve trace ingestion and trace details #43975
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
Merged
yujonglee-berri
merged 25 commits into
litellm_tracing_dependencies
from
litellm_gateway_traces_boundary
Oct 1, 2026
Merged
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
2cdb466
refactor: separate OTLP HTTP decoding from trace codec
yujonglee-berri 3361089
feat: complete trace ingestion and read paths
yujonglee-berri d658271
fix: encode OTLP protobuf errors in Rust
yujonglee-berri 4a4307b
fix: raise OTLP body limit to 16 MiB
yujonglee-berri 6a9b197
test: cover OTLP auth body parsing boundary
yujonglee-berri 1aad40b
refactor: parse OTLP media type into enum
yujonglee-berri cb67ba4
fix: enforce OTLP body size at HTTP boundary
yujonglee-berri 89cb993
perf: preserve shared OTLP metadata across ingestion
yujonglee-berri 9ecb10c
bench: compare owned and shared trace resource fanout
yujonglee-berri e59aa75
refactor: extract shared storage and Python conversion caches
yujonglee-berri 5b376da
refactor: keep shared storage owned by traces
yujonglee-berri 02442b3
test: keep trace loopback coverage in Rust
yujonglee-berri 3b7c9e7
test(proxy): adapt trace coverage to injected access context
yujonglee-berri d63e323
fix(tracing): satisfy stacked branch lint checks
yujonglee-berri 211abd7
refactor(tracing): use immutable ingestion payloads
yujonglee-berri f3041e6
fix(tracing): declare native error encoder export
yujonglee-berri 7dada1e
test(proxy): resolve trace access through dependency
yujonglee-berri b5110d3
merge: sync trace boundary with tracing dependencies
yujonglee-berri 22d9125
fix(tracing): align merged normalizer types and bridge tests
yujonglee-berri 09a0352
merge: include migration test fix from tracing base
yujonglee-berri eb85680
fix(tracing): address ingestion and diagnostic review findings
yujonglee-berri f6e145e
Merge remote-tracking branch 'origin/litellm_tracing_dependencies' in…
yujonglee-berri 484ce13
fix(proxy): preserve body parsing for partial request scopes
yujonglee-berri d9ed39a
test(proxy): use valid HTTP scopes in request fixtures
yujonglee-berri 8019534
test(proxy): complete auth request flow scopes
yujonglee-berri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| [package] | ||
| name = "litellm-gateway-traces" | ||
| version = "0.1.0" | ||
| edition.workspace = true | ||
| license.workspace = true | ||
| repository.workspace = true | ||
|
|
||
| [dependencies] | ||
| axum.workspace = true | ||
| flate2.workspace = true | ||
| litellm-traces.workspace = true | ||
|
|
||
| [dev-dependencies] | ||
| prost.workspace = true | ||
| opentelemetry-proto = { workspace = true, features = ["gen-tonic-messages", "trace", "with-serde"] } | ||
| rstest.workspace = true | ||
| tokio.workspace = true | ||
| tower = { version = "0.5", features = ["util"] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| use std::{future::Future, io::Read, sync::Arc}; | ||
|
|
||
| use axum::{ | ||
| Router, | ||
| body::to_bytes, | ||
| extract::{Request, State}, | ||
| http::{StatusCode, header}, | ||
| response::{IntoResponse, Response}, | ||
| routing::post, | ||
| }; | ||
| use flate2::read::MultiGzDecoder; | ||
| use litellm_traces::{DecodeError, DecodedSpan, decode_otlp}; | ||
|
|
||
| pub const MAX_BODY_BYTES: usize = 16 * 1024 * 1024; | ||
|
|
||
| fn otlp_max_body_bytes() -> usize { | ||
| std::env::var("OTLP_MAX_BODY_BYTES") | ||
| .ok() | ||
| .and_then(|value| value.trim().parse().ok()) | ||
| .unwrap_or(MAX_BODY_BYTES) | ||
| } | ||
|
|
||
| pub trait SpanSink: Send + Sync + 'static { | ||
| fn write(&self, spans: Vec<DecodedSpan>) -> impl Future<Output = Result<(), ()>> + Send; | ||
| } | ||
|
|
||
| pub fn router<S: SpanSink>(sink: S) -> Router { | ||
| Router::new() | ||
| .route("/v1/traces", post(ingest::<S>)) | ||
| .with_state(Arc::new(sink)) | ||
| } | ||
|
|
||
| async fn ingest<S: SpanSink>(State(sink): State<Arc<S>>, request: Request) -> Response { | ||
| let max_body_bytes = otlp_max_body_bytes(); | ||
| let content_type = request | ||
| .headers() | ||
| .get(header::CONTENT_TYPE) | ||
| .and_then(|value| value.to_str().ok()) | ||
| .map(str::to_owned); | ||
| let encoding = request | ||
| .headers() | ||
| .get(header::CONTENT_ENCODING) | ||
| .map(|value| value.to_str().map(str::to_owned)); | ||
| let response_type = if content_type.as_deref().is_some_and(|value| { | ||
| value | ||
| .split(';') | ||
| .next() | ||
| .is_some_and(|value| value.trim().eq_ignore_ascii_case("application/json")) | ||
| }) { | ||
| "application/json" | ||
| } else { | ||
| "application/x-protobuf" | ||
| }; | ||
| let result = async { | ||
| let encoding = encoding.transpose().map_err(|_| StatusCode::BAD_REQUEST)?; | ||
| let body = to_bytes(request.into_body(), max_body_bytes.saturating_add(1)) | ||
| .await | ||
| .map_err(|_| StatusCode::PAYLOAD_TOO_LARGE)?; | ||
| let payload = decode_content_encoding(&body, encoding.as_deref(), max_body_bytes)?; | ||
| let spans = | ||
| decode_otlp(&payload, content_type.as_deref()).map_err(|error| match error { | ||
| DecodeError::TooLarge => StatusCode::PAYLOAD_TOO_LARGE, | ||
| DecodeError::InvalidPayload => StatusCode::BAD_REQUEST, | ||
| })?; | ||
| sink.write(spans) | ||
| .await | ||
| .map_err(|_| StatusCode::SERVICE_UNAVAILABLE) | ||
| } | ||
| .await; | ||
| match result { | ||
| Ok(()) if response_type == "application/json" => { | ||
| ([(header::CONTENT_TYPE, response_type)], "{}").into_response() | ||
| } | ||
| Ok(()) => ([(header::CONTENT_TYPE, response_type)], "").into_response(), | ||
| Err(status) => status.into_response(), | ||
| } | ||
| } | ||
|
|
||
| fn decode_content_encoding( | ||
| body: &[u8], | ||
| encoding: Option<&str>, | ||
| max_body_bytes: usize, | ||
| ) -> Result<Vec<u8>, StatusCode> { | ||
| if body.len() > max_body_bytes { | ||
| return Err(StatusCode::PAYLOAD_TOO_LARGE); | ||
| } | ||
| match encoding { | ||
| None => Ok(body.to_vec()), | ||
| Some(value) if value.eq_ignore_ascii_case("identity") => Ok(body.to_vec()), | ||
| Some(value) if value.eq_ignore_ascii_case("gzip") => { | ||
| let mut payload = Vec::new(); | ||
| MultiGzDecoder::new(body) | ||
| .take((max_body_bytes as u64).saturating_add(1)) | ||
| .read_to_end(&mut payload) | ||
| .map_err(|_| StatusCode::BAD_REQUEST)?; | ||
| if payload.len() > max_body_bytes { | ||
| return Err(StatusCode::PAYLOAD_TOO_LARGE); | ||
| } | ||
| Ok(payload) | ||
| } | ||
| _ => Err(StatusCode::BAD_REQUEST), | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use std::io::Write; | ||
|
|
||
| use flate2::{Compression, write::GzEncoder}; | ||
| use rstest::rstest; | ||
|
|
||
| use super::*; | ||
|
|
||
| #[rstest] | ||
| fn decompressed_size_limit_rejects_expansion() { | ||
| let mut encoder = GzEncoder::new(Vec::new(), Compression::default()); | ||
| encoder.write_all(&vec![b' '; MAX_BODY_BYTES + 1]).unwrap(); | ||
| let compressed = encoder.finish().unwrap(); | ||
| assert!(compressed.len() < MAX_BODY_BYTES); | ||
| assert!(matches!( | ||
| decode_content_encoding(&compressed, Some("gzip"), MAX_BODY_BYTES), | ||
| Err(StatusCode::PAYLOAD_TOO_LARGE) | ||
| )); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.