Skip to content

feat(proxy): log routing target attempts - #378

Merged
nic-6443 merged 5 commits into
mainfrom
nic/issue-372-routing-logs-dp
May 22, 2026
Merged

feat(proxy): log routing target attempts#378
nic-6443 merged 5 commits into
mainfrom
nic/issue-372-routing-logs-dp

Conversation

@jarvis9443

@jarvis9443 jarvis9443 commented May 22, 2026

Copy link
Copy Markdown
Contributor

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_model
  • routing_attempt_count
  • routing_fallback_count
  • routing_attempts, containing target display name, per-target attempt index, HTTP status or error class, and success flag

Direct-model requests and cache hits omit these fields. Existing response model behavior and x-aisix-served-by are unchanged.

Tests:

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • RUSTFLAGS='--cfg=coverage' cargo test --workspace --all-features --no-run
  • cargo test -p aisix-obs
  • cargo test -p aisix-proxy

Summary by CodeRabbit

  • New Features

    • Access logs and usage events now include optional routing metadata when available: served-by model, per-attempt outcomes, total routing attempts, and fallback counts; routing telemetry is emitted across endpoints and in both success and failure (including streaming) flows.
    • New per-attempt routing telemetry is captured and surfaced with usage events.
  • Tests

    • Added tests verifying routing telemetry is recorded and serialized only when present and that per-attempt details are recorded.

Review Change Stack

Copilot AI review requested due to automatic review settings May 22, 2026 07:58
@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown

Caution

Review failed

Failed to post review comments

📝 Walkthrough

Walkthrough

Adds 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.

Changes

Routing Telemetry System

Layer / File(s) Summary
Observability types and contracts
crates/aisix-obs/src/usage.rs, crates/aisix-obs/src/access_log.rs, crates/aisix-obs/src/lib.rs, tests
Adds RoutingAttemptEvent; extends UsageEvent and AccessLog with served_by_model, routing_attempt_count, routing_fallback_count, and routing_attempts. Public re-exports updated; tests verify conditional serialization and access-log rendering.
Chat handler routing structures and dispatch integration
crates/aisix-proxy/src/chat.rs
Introduces RoutingTelemetry, DispatchFailure, and mapping helpers; changes dispatch to return Result<Success, DispatchFailure>; extends Success, UpstreamCharge, and UsageExtras to carry routing info through validation, streaming, success, failure, and guardrail paths.
Emit functions and instrumentation
crates/aisix-proxy/src/chat.rs
Computes routing_attempts_json, injects routing into emit_access_log and emit_usage_event, emits streaming routing snapshots in on_complete, and sets cache-hit routing defaults.
Endpoint access-log routing field stubs
crates/aisix-proxy/src/audio.rs, completions.rs, embeddings.rs, images.rs, messages.rs, passthrough.rs, rerank.rs, responses.rs
All endpoints initialize new AccessLog routing fields to None when emitting access logs.
Routing telemetry tests
crates/aisix-proxy/src/lib.rs
Tests wire an aisix_obs::UsageSink into proxy state to capture emitted usage events; assertions validate served-by model, attempt/fallback counts, and per-attempt sequences; adds streaming test for a failed initial attempt.

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding logging for routing target attempts across the proxy module.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::AccessLog and aisix_obs::UsageEvent with 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 None where 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.

Comment thread crates/aisix-proxy/src/chat.rs
Copilot AI review requested due to automatic review settings May 22, 2026 08:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Comment thread crates/aisix-proxy/src/chat.rs Outdated
@nic-6443
nic-6443 merged commit 91a0567 into main May 22, 2026
8 checks passed
@nic-6443
nic-6443 deleted the nic/issue-372-routing-logs-dp branch May 22, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: The log needs to be able to see which model in the model group was accessed

3 participants