Send browser support information and format user id

This commit is contained in:
Paul Chavard 2019-04-04 14:21:18 +02:00
parent 8e6e730c80
commit 4fb889f10a
3 changed files with 7 additions and 5 deletions

View file

@ -195,7 +195,7 @@ class ApplicationController < ActionController::Base
def sentry_user def sentry_user
user = logged_user user = logged_user
{ id: user&.id, role: user&.class&.name || 'Guest' }.compact { id: user ? "#{user.class.name}##{user.id}" : 'Guest' }
end end
def sentry_config def sentry_config
@ -205,6 +205,7 @@ class ApplicationController < ActionController::Base
key: sentry[:client_key], key: sentry[:client_key],
enabled: sentry[:enabled], enabled: sentry[:enabled],
environment: sentry[:environment], environment: sentry[:environment],
browser: { modern: browser.modern? },
user: sentry_user user: sentry_user
} }
end end

View file

@ -1,6 +1,6 @@
import * as Sentry from '@sentry/browser'; import * as Sentry from '@sentry/browser';
const { key, enabled, user, environment } = gon.sentry || {}; const { key, enabled, user, environment, browser } = gon.sentry || {};
// We need to check for key presence here as we do not have a dsn for browser yet // We need to check for key presence here as we do not have a dsn for browser yet
if (enabled && key) { if (enabled && key) {
@ -8,5 +8,6 @@ if (enabled && key) {
Sentry.configureScope(scope => { Sentry.configureScope(scope => {
scope.setUser(user); scope.setUser(user);
scope.setExtra('browser', browser.modern ? 'modern' : 'legacy');
}); });
} }

View file

@ -34,7 +34,7 @@ describe ApplicationController, type: :controller do
context 'when no one is logged in' do context 'when no one is logged in' do
it do it do
expect(Raven).to have_received(:user_context) expect(Raven).to have_received(:user_context)
.with({ role: 'Guest' }) .with({ id: 'Guest' })
end end
it do it do
@ -53,7 +53,7 @@ describe ApplicationController, type: :controller do
it do it do
expect(Raven).to have_received(:user_context) expect(Raven).to have_received(:user_context)
.with({ id: current_user.id, role: 'User' }) .with({ id: "User##{current_user.id}" })
end end
it do it do
@ -77,7 +77,7 @@ describe ApplicationController, type: :controller do
it do it do
expect(Raven).to have_received(:user_context) expect(Raven).to have_received(:user_context)
.with({ id: current_user.id, role: 'User' }) .with({ id: "User##{current_user.id}" })
end end
it do it do