flagr icon indicating copy to clipboard operation
flagr copied to clipboard

Add extra fields to the log entries

Open gkkishan opened this issue 3 years ago • 1 comments

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}

gkkishan avatar Jun 08 '21 12:06 gkkishan

There're 3 logging places I can think of

  1. Flagr's verbose logging middleware to stdout https://github.com/checkr/flagr/blob/master/pkg/config/middleware.go#L43
  2. Flagr's evalResult to stdout https://github.com/checkr/flagr/blob/master/pkg/handler/eval.go#L327
  3. 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!

zhouzhuojie avatar Jun 09 '21 00:06 zhouzhuojie

Stale issue message

github-actions[bot] avatar Aug 26 '22 21:08 github-actions[bot]