mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-02 02:11:58 +00:00
* feat(tracing): bring current ingestion prerequisite onto main
Port the prerequisite implementation from BerriAI/litellm#43915 at 5aacd57455 so Lens does not depend on the retired tracing stack.
* feat(lens): add trace analysis and standalone worker
* fix(lens): clarify review limits and finalize main integration
* fix(lens): simplify worker setup and show the next check
* fix(lens): simplify analyzer setup and resolve integration failures
* fix(lens): preserve durations and evidence from later trace reads
* fix(lens): trust server context for internal analysis exclusion
* fix(lens): pin reviewed analyzer image and verify request inclusion
* test(lens): select time units before entering custom duration
* test(lens): allow the standalone analyzer lifetime HTTP client
* test(lens): run analyzer tests in active proxy coverage shard
63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
import base64
|
|
import json
|
|
from typing import Final
|
|
|
|
import pytest
|
|
|
|
from litellm.proxy.engine.models import Scope, MetadataFilter
|
|
from litellm.proxy.engine.sources import SourceReader
|
|
from tests.unit.proxy.engine.test_state import engine
|
|
|
|
from litellm.proxy.engine.sources import execution_id, parse_execution
|
|
|
|
|
|
def test_same_trace_id_from_different_keys_is_a_distinct_execution() -> None:
|
|
assert execution_id("traces", "team", "trace", "key-one-ref") != execution_id(
|
|
"traces", "team", "trace", "key-two-ref"
|
|
)
|
|
assert parse_execution(execution_id("traces", "team", "trace", "key-one-ref")) == (
|
|
"traces",
|
|
"team",
|
|
"trace",
|
|
"key-one-ref",
|
|
)
|
|
|
|
|
|
def test_previous_saved_findings_keep_their_execution_links() -> None:
|
|
assert parse_execution(base64.urlsafe_b64encode(json.dumps(("traces", "team", "trace")).encode()).decode()) == (
|
|
"traces",
|
|
"team",
|
|
"trace",
|
|
"",
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_sample_never_returns_authentication_attributes() -> None:
|
|
class StorageResponse:
|
|
async def lens_sample(self, parameters):
|
|
assert parameters["team"] == "alpha"
|
|
return [
|
|
{
|
|
"source": "traces",
|
|
"trace_id": "trace",
|
|
"team_id": "alpha",
|
|
"name": "run",
|
|
"start_time": "",
|
|
"span_count": 1,
|
|
"root_seen": 1,
|
|
"eligible": 1,
|
|
"attributes": [
|
|
["litellm.api_key_hash", "opaque-oauth-bearer"],
|
|
["environment", "production"],
|
|
["", "invalid"],
|
|
["oversized", "x" * 501],
|
|
],
|
|
}
|
|
]
|
|
|
|
reader: Final = SourceReader(StorageResponse())
|
|
sample: Final = await reader.sample(Scope(team_id="alpha"), engine().settings, 1, 2)
|
|
assert sample.executions[0].metadata == (MetadataFilter(key="environment", value="production"),)
|
|
assert "opaque-oauth-bearer" not in sample.model_dump_json()
|
|
assert sample.eligible == 1
|