Skip to content

Commit

Permalink
Introduces client side javascript error tracking
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hennevogel committed Aug 29, 2019
1 parent d89df6e commit ba660a5
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ReleaseNotes-2.11
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/api/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
GEM
remote: https://rubygems.org/
remote: https://rails-assets.org/
specs:
actioncable (5.2.3)
actionpack (= 5.2.3)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions src/api/app/assets/javascripts/webui2/airbrake-js.js.erb
Original file line number Diff line number Diff line change
@@ -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!');
}
});
};
};
1 change: 1 addition & 0 deletions src/api/app/assets/javascripts/webui2/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@
//= require rails-timeago
//= require webui2/kiwi_editor.js
//= require webui2/monitor.js
//= require webui2/airbrake-js
9 changes: 9 additions & 0 deletions src/api/config/options.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ba660a5

Please sign in to comment.