Skip to content

Give inference requests an X-Request-ID - #442

Merged
Priyanshu-u07 merged 1 commit into
mainfrom
feat/inference-request-id
Oct 26, 2026
Merged

Priyanshu-u07 merged 1 commit into
mainfrom
feat/inference-request-id

Conversation

@Priyanshu-u07

Copy link
Copy Markdown
Collaborator

The inference app never set a request id, so request_id_ctx was always empty there: its JSON logs and error responses carried no id, and its calls to the gateway could not be matched to a request.

  • Add RequestIDMiddleware to common/middleware.py. It's plain ASGI rather than BaseHTTPMiddleware, so streamed responses pass through untouched. It keeps a caller's X-Request-ID if it's short and plain, otherwise generates one, and sets it in request_id_ctx, request.state.request_id and the response header.
  • Install it on the inference app as the outermost middleware.
  • Forward the id in ApiGatewayClient so gateway logs can be matched to the inference request.

Tests: test_request_id.py (8 tests: new id, kept id, rejected ids, streaming, the real app, forwarding to the gateway). Full suite with the CI ignore list: 3,061 passed.

The inference app never set a request id, so its logs and error responses had none and its calls to the gateway could not be matched to a request. Add a plain ASGI request-id middleware to common (it leaves streamed responses untouched), install it on the inference app, and forward the id in ApiGatewayClient. A caller's id is kept only if it is short and plain.

Signed-off-by: Priyanshu-u07 <connect.priyanshu8271@gmail.com>
@Priyanshu-u07
Priyanshu-u07 merged commit 28321a6 into main Oct 26, 2026
2 checks passed
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