https://github.com/josestg/httpreqid
httpreqid is a net/http compatible middleware designed for generating a request ID for each request if it doesn't already have one, and propagates it into the request context and response.
https://github.com/josestg/httpreqid
go logging observability request-id slog
Last synced: about 1 month ago
JSON representation
httpreqid is a net/http compatible middleware designed for generating a request ID for each request if it doesn't already have one, and propagates it into the request context and response.
- Host: GitHub
- URL: https://github.com/josestg/httpreqid
- Owner: josestg
- License: bsd-3-clause
- Created: 2024-03-02T08:41:35.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-12T09:57:32.000Z (about 1 year ago)
- Last Synced: 2025-01-31T06:47:06.931Z (3 months ago)
- Topics: go, logging, observability, request-id, slog
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# httpreqid
httpreqid is a `net/http` compatible middleware designed for generating a request ID for each request if it doesn't already have one, and propagates it into the request context and response.
By default, this middleware will look for headers such as `X-Request-ID`, `X-Correlation-ID`, `X-Trace-ID`, `Request-ID`, `Correlation-ID`, and `Trace-ID`.
Additionally, this middleware provides a handler for `log/slog` that automatically adds the request ID to the log record.
## Install
```shell
go get github.com/josestg/httpreqid
```## Examples
1. [A Simple Example of Using `crypto/rand`](examples/randstr)