Skip to content

fix: propagate tracing_ids to all route handlers#146

Open
lloydmak99 wants to merge 1 commit into
mainfrom
fix/tracing-ids-all-routes
Open

fix: propagate tracing_ids to all route handlers#146
lloydmak99 wants to merge 1 commit into
mainfrom
fix/tracing-ids-all-routes

Conversation

@lloydmak99
Copy link
Copy Markdown
Contributor

Problem

The e2e tracing PR (#130) only wired TracingIds (request_id, org_id, workspace_id) into the /v1/chat/completions handler. All other routes had tracing_ids: None, meaning requests to those endpoints were logged without request_id, org_id, or workspace_id — making them invisible in the Datadog e2e tracing dashboard (which filters @fields.org_id:*).

Affected routes:

  • /v1/completions
  • /v1/embeddings
  • /v1/rerank
  • /v1/score
  • /v1/images/generations
  • /v1/images/edits
  • /v1/audio/transcriptions
  • catch-all passthrough

Fix

Extract Extension<TracingIds> in all route handlers and pass Some(tracing_ids) through to ProxyOpts:

  • completions.rs: extract and propagate TracingIds
  • catch_all.rs: extract and propagate in both streaming and JSON branches
  • passthrough.rs: extract in all 5 handler fns, add tracing_ids param to json_passthrough_encrypted helper, propagate in all ProxyOpts (both url_override and backend_pool branches)

Not changed: tokenize route — uses proxy::proxy_simple which has no ProxyOpts (no signing, no usage, no structured logging).

Testing

  • cargo check — clean
  • cargo clippy --all-targets — clean
  • cargo test — 134/134 passed

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request integrates TracingIds into various API routes (such as catch-all, completions, and passthrough endpoints) by extracting them via Axum's Extension and passing them down to the proxy options. The feedback identifies two instances in catch_all.rs and passthrough.rs where tracing_ids is unnecessarily cloned. Since the conditional branches are mutually exclusive, tracing_ids can be moved directly without cloning, which avoids redundant heap allocations.

Comment thread src/routes/catch_all.rs
backend_guard: Some(backend_guard),
response_shape: ResponseShape::ChatCompletion,
tracing_ids: None,
tracing_ids: Some(tracing_ids.clone()),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The .clone() here is unnecessary. Since the if and else if branches are mutually exclusive, Rust's borrow checker allows moving tracing_ids into both branches without cloning, avoiding redundant heap allocations of the TracingIds strings on the hot path.

Suggested change
tracing_ids: Some(tracing_ids.clone()),
tracing_ids: Some(tracing_ids),

Comment thread src/routes/passthrough.rs
backend_guard: None,
response_shape: ResponseShape::ChatCompletion,
tracing_ids: None,
tracing_ids: Some(tracing_ids.clone()),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The .clone() here is unnecessary. Since the Some and None branches of the match url_override are mutually exclusive, Rust's borrow checker allows moving tracing_ids into both branches without cloning, avoiding redundant heap allocations of the TracingIds strings on the hot path.

Suggested change
tracing_ids: Some(tracing_ids.clone()),
tracing_ids: Some(tracing_ids),

… logs

Two fixes for e2e tracing:

1. Propagate TracingIds to all route handlers (not just chat_completions):
   - completions.rs: extract Extension<TracingIds>
   - catch_all.rs: extract Extension<TracingIds>
   - passthrough.rs: extract in all handlers, add param to helper
   Previously these routes had tracing_ids: None, making org_id, request_id,
   workspace_id invisible in Datadog dashboards.

2. Lowercase model name in structured logs:
   The proxy logged model=opts.model_name (original case, e.g.
   'Qwen/Qwen3.5-122B-A10B') but Datadog lowercases ALL metric tags
   and Docker label tags (e.g. 'qwen/qwen3.5-122b-a10b'). This caused
   the same traffic to appear under two different model names depending
   on which facet you query (@fields.model vs model tag), breaking
   joins with cloud_api metrics which also use lowercase model tags.
   Now logs emit lowercase model names consistent with all other sources.
@lloydmak99 lloydmak99 force-pushed the fix/tracing-ids-all-routes branch from b8d6a1f to 1627f0e Compare May 28, 2026 21:09
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.

1 participant