Skip to content

feat: make HTTP header to log attribute mapping configurable#257

Closed
stuartwdouglas wants to merge 1 commit intomainfrom
sdouglas/configurable-header-log-attrs
Closed

feat: make HTTP header to log attribute mapping configurable#257
stuartwdouglas wants to merge 1 commit intomainfrom
sdouglas/configurable-header-log-attrs

Conversation

@stuartwdouglas
Copy link
Copy Markdown
Contributor

Replace the hard-coded X-Blox-Workstation-Id header extraction in LoggingMiddleware with a general-purpose header-attrs config map in the log block.

Any header can now be mapped to a log attribute via config:

log {
  header-attrs = {
    "X-Blox-Workstation-Id" = "blox.workstation_id"
    "X-Request-Id"          = "request_id"
  }
}

Changes

  • Added HeaderAttrs map[string]string to logging.Config
  • Updated LoggingMiddleware to accept the map and iterate over it
  • Threaded the config through newServer

Replace the hard-coded X-Blox-Workstation-Id header extraction in
LoggingMiddleware with a general-purpose header-attrs config map in the
log block. Any header can now be mapped to a log attribute via config:

  log {
    header-attrs = {
      "X-Blox-Workstation-Id" = "blox.workstation_id"
    }
  }

Amp-Thread-ID: https://ampcode.com/threads/T-019d8a28-e244-724f-834e-79e196aab7c2
Co-authored-by: Amp <amp@ampcode.com>
@stuartwdouglas stuartwdouglas requested a review from a team as a code owner April 14, 2026 04:09
@stuartwdouglas stuartwdouglas requested review from alecthomas and removed request for a team April 14, 2026 04:09
@alecthomas
Copy link
Copy Markdown
Collaborator

#256 won the race! But also consolidates the middleware into the logging package

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.

2 participants