Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interceptors: Update logging interceptor Reporter to re-extract fields from context before logging #702

Merged

Conversation

chancez
Copy link
Contributor

@chancez chancez commented Apr 8, 2024

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.fieldsFromCtxCallMetaFn PostCall, 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.

…s from context before logging

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.

Signed-off-by: Chance Zibolski <[email protected]>
Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me, thanks for the PR!

@johanbrandhorst johanbrandhorst merged commit ea545dc into grpc-ecosystem:main Apr 8, 2024
5 checks passed
@chancez chancez deleted the pr/chancez/log_updated_fields branch April 8, 2024 21:00
@chancez
Copy link
Contributor Author

chancez commented Apr 8, 2024

Wow thanks for the promptness!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants