From ba660a5527ecbe985347a536892467bd66f09112 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 28 Aug 2019 18:17:29 +0200 Subject: [PATCH] Introduces client side javascript error tracking As a developer you might be interested in exceptions that occur in the javascript that is running in the users browser. Separate this with another errbit configuration key because this is getting exposed publicly. --- ReleaseNotes-2.11 | 3 ++- src/api/Gemfile | 4 +++ src/api/Gemfile.lock | 3 +++ .../javascripts/webui2/airbrake-js.js.erb | 25 +++++++++++++++++++ .../assets/javascripts/webui2/application.js | 1 + src/api/config/options.yml.example | 9 +++++++ 6 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/api/app/assets/javascripts/webui2/airbrake-js.js.erb diff --git a/ReleaseNotes-2.11 b/ReleaseNotes-2.11 index 1f2bf36c561..584762508f8 100644 --- a/ReleaseNotes-2.11 +++ b/ReleaseNotes-2.11 @@ -27,7 +27,8 @@ Features ======== Generic: - * + * You can track javascript errors that occur in the users browser with errbit, enable + it in the API configuration file options.yml. User Interface: * Colors were adjusted to improve contrast thus improving readability diff --git a/src/api/Gemfile b/src/api/Gemfile index d81da89759a..4b018b789c2 100644 --- a/src/api/Gemfile +++ b/src/api/Gemfile @@ -212,4 +212,8 @@ group :assets do gem 'font-awesome-sass' # assets for formatting dates gem 'momentjs-rails' + # for catching javascript exceptions + source 'https://rails-assets.org' do + gem 'rails-assets-airbrake-js-client' + end end diff --git a/src/api/Gemfile.lock b/src/api/Gemfile.lock index 3296de7d52e..ba9892a9e8f 100644 --- a/src/api/Gemfile.lock +++ b/src/api/Gemfile.lock @@ -1,5 +1,6 @@ GEM remote: https://rubygems.org/ + remote: https://rails-assets.org/ specs: actioncable (5.2.3) actionpack (= 5.2.3) @@ -303,6 +304,7 @@ GEM bundler (>= 1.3.0) railties (= 5.2.3) sprockets-rails (>= 2.0.0) + rails-assets-airbrake-js-client (1.6.6) rails-controller-testing (1.0.4) actionpack (>= 5.0.1.x) actionview (>= 5.0.1.x) @@ -525,6 +527,7 @@ DEPENDENCIES puma (~> 4.0) pundit rails (~> 5.2) + rails-assets-airbrake-js-client! rails-controller-testing rails-timeago (~> 2.0) rails_tokeninput (>= 1.6.1.rc1) diff --git a/src/api/app/assets/javascripts/webui2/airbrake-js.js.erb b/src/api/app/assets/javascripts/webui2/airbrake-js.js.erb new file mode 100644 index 00000000000..a08b1ad732e --- /dev/null +++ b/src/api/app/assets/javascripts/webui2/airbrake-js.js.erb @@ -0,0 +1,25 @@ +//= require airbrake-js-client +var errbit_id = "<%= CONFIG['errbit_javascript_api_key'] %>"; +var errbit_host = "<%= CONFIG['errbit_javascript_host'] %>"; + +if (errbit_id) { + var airbrake = new airbrakeJs.Client({ + projectId: 1, + projectKey: errbit_id, + host: errbit_host, + environment: 'production', + }); + + window.onerror = function (message, file, line, col, error) { + var promise = airbrake.notify(error); + promise.then(function(notice) { + if (notice.id) { + // console.log('Notified errbit. Notice:', notice.id); + console.log('Notified errbit.'); + } else { + // console.log('Notifying errbit failed. Reason:', notice.error); + console.log('Notifying errbit failed!'); + } + }); + }; +}; diff --git a/src/api/app/assets/javascripts/webui2/application.js b/src/api/app/assets/javascripts/webui2/application.js index a96ef97fe1c..15c42a85a84 100644 --- a/src/api/app/assets/javascripts/webui2/application.js +++ b/src/api/app/assets/javascripts/webui2/application.js @@ -53,3 +53,4 @@ //= require rails-timeago //= require webui2/kiwi_editor.js //= require webui2/monitor.js +//= require webui2/airbrake-js diff --git a/src/api/config/options.yml.example b/src/api/config/options.yml.example index b0a02fbdad6..c0ff71fe44d 100644 --- a/src/api/config/options.yml.example +++ b/src/api/config/options.yml.example @@ -67,6 +67,15 @@ default: &default #errbit_api_key: api_key_of_your_app #errbit_project_id: #errbit_host: installation.of.errbit.com + # + # If you also want to track javascript errors that occur in the users browser, + # you can supply this api key. + # PLEASE NOTE: THIS API KEY IS GOING TO GET EXPOSED TO EVERYONE VISITING YOUR OBS + # INSTANCE. BE AWARE THAT ANYONE CAN SEND FAKE DATA WITH IT, + # DENIAL OF SERVICE YOUR ERRBIT SERVER OR DO ANY OTHER NASTY THING + # YOU CAN THINK ABOUT. BE VIGILANT! + #errbit_javascript_api_key: errbit api key + #errbit_javascript_host: errbit.example.com ################## # LDAP options