Repository navigation
feat(tracing): add scoped SQL queries and schema-aware help - #44085
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
@greptile-apps wdyt |
|
|
@greptileai Please review the latest commit again, checking discovery failure recovery, current metadata sampling, SQL error responses, and resolved review threads |
|
@greptileai Please review the latest tip for managed reader provisioning, authenticated team scope, privilege bypasses, and scoped metadata discovery |
6d1cf91 to
cfa6529
Compare
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@greptileai Please review the latest tip 8c2013f, which derives reader names from scope alone, resets reader passwords with ALTER USER so master-key rotation revokes old credentials, and removes local mutation from query help |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@greptileai Please review the latest tip 89394d5, which runs query help discovery sequentially again |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@greptileai Please review the latest tip e287f34, which updates the Python bridge test fixtures for the extra ALTER USER provisioning request |
TLDR
Problem this solves:
How it solves it:
Intentional product change: team users can run SQL and discover fields within their authenticated scope. Proxy admins and view-only admins can read all LiteLLM trace data. Project-bound keys remain restricted to their own key's rows until project-wide scope is implemented
The broader configuration work remains in #43941
User Flow
Before: a team developer cannot explore their traces through SQL
http://localhost:4000/v1/traceshttp://localhost:4000/v1/traces/query/helpreturns 404http://localhost:4000/v1/traces/querywith a SQL body returns 405After: the same developer can explore their team's traces
http://localhost:4000/v1/traceshttp://localhost:4000/v1/traces/query/helpreturns schema, examples, and scoped field discoveryhttp://localhost:4000/v1/traces/queryreturns rows only within the key's authenticated scopeSetup and enforcement
Set
CLICKHOUSE_URLand, optionally,CLICKHOUSE_DATABASE. Trace startup no longer requiresCLICKHOUSE_READER_URL. SQL queries and help use automatically provisioned readers on the configured writer connection's server. The configured account needs its existing schema/ingestion privileges,CREATE USER,ALTER USER,CREATE ROW POLICYon the three trace tables, and permission to grantSELECTon those tablesEach database and authorization scope gets a stable reader name, and the proxy's master key derives its password. Provisioning resets that password with
ALTER USER, so rotating the master key revokes credentials derived from the previous one. Customers do not supply per-team credentials. ClickHouse stores password hashes. Provisioning creates locked settings and both permissive and restrictive row policies before granting table access. Failures reject the request and log setup guidance; execution never falls back to the writer identityTeam policies cover
otel_traces,agent_traces_by_key, andspend_logs. Project-bound keys and teamless keys additionally require their authenticated key hash. Scope comes from proxy authentication, not the request body or SQL. Help uses the same reader, so its metadata discovery cannot sample another team's rowsReaders have only explicit SELECT grants and enforce readonly mode, 10 seconds, 1,000 rows, 4 MiB results, 256 MiB memory, two threads, and eight concurrent queries per user. Each storage instance also admits at most eight SQL/help requests. Reader provisioning is coalesced and cached with a 1,024-entry bound
Validation
make checkpass without changing budgetsALTER USERstep makes the rotation regression failLive tests cover raw and qualified table names, CTEs, unions, joins, merge-table reads, summary rows, spend rows, help discovery, quoted team IDs, repeated provisioning, master-key rotation, resource settings, denied privileges, and provisioning failures. Discovery explicitly describes its bounded seven-day sample as unordered rather than promising the newest rows
Pre-Submission checklist
CI, Codecov, and bot reviews must be evaluated for
e287f3495f6902faab11d774514b21b2474346ae. Earlier results do not approve this tip. No maintainer review is being requested while those checks are pending or unavailableLatest-tip review evidence: Greptile re-review requested after the review fixes in e287f34. Required CI and Codecov results remain outstanding
Screenshots / Proof of Fix
Two local proxy processes used an isolated Postgres database and ClickHouse database named
trace_scope_proof. Team keys were created through/team/newand/key/generate. Each exported one span through/v1/traces, including a forged resource team label that the proxy replaced from authentication. The after process had onlyCLICKHOUSE_URL, withCLICKHOUSE_READER_URLunsetThe local curl files contain authorization and JSON content-type headers. Response excerpts below preserve
dataordetail; ClickHouse schema and timing fields are omitted for readability. These checks query stored spans and do not invoke an LLMBefore (c4f506a)
Team SQL
curl -sS -K /tmp/litellm-scope-proof/a.curl http://127.0.0.1:4104/v1/traces/query -d '{"sql":"SELECT TeamId, SpanName FROM otel_traces ORDER BY TeamId"}'{"detail":"Method Not Allowed"}Explicit other-team read
curl -sS -K /tmp/litellm-scope-proof/a.curl http://127.0.0.1:4104/v1/traces/query --data-binary @/tmp/litellm-scope-proof/other-team-query.request.json, containing{"sql":"SELECT TeamId, SpanName FROM trace_scope_proof.otel_traces WHERE TeamId = 'scope-proof-b'"}{"detail":"Method Not Allowed"}Admin SQL
curl -sS -K /tmp/litellm-scope-proof/admin.curl http://127.0.0.1:4104/v1/traces/query -d '{"sql":"SELECT TeamId, SpanName FROM otel_traces ORDER BY TeamId"}'{"detail":"Method Not Allowed"}Scoped query help
curl -sS -K /tmp/litellm-scope-proof/a.curl http://127.0.0.1:4104/v1/traces/query/help{"detail":"Not Found"}After (6d1cf91)
Team SQL
curl -sS -K /tmp/litellm-scope-proof/a.curl http://127.0.0.1:4105/v1/traces/query -d '{"sql":"SELECT TeamId, SpanName FROM otel_traces ORDER BY TeamId"}'{"data":[{"TeamId":"scope-proof-a","SpanName":"team-a-span"}]}Explicit other-team read
curl -sS -K /tmp/litellm-scope-proof/a.curl http://127.0.0.1:4105/v1/traces/query --data-binary @/tmp/litellm-scope-proof/other-team-query.request.json, containing{"sql":"SELECT TeamId, SpanName FROM trace_scope_proof.otel_traces WHERE TeamId = 'scope-proof-b'"}{"data":[]}Admin SQL
curl -sS -K /tmp/litellm-scope-proof/admin.curl http://127.0.0.1:4105/v1/traces/query -d '{"sql":"SELECT TeamId, SpanName FROM otel_traces ORDER BY TeamId"}'{"data":[{"TeamId":"scope-proof-a","SpanName":"team-a-span"},{"TeamId":"scope-proof-b","SpanName":"team-b-span"}]}Scoped query help
curl -sS -K /tmp/litellm-scope-proof/a.curl http://127.0.0.1:4105/v1/traces/query/help"access":"Authenticated team scope enforced by ClickHouse row policies; proxy admins can read all teams, while project-bound and teamless keys can read only their own rows"Caveats
Severe
Medium
Low
Type
New Feature
Final Attestation
Link to Devin session: https://app.devin.ai/sessions/6e2de59712e541e19e0537343bca6290
Open in Devin Desktop: https://app.devin.ai/desktop/session/6e2de59712e541e19e0537343bca6290?variant=devin
Requested by: @yujonglee-berri