Skip to content

CorrelationIdMiddlewareConfig.header_name changes the echoed header but not the one the request id is read from #116

Closed

Description

@AlexeyShalaev

Problem

CorrelationIdMiddlewareConfig.header_name only changes the header the request id is echoed in. ContextMiddleware still reads the incoming id from x-request-id, because its default extractors hardcode that key, and request_id_header is used only for the echo.

The FastAPI page presents it as the way to change the header name:

MiddlewareConfig(correlation_id=CorrelationIdMiddlewareConfig(header_name="X-Correlation-ID"))

With that config, a caller sending X-Correlation-ID: abc gets a freshly minted id back in X-Correlation-ID, and abc never reaches the logs or outbound propagation. A caller sending X-Request-ID: abc gets abc back, but under the other header.

Proposal

When no explicit header mapping is given, read the request id from the same header it is echoed in: build the default extractors from request_id_header instead of the literal x-request-id. An explicit mapping (context_headers from #110, once merged) stays as given.

Acceptance

  • With header_name="X-Correlation-ID", a request carrying X-Correlation-ID: abc binds request_id=abc and gets abc back in X-Correlation-ID.
  • With the default config nothing changes.

Activity

  1. added
    bug
    on Nov 13, 2026
  2. AlexeyShalaev commented on Nov 13, 2026

    @AlexeyShalaev
    MemberAuthor

    PR is up: #117, stacked on #115. Without an explicit mapping the request id is now read from request_id_header. The default config doesn't change. With a custom header_name, an incoming X-Request-ID is no longer read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions