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

FIX: Stop env mutation to allow all chained loggers to have the same env #110

Merged
merged 2 commits into from Mar 2, 2020

Conversation

OsamaSayegh
Copy link
Member

Logster allows the backtrace of a message to be provided via its env. This can be done by setting the env hash in the current thread's storage like so Thread.current[Logster::Logger::LOGSTER_ENV] = env_with_backtrace. Logster also has the ability to chain multiple loggers that do different things. The problem here is that if one of the chained loggers mutate something, that change may cause the remaining loggers to behave differently.

An example of this problem is base_store.rb at line 163 it does this: backtrace = env.delete(:backtrace). This affects us at Discourse where we ship all the logs from sites we host to a central place by adding a logger to logster's chain. The problem we're seeing is that the same log message has a completely different backtraces on the central website vs the website that originated the log message. The reason for this is 1) some messages rely on passing the backtrace via env, and 2) the env mutations that happen at line 163 in base_store.rb. This PR fixes the problem by duping env before deleting :backtrace from it (we still need to delete :backtrace from env because we don't want the backtrace to actually be part of env).

@SamSaffron
Copy link
Member

Looks good to me! Thanks

@SamSaffron SamSaffron merged commit f404c51 into master Mar 2, 2020
@OsamaSayegh OsamaSayegh deleted the fix-env-mutation branch March 2, 2020 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants