mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-11 03:38:38 +00:00
* refactor: separate OTLP HTTP decoding from trace codec * feat: complete trace ingestion and read paths * fix: encode OTLP protobuf errors in Rust * fix: raise OTLP body limit to 16 MiB * test: cover OTLP auth body parsing boundary * refactor: parse OTLP media type into enum * fix: enforce OTLP body size at HTTP boundary * perf: preserve shared OTLP metadata across ingestion * bench: compare owned and shared trace resource fanout * refactor: extract shared storage and Python conversion caches * refactor: keep shared storage owned by traces * test: keep trace loopback coverage in Rust * test(proxy): adapt trace coverage to injected access context * fix(tracing): satisfy stacked branch lint checks * refactor(tracing): use immutable ingestion payloads * fix(tracing): declare native error encoder export * test(proxy): resolve trace access through dependency * fix(tracing): align merged normalizer types and bridge tests * fix(tracing): address ingestion and diagnostic review findings * fix(proxy): preserve body parsing for partial request scopes * test(proxy): use valid HTTP scopes in request fixtures * test(proxy): complete auth request flow scopes
57 lines
1.5 KiB
Rust
57 lines
1.5 KiB
Rust
use std::collections::{HashMap, hash_map::Entry};
|
|
|
|
use pyo3::prelude::*;
|
|
|
|
pub struct ToPythonCache<'a, 'py, T> {
|
|
entries: HashMap<usize, (&'a T, Bound<'py, PyAny>)>,
|
|
}
|
|
|
|
impl<T> Default for ToPythonCache<'_, '_, T> {
|
|
fn default() -> Self {
|
|
Self {
|
|
entries: HashMap::new(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<'a, 'py, T> ToPythonCache<'a, 'py, T> {
|
|
pub fn get_or_try_insert_with(
|
|
&mut self,
|
|
value: &'a T,
|
|
convert: impl FnOnce(&'a T) -> PyResult<Bound<'py, PyAny>>,
|
|
) -> PyResult<&Bound<'py, PyAny>> {
|
|
let identity = std::ptr::from_ref(value) as usize;
|
|
let entry = match self.entries.entry(identity) {
|
|
Entry::Occupied(entry) => entry.into_mut(),
|
|
Entry::Vacant(entry) => entry.insert((value, convert(value)?)),
|
|
};
|
|
Ok(&entry.1)
|
|
}
|
|
}
|
|
|
|
pub struct FromPythonCache<'py, T> {
|
|
entries: HashMap<usize, (Bound<'py, PyAny>, T)>,
|
|
}
|
|
|
|
impl<T> Default for FromPythonCache<'_, T> {
|
|
fn default() -> Self {
|
|
Self {
|
|
entries: HashMap::new(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<'py, T> FromPythonCache<'py, T> {
|
|
pub fn get_or_try_insert_with(
|
|
&mut self,
|
|
value: &Bound<'py, PyAny>,
|
|
convert: impl FnOnce(&Bound<'py, PyAny>) -> PyResult<T>,
|
|
) -> PyResult<&T> {
|
|
let identity = value.as_ptr() as usize;
|
|
let entry = match self.entries.entry(identity) {
|
|
Entry::Occupied(entry) => entry.into_mut(),
|
|
Entry::Vacant(entry) => entry.insert((value.clone(), convert(value)?)),
|
|
};
|
|
Ok(&entry.1)
|
|
}
|
|
}
|