Request id

A request ID is a unique identifier generated or accepted at the HTTP boundary for an incoming request. It is stored in the request context, returned in the X-Request-Id response header, and attached to log entries so operations belonging to the same request can be correlated.

Minimal example

go
id := middleware.GetReqID(r.Context())
logger := base.With("request_id", id)

Learn this concept

Lesson 6.5 · Request-scoped logging and timeouts

Used in exercises

Exercise 6.6 · Request context and timeout layer