From 8e6e730c8097f04195e79b29f9b91a0db9bd5dad Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 4 Apr 2019 11:47:55 +0200 Subject: [PATCH 1/2] Send user information to sentry without email --- app/javascript/shared/track/sentry.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/javascript/shared/track/sentry.js b/app/javascript/shared/track/sentry.js index 5c3bafc17..f5f485148 100644 --- a/app/javascript/shared/track/sentry.js +++ b/app/javascript/shared/track/sentry.js @@ -6,9 +6,7 @@ const { key, enabled, user, environment } = gon.sentry || {}; if (enabled && key) { Sentry.init({ dsn: key, environment }); - if (user.email) { - Sentry.configureScope(scope => { - scope.setUser(user); - }); - } + Sentry.configureScope(scope => { + scope.setUser(user); + }); } From 4fb889f10a91ec0deedabf49add196fa55715a86 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 4 Apr 2019 14:21:18 +0200 Subject: [PATCH 2/2] Send browser support information and format user id --- app/controllers/application_controller.rb | 3 ++- app/javascript/shared/track/sentry.js | 3 ++- spec/controllers/application_controller_spec.rb | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7551320aa..8ab881d8b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -195,7 +195,7 @@ class ApplicationController < ActionController::Base def sentry_user user = logged_user - { id: user&.id, role: user&.class&.name || 'Guest' }.compact + { id: user ? "#{user.class.name}##{user.id}" : 'Guest' } end def sentry_config @@ -205,6 +205,7 @@ class ApplicationController < ActionController::Base key: sentry[:client_key], enabled: sentry[:enabled], environment: sentry[:environment], + browser: { modern: browser.modern? }, user: sentry_user } end diff --git a/app/javascript/shared/track/sentry.js b/app/javascript/shared/track/sentry.js index f5f485148..23410535a 100644 --- a/app/javascript/shared/track/sentry.js +++ b/app/javascript/shared/track/sentry.js @@ -1,6 +1,6 @@ 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 if (enabled && key) { @@ -8,5 +8,6 @@ if (enabled && key) { Sentry.configureScope(scope => { scope.setUser(user); + scope.setExtra('browser', browser.modern ? 'modern' : 'legacy'); }); } diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index f07bd8737..d8070743d 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -34,7 +34,7 @@ describe ApplicationController, type: :controller do context 'when no one is logged in' do it do expect(Raven).to have_received(:user_context) - .with({ role: 'Guest' }) + .with({ id: 'Guest' }) end it do @@ -53,7 +53,7 @@ describe ApplicationController, type: :controller do it do expect(Raven).to have_received(:user_context) - .with({ id: current_user.id, role: 'User' }) + .with({ id: "User##{current_user.id}" }) end it do @@ -77,7 +77,7 @@ describe ApplicationController, type: :controller do it do expect(Raven).to have_received(:user_context) - .with({ id: current_user.id, role: 'User' }) + .with({ id: "User##{current_user.id}" }) end it do