You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This in and of itself works, but has a few quirks:
When using push_named_tags, the log context will leak between requests. As an example, a logged out request following a logged in request will still receive the named tags.
The push_named_tags method in general does not perform a deep merge on provided context, meaning if multiple push_named_tags were to set user, only the last one would win.
As is, both of these can be resolved with some tricks that ultimately come down to a special tag named _mdc, a lot of (inefficient) juggling, and a middleware to clear this after every request. This, however, is obviously inelegant and inefficient. A number of monkeypatches can also be applied, but that in turn has its own problems. It would be nicer to be able to use SemanticLogger.tagged, but I'm not sure how (or even if) it's possible to appropriately wrap Rails contexts in that.
Has anyone managed to set up something like this before? Or, better yet, is this something that would be beneficial to SemanticLogger overall? It seems relatively simple to tweak the requisite behavior, but I'm not sure it's desired.
I suspect all that would really be needed would be to change named_tags to properly deep merge, and then inject some middleware accordingly to set/clear things.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'd like to look at using
SemanticLogger#push_named_tags
to support MDC-like log contexts:This in and of itself works, but has a few quirks:
push_named_tags
, the log context will leak between requests. As an example, a logged out request following a logged in request will still receive the named tags.push_named_tags
method in general does not perform a deep merge on provided context, meaning if multiplepush_named_tags
were to setuser
, only the last one would win.As is, both of these can be resolved with some tricks that ultimately come down to a special tag named
_mdc
, a lot of (inefficient) juggling, and a middleware to clear this after every request. This, however, is obviously inelegant and inefficient. A number of monkeypatches can also be applied, but that in turn has its own problems. It would be nicer to be able to useSemanticLogger.tagged
, but I'm not sure how (or even if) it's possible to appropriately wrap Rails contexts in that.Has anyone managed to set up something like this before? Or, better yet, is this something that would be beneficial to SemanticLogger overall? It seems relatively simple to tweak the requisite behavior, but I'm not sure it's desired.
I suspect all that would really be needed would be to change named_tags to properly deep merge, and then inject some middleware accordingly to set/clear things.
Beta Was this translation helpful? Give feedback.
All reactions