When using logging.WithFieldsFromContext, if the value being extracted as a log field is modified after the logging interceptor initializes the Reporter before the underlying handler is called, then the updated value will not be reflected in the log message.
To fix this, re-extract fields from the context before logging them in PostCall, PostMsgSend and PostMsgReceive, ensuring the updated values in the context are logged.
Changes
Call c.opts.fieldsFromCtxCallMetaFnPostCall, PostMsgSend and PostMsgReceive
Update tests to verify log fields derived from context values are updated in the reporter.Post* methods
Verification
Unit tests
Used this branch in a (private) project where I was expecting this behavior to work, and after the patch is applied, the expected behavior is observed.
When using logging.WithFieldsFromContext, if the value being extracted as a log field is modified after the logging interceptor initializes the Reporter before the underlying handler is called, then the updated value will not be reflected in the log message.
To fix this, re-extract fields from the context before logging them in PostCall, PostMsgSend and PostMsgReceive, ensuring the updated values in the context are logged.
Changes
c.opts.fieldsFromCtxCallMetaFn
PostCall
,PostMsgSend
andPostMsgReceive
reporter.Post*
methodsVerification