To give more background to my question, please refer to this Github issue - https://github.com/getsentry/raven-ruby/issues/144
I am using raven
which is an error logger. I want to add the id for the current_user
if user is logged in. The answer I received was
This should be done via your middleware or somewhere similar.
where this means setting the current_user in Raven.
I have read about middlewares, but still have not been able to figure out how can I get current_user
in one.
I do not have much idea about
Raven
, but below is a way, using which, we access the current user in a request, all over our application.We have created a class, which acts as a cache, and inserts/retrieves data from the current thread
And then, when the request is received, a check for the current session is performed, and then the user's model is inserted in the cache as below
Now, you can retrieve the current user from anywhere in your application, using the code below,
We also make sure to reset the cache before and after the request has been served, so we do this,
Hope this helps.