diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 02b4f0144..0cf7d51dd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -67,4 +67,17 @@ module ApplicationHelper Raven.capture_exception(e) {} end + + def sentry_config + sentry = Rails.application.secrets.sentry + if sentry + { + dsn: sentry[:browser], + id: current_user&.id, + email: current_email + }.to_json + else + {} + end + end end diff --git a/app/javascript/packs/application-old.js b/app/javascript/packs/application-old.js index 89c9a9706..2af95caeb 100644 --- a/app/javascript/packs/application-old.js +++ b/app/javascript/packs/application-old.js @@ -13,6 +13,7 @@ import 'babel-polyfill'; import 'typeahead.js'; +import '../shared/sentry'; import '../shared/rails-ujs-fix'; // Start Rails helpers diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index dce4ef0c5..e94c60e8d 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -13,6 +13,7 @@ import 'babel-polyfill'; import 'select2'; import 'typeahead.js'; +import '../shared/sentry'; import '../shared/rails-ujs-fix'; import '../new_design/buttons'; diff --git a/app/javascript/shared/sentry.js b/app/javascript/shared/sentry.js new file mode 100644 index 000000000..7332390d0 --- /dev/null +++ b/app/javascript/shared/sentry.js @@ -0,0 +1,14 @@ +import { init, configureScope } from '@sentry/browser'; +import { getData } from './data'; + +const { dsn, email, id } = getData('sentry'); + +if (dsn) { + init({ dsn }); + + if (email) { + configureScope(scope => { + scope.setUser({ id, email }); + }); + } +} diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index cc6e06cb7..be9304b91 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -17,7 +17,9 @@ = csrf_meta_tags :javascript - DATA = []; + DATA = [{ + sentry: #{raw(sentry_config)} + }]; %body = render partial: 'layouts/support_navigator_banner' = render partial: 'layouts/pre_maintenance' diff --git a/app/views/layouts/new_application.html.haml b/app/views/layouts/new_application.html.haml index 661a8990c..268c24f61 100644 --- a/app/views/layouts/new_application.html.haml +++ b/app/views/layouts/new_application.html.haml @@ -22,7 +22,9 @@ = stylesheet_link_tag :xray :javascript - DATA = []; + DATA = [{ + sentry: #{raw(sentry_config)} + }]; %body .page-wrapper = render partial: "layouts/support_navigator_banner" diff --git a/package.json b/package.json index 75418d893..15fcf1da8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "dependencies": { "@rails/webpacker": "4.0.0-pre.2", + "@sentry/browser": "^4.0.0-beta.12", "activestorage": "^5.2.0", "bloodhound-js": "^1.2.2", "chartkick": "^2.3.6", diff --git a/yarn.lock b/yarn.lock index 387c088b0..bd59124a8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -49,6 +49,49 @@ dependencies: any-observable "^0.3.0" +"@sentry/browser@^4.0.0-beta.12": + version "4.0.0-beta.12" + resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-4.0.0-beta.12.tgz#dff44c7a3732577057844b1643e0ba38c644138b" + dependencies: + "@sentry/core" "4.0.0-beta.12" + "@sentry/hub" "4.0.0-beta.12" + "@sentry/minimal" "4.0.0-beta.12" + "@sentry/types" "4.0.0-beta.12" + "@sentry/utils" "4.0.0-beta.12" + +"@sentry/core@4.0.0-beta.12": + version "4.0.0-beta.12" + resolved "https://registry.yarnpkg.com/@sentry/core/-/core-4.0.0-beta.12.tgz#c821e41b02c1d66e48fbef16da744f0173575558" + dependencies: + "@sentry/hub" "4.0.0-beta.12" + "@sentry/minimal" "4.0.0-beta.12" + "@sentry/types" "4.0.0-beta.12" + "@sentry/utils" "4.0.0-beta.12" + +"@sentry/hub@4.0.0-beta.12": + version "4.0.0-beta.12" + resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-4.0.0-beta.12.tgz#85267cec47c0bbf1094a537f7d14d19495c77234" + dependencies: + "@sentry/types" "4.0.0-beta.12" + "@sentry/utils" "4.0.0-beta.12" + +"@sentry/minimal@4.0.0-beta.12": + version "4.0.0-beta.12" + resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-4.0.0-beta.12.tgz#534e8edd065646e0e5f8d71443a63f6ce7187573" + dependencies: + "@sentry/hub" "4.0.0-beta.12" + "@sentry/types" "4.0.0-beta.12" + +"@sentry/types@4.0.0-beta.12": + version "4.0.0-beta.12" + resolved "https://registry.yarnpkg.com/@sentry/types/-/types-4.0.0-beta.12.tgz#0abd303692e48c0fc11afbfea8cbad87e625357a" + +"@sentry/utils@4.0.0-beta.12": + version "4.0.0-beta.12" + resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-4.0.0-beta.12.tgz#9d51e88634843232b6c6f0edb6df3d3fba83071e" + dependencies: + "@sentry/types" "4.0.0-beta.12" + "@sindresorhus/is@^0.7.0": version "0.7.0" resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.7.0.tgz#9a06f4f137ee84d7df0460c1fdb1135ffa6c50fd"