Skip to content

feat(server): add request-ID middleware for request correlation#1082

Open
sauagarwa wants to merge 1 commit intoNVIDIA:mainfrom
sauagarwa:932-request-id-middleware/sauagarwa
Open

feat(server): add request-ID middleware for request correlation#1082
sauagarwa wants to merge 1 commit intoNVIDIA:mainfrom
sauagarwa:932-request-id-middleware/sauagarwa

Conversation

@sauagarwa
Copy link
Copy Markdown

Summary

Add request-ID middleware to the gateway server so every request carries a unique, traceable identifier. Uses tower-http's SetRequestIdLayer and PropagateRequestIdLayer with UUID v4 generation, recording the ID in the tracing span and returning it in the x-request-id response header. Client-supplied IDs are preserved (no overwrite).

Related Issue

Closes #932

Changes

  • Cargo.toml: Enable request-id feature on the tower-http workspace dependency
  • crates/openshell-server/src/multiplex.rs:
    • Add UuidRequestId struct implementing MakeRequestId (UUID v4 via existing uuid crate)
    • Update make_request_span to extract and record x-request-id in the tracing span
    • Add request_id_middleware! macro for consistent layer ordering: SetRequestIdTraceLayerPropagateRequestId
    • Apply middleware to both gRPC and HTTP inner services in MultiplexService::serve()
    • Add 7 unit tests: UUID generation, uniqueness, response header presence, client ID preservation, per-request uniqueness, gRPC content-type routing, and trace span recording
  • crates/openshell-server/tests/multiplex_integration.rs:
    • Add grpc_response_propagates_request_id integration test verifying tonic metadata ↔ HTTP header roundtrip for both server-generated and client-supplied request IDs

Log output before

INFO request{method=POST path=/openshell.v1.OpenShell/CreateSandbox}: response status=200 latency_ms=45
INFO request{method=POST path=/openshell.v1.OpenShell/CreateSandbox}: response status=200 latency_ms=312

Log output after

INFO request{method=POST path=/openshell.v1.OpenShell/CreateSandbox request_id=a1b2c3d4-...}: response status=200 latency_ms=45
INFO request{method=POST path=/openshell.v1.OpenShell/CreateSandbox request_id=e5f6a7b8-...}: response status=200 latency_ms=312

Testing

  • mise run pre-commit passes
  • Unit tests added/updated (7 new tests in multiplex::tests)
  • Integration test added (grpc_response_propagates_request_id)
  • Full cargo test -p openshell-server passes (353 tests, 0 failures)
  • Verified on running cluster — request IDs appear in all gRPC endpoint logs

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (if applicable)

@sauagarwa sauagarwa requested a review from a team as a code owner April 30, 2026 16:44
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented Apr 30, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 30, 2026

All contributors have signed the DCO ✍️ ✅
Posted by the DCO Assistant Lite bot.

Add a UUID-based request-ID middleware using tower-http's request-id
feature. Each inbound request receives a unique x-request-id header
(or preserves a client-supplied one), which is recorded in the tracing
span and propagated to the response.

This enables operators to correlate log lines across the middleware
stack for a single request under concurrent load, and lets clients
reference specific requests in bug reports.

Signed-off-by: sauagarwa <sauagarw@redhat.com>
@sauagarwa sauagarwa force-pushed the 932-request-id-middleware/sauagarwa branch from 942d293 to d7f49b2 Compare April 30, 2026 16:51
@sauagarwa
Copy link
Copy Markdown
Author

I have read the DCO document and I hereby sign the DCO.

recheck

@sauagarwa
Copy link
Copy Markdown
Author

recheck

@sauagarwa
Copy link
Copy Markdown
Author

I have read the DCO document and I hereby sign the DCO.

@sauagarwa
Copy link
Copy Markdown
Author

recheck

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(server): add request-ID middleware for request correlation

1 participant