feat(proxy): log routing target attempts - #378
Conversation
|
Caution Review failedFailed to post review comments 📝 WalkthroughWalkthroughAdds routing telemetry types and threads per-attempt routing metadata through chat dispatch, access logs, and usage events; other endpoints set routing fields to None. Tests capture and assert emitted routing events for non-streaming and streaming failure scenarios. ChangesRouting Telemetry System
🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Pull request overview
This PR adds routing-target telemetry for /v1/chat/completions routing-model requests so operational logs and UsageEvent telemetry can show which target ultimately served the request and which upstream attempts failed before success.
Changes:
- Extend
aisix_obs::AccessLogandaisix_obs::UsageEventwith routing telemetry fields (served_by_model, attempt/fallback counts, and per-attempt trace). - Capture routing attempt details inside chat dispatch (including retries and fallbacks) and emit them via access logs and UsageEvents.
- Update proxy access-log emitters across endpoints to populate the new access-log fields (as
Nonewhere routing telemetry does not apply), and add tests for the new serialization/logging behavior.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/aisix-proxy/src/chat.rs | Implements routing telemetry capture/emission for chat requests and wires it into access logs + UsageEvents. |
| crates/aisix-proxy/src/lib.rs | Updates routing retry test to assert emitted UsageEvent includes routing telemetry. |
| crates/aisix-proxy/src/responses.rs | Populates new AccessLog fields with None for /v1/responses. |
| crates/aisix-proxy/src/rerank.rs | Populates new AccessLog fields with None for /v1/rerank. |
| crates/aisix-proxy/src/passthrough.rs | Populates new AccessLog fields with None for passthrough requests. |
| crates/aisix-proxy/src/messages.rs | Populates new AccessLog fields with None for /v1/messages. |
| crates/aisix-proxy/src/images.rs | Populates new AccessLog fields with None for /v1/images/generations. |
| crates/aisix-proxy/src/embeddings.rs | Populates new AccessLog fields with None for /v1/embeddings. |
| crates/aisix-proxy/src/completions.rs | Populates new AccessLog fields with None for /v1/completions. |
| crates/aisix-proxy/src/audio.rs | Populates new AccessLog fields with None for /v1/audio/*. |
| crates/aisix-obs/src/usage.rs | Adds RoutingAttemptEvent and new routing fields to UsageEvent, plus serialization tests. |
| crates/aisix-obs/src/lib.rs | Re-exports RoutingAttemptEvent. |
| crates/aisix-obs/src/access_log.rs | Adds routing fields to AccessLog and extends logging tests to assert field emission. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This adds routing-target telemetry for chat routing requests so logs can show the model that actually served the request and the failed target attempts that happened before it.
The DP now emits these low-sensitivity fields in both structured access logs and UsageEvent telemetry:
served_by_modelrouting_attempt_countrouting_fallback_countrouting_attempts, containing target display name, per-target attempt index, HTTP status or error class, and success flagDirect-model requests and cache hits omit these fields. Existing response model behavior and
x-aisix-served-byare unchanged.Tests:
cargo fmt --all -- --checkcargo clippy --workspace --all-targets -- -D warningsRUSTFLAGS='--cfg=coverage' cargo test --workspace --all-features --no-runcargo test -p aisix-obscargo test -p aisix-proxySummary by CodeRabbit
New Features
Tests