Sentry-ruby: Raven.user_context results in ActionController::InvalidAuthenticityToken

Created on 31 Aug 2020  路  4Comments  路  Source: getsentry/sentry-ruby

I've set up Raven context in my application controller. However user_context results in invalid authenticity token errors. I tried skip_before_action :verify_authenticity_token, only: [:set_raven_context] without success.

I followed Sentry Rails set up directions. Is this a bug or an issue with my set up?

before_action :set_raven_context
def set_raven_context
Raven.user_context(id: current_user&.id)
Raven.extra_context(params: params.to_unsafe_h, url: request.url)
end

question

Most helpful comment

I had added before_action :set_raven_context above the protect_from_forgery call. Moving the before_action call to below protect_from_forgery solve this issue.

All 4 comments

changing Raven.user_context(id: current_user&.id) to Raven.user_context(id: 12345) does not create the error. So, Raven.user_context is not erring... But, for some reason passing current_user is throwing an invalid authenticity token. I'm not sure why that would be.

It looks to me that the issue is on the current_user in your app instead of the SDK. So here is probably not the best place to get an answer for it 馃槃


There are many possible ways to get the InvalidAuthenticityToken error. I suggest you searching for related issues in the Rails repo & the authentication library (like devise) you're using

I had added before_action :set_raven_context above the protect_from_forgery call. Moving the before_action call to below protect_from_forgery solve this issue.

@atstockland I'm glad that you found a solution and posted it back to help others 馃槈

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sanjibukai picture sanjibukai  路  5Comments

lewisifer picture lewisifer  路  4Comments

dcramer picture dcramer  路  8Comments

SirRawlins picture SirRawlins  路  7Comments

jonhue picture jonhue  路  5Comments