mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-04 01:48:57 +00:00
* refactor(proxy): extract shared spend log read policy * test(proxy): use named bindings for spend scope regression * test(proxy): reuse existing spend log query harness * test(proxy): cover spend log permission lookup adoption * chore(proxy): relocate existing spend query baseline * refactor(proxy): make scope query returns explicit * refactor(proxy): inject deferred log permission lookup * test(proxy): cover teamless management compatibility lookup * refactor(proxy): compose user and team log grants * refactor(proxy): share generic authorization composition * refactor(proxy): compose trace read permissions * refactor(proxy): centralize spend and trace authorization * refactor(proxy): strengthen spend and trace scope types * refactor(proxy): flatten log read scope into owned logs Replace the AnyOf grant tree with a flat OwnedLogs(user_id, team_ids) scope, and OwnedTraces(logs, api_key_hash) for traces, since every consumer flattened the tree back into that shape. A caller with no user id now gets an empty scope instead of matching ownerless rows through Prisma's IS NULL. The dead request_id guard in ui_view_spend_logs is removed, and the management facets inject the log team lookup and reuse read_scope_sql instead of the list shim. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(proxy): run spend scope tests through one SQLite emulator Replace the string-matching payload emulator and the hand-rolled Prisma where interpreter with one SQLite helper that runs the real scope SQL. Session scope tests now go through the endpoint, including the no-user caller that must not match ownerless rows. Drop duplicated lookup-failure and trace mapping cases. load_permitted_log_team_ids returns no teams without a database instead of relying on the resolver's broad except. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(proxy): unify log and trace ownership permissions * test(tracing): align fixtures with ownership read scopes * refactor(tracing): align query scopes with row ownership * refactor(spend): make ownership SQL predicates explicit * test(spend): validate ownership SQL against PostgreSQL * docs(traces): drop key-row visibility from query help guide Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * test(spend): reach the empty-memberships branch in team lookup test Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * chore(ui): regenerate dashboard API types Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
24 lines
1.2 KiB
SQL
24 lines
1.2 KiB
SQL
SELECT o.SpanId AS span_id, o.Input AS input,
|
|
if(o.Output = '' AND o.ObservationType = 'agent', answer.output, o.Output) AS output,
|
|
o.SpanAttributes AS attributes
|
|
FROM otel_traces AS o
|
|
LEFT JOIN (
|
|
SELECT TeamId, ApiKeyHash, ParentSpanId AS parent_span_id, argMax(Output, Timestamp) AS output
|
|
FROM otel_traces
|
|
WHERE TraceId = {trace_id:String} AND ParentSpanId = {span_id:String}
|
|
AND ObservationType = 'llm' AND Output != ''
|
|
AND ({all_teams:UInt8} = 1
|
|
OR ({user_id:String} != '' AND UserId = {user_id:String})
|
|
OR has({team_ids:Array(String)}, TeamId))
|
|
AND ({trace_ref:String} = '' OR
|
|
hex(SHA256(concat(TeamId, char(0), ApiKeyHash, char(0), TraceId))) = {trace_ref:String})
|
|
GROUP BY TeamId, ApiKeyHash, ParentSpanId
|
|
) AS answer ON answer.parent_span_id = o.SpanId
|
|
AND answer.TeamId = o.TeamId AND answer.ApiKeyHash = o.ApiKeyHash
|
|
WHERE o.TraceId = {trace_id:String} AND o.SpanId = {span_id:String}
|
|
AND ({all_teams:UInt8} = 1
|
|
OR ({user_id:String} != '' AND o.UserId = {user_id:String})
|
|
OR has({team_ids:Array(String)}, o.TeamId))
|
|
AND ({trace_ref:String} = '' OR
|
|
hex(SHA256(concat(o.TeamId, char(0), o.ApiKeyHash, char(0), o.TraceId))) = {trace_ref:String})
|
|
LIMIT 1
|