flagr
flagr copied to clipboard
Add extra fields to the log entries
It appears from the current logs that is getting emitted from flagr is coming with certain fields pre-defined. Without making changes to the code / forking and putting our own version, is there a provision in the flagr service where a new field can be added to the log? We are planning to add something like "sourceContext" that will tell us which system (or instance) of flagr (as we host multiple instances) is emitting this log? Not picky on the field name and it can be anything but just looking for a technical provision if this is allowed.
Current: {"level":"info","measure#flagr.latency":3609700,"method":"GET","msg":"completed handling request","remote":"172.17.0.1:56178","request":"/api/v1/flags","status":200,"text_status":"OK","time":"2021-06-08T07:39:32Z","took":3609700}
Expected: {"sourceContext": "blablabla", "level":"info","measure#flagr.latency":3609700,"method":"GET","msg":"completed handling request","remote":"172.17.0.1:56178","request":"/api/v1/flags","status":200,"text_status":"OK","time":"2021-06-08T07:39:32Z","took":3609700}
There're 3 logging places I can think of
- Flagr's verbose logging middleware to stdout https://github.com/checkr/flagr/blob/master/pkg/config/middleware.go#L43
- Flagr's evalResult to stdout https://github.com/checkr/flagr/blob/master/pkg/handler/eval.go#L327
- Flagr's evalResult to dataRecorder https://github.com/checkr/flagr/blob/master/pkg/handler/eval.go#L225
Each of them can be added with additional server-side logging context, from your description, looks like it's source 1
. Things can be configurable via env variables, for example
FLAGR_SERVER_SIDE_LOGGING_CONTEXT='{"sourceContext": "blablabla", "region": "xyz"}'
And then the whole logging context will be merged into the logging body - may want to do it in a backward compatible way.
PRs are welcome!
Stale issue message