Uh oh!
There was an error while loading. Please reload this page.
fix(proxy): record messages stream telemetry - #363
Conversation
📝 WalkthroughWalkthroughThe PR adds time-to-first-token (TTFT) measurement for cross-provider streaming by threading a ChangesCross-provider Streaming TTFT and Conditional Usage Event Emission
🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Pull request overview
This PR fixes telemetry gaps for Anthropic /v1/messagesstreaming requests that are protocol-converted and routed to an OpenAI-compatible upstream. It defers usage/telemetry emission until the upstream stream completes so the proxy can record TTFT, token counts, provider request metadata, and correctly tag inbound_protocol = "anthropic" for the conversion path (while keeping Anthropic-upstream byte-stream passthrough unchanged).
Changes:
- Plumbs request start time and identity metadata into the cross-provider streaming path and emits usage on stream completion.
- Adds TTFT tracking for
/v1/messagesprotocol-conversion streaming by observing the first upstream chunk that carries generated output. - Adds an E2E-style unit test verifying that cross-provider streaming emits a single usage event with TTFT and upstream metadata.
Comments suppressed due to low confidence (1)
crates/aisix-proxy/src/messages.rs:785
finish_reasonis derived viaformat!("{fr:?}").to_lowercase(), which collapses variants likeContentFilter/ToolCallsintocontentfilter/toolcalls(missing underscores) and can diverge from the canonical wire labels used elsewhere (e.g., chat.rs’finish_reason_label). This will produce inconsistentUsageEvent.finish_reasonvalues for/v1/messagesprotocol-conversion streams. Consider reusing the same mapping (stop,length,content_filter,tool_calls,other) here.
if let Some(fr) = chunk.finish_reason.as_ref() {
comp.finish_reason = format!("{fr:?}").to_lowercase();
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Fixes#359.
When an Anthropic
/v1/messagesstreaming request is routed to an OpenAI-compatible upstream, telemetry now waits for the stream to finish before emitting usage. That lets the proxy record TTFT, token counts, provider request metadata, canonical finish-reason labels, andinbound_protocol = "anthropic"for the protocol-conversion path.TTFT histogram samples are only recorded when the first-token measurement is known, so non-streaming/default paths do not add synthetic 0ms samples.
This keeps Anthropic-upstream byte-stream passthrough behavior unchanged.