One feature I’ve missed in logging packages is a way to turn on debug logging for one HTTP request at a time by use of a HTTP header. If this is passed on to any other HTTP services called, like in a micro-services architecture, we can get a cheap trace. The other requests will still log at the default (non-debug) level. I’ve written an extension for slog called tracerbullet that does exactly that.
Since version 1.21 Go has a structure logging package called slog. It has a feature where you can create your own handler. Tracerbullet is one of these handlers. It takes a user defined HTTP header name and value. If an HTTP request comes in with that header and value then this is passed along in the context object. The handler then turns on debug level logging for this one request. A few more things need be set. Please look at the README.md in the repo for more details and an example setup in docker compose.
Please have a look at it and let me know of any issues on Github.
Copyright (c) 2024 Michel Hollands