smoke_detector 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: beac5b3fa1290a4d289c18f6b21e642b8588cf77
4
- data.tar.gz: 34be662f60eadf8723c41c844056b236ca18ae42
3
+ metadata.gz: 9539101ddc9c4b9edb48332bb8aa1e1261cf44fb
4
+ data.tar.gz: 6369af09d39456576eda2a3f3a27e41698b45e6a
5
5
  SHA512:
6
- metadata.gz: 2f3ae8cfb7e1d9187069f5e5678cb4ce8d8a728453da5668a8e4f23c920f8e2c4d6ec9d21452c10c1afa0b236bb10d4837fd173008850faa22f2677743b4c56f
7
- data.tar.gz: 7bfbffbf840d2fb3b7a2dae2215fec7a0f8f8eab41426d70e9961097660e3c265673feb3dbd53e89ecece34dbac68ca6a5448193a66aef83f78f543c46ec7efc
6
+ metadata.gz: c6bb76bf4122dc930759b1d4b80c3089c5880d388bd5c03e5d22d18ff0a55e8d6deb3d4b385ec793e99cfa269ce2fbce68a2d228a81c7ef57d198c4e5639960c
7
+ data.tar.gz: 90cde341fae602a40906b703a83bdadc76418f3141898b9c01d345bf81dc10f330292367fab85eeaaca5384db96bd633d2c87f32e276135bfc4222b520ce30d7
data/README.md CHANGED
@@ -13,7 +13,6 @@ Add the following to your `Gemfile`:
13
13
  ```
14
14
  gem 'smoke_detector'
15
15
  ```
16
- This assumes you're using Lumos Labs' gemfury account.
17
16
 
18
17
  Then add the provider's gem to your gemfile. Smoke Detector currently supports Rollbar and Airbrake. For example,
19
18
  ```
@@ -67,8 +66,10 @@ by Rollbar.js unless you do some additional filtering.
67
66
 
68
67
  The following config demonstrates how to filter JavaScript exceptions by
69
68
  the exception's message, and also, by the offending exception's source host url.
70
- You can choose to filter by `host_whitelist` or `ignored_messages` or both. It's
71
- up to you.
69
+ You can choose to filter by `hostWhitelist` or `ignoredMessages` or both. It's
70
+ up to you. Note the lower, camel-case of the setting keys. They should match
71
+ [rollbar.js's](https://github.com/rollbar/rollbar.js) documentation in order to
72
+ be passed-along to the rollbar.js framework appropriately.
72
73
 
73
74
  ```
74
75
  config.providers = [
@@ -77,13 +78,23 @@ config.providers = [
77
78
  api_key: ENV['ROLLBAR_KEY'],
78
79
  client_settings: {
79
80
  api_key: ENV['ROLLBAR_CLIENT_KEY'],
80
- ignored_messages: ["Error: Clippy.bmp not found. The end is nigh."],
81
- host_whitelist: ["yourdomain.com", "cdn.anotherdomain.com"]
81
+ ignoredMessages: ["Error: Clippy.bmp not found. The end is nigh."],
82
+ hostWhitelist: ["yourdomain.com", "cdn.anotherdomain.com"]
82
83
  }
83
84
  }
84
85
  ]
85
86
  ```
86
87
 
88
+ All key-value pairs under `client_settings` will be passed along to the javascript
89
+ client tracking library (in this case, Rollbar).
90
+
91
+ ### Rollbar.js Person data
92
+
93
+ By default, there is no person data sent to rollbar. In order to do that, you will have to override the rollbar person data config:
94
+
95
+ ```javascript
96
+ window._rollbarConfig.payload.person = { id: 1, email: 'someemail@example.com', username: 'someuser' }
97
+ ```
87
98
 
88
99
  TODO
89
100
  ----
@@ -2,6 +2,7 @@ module SmokeDetector::Providers
2
2
 
3
3
  class Provider
4
4
  attr_accessor :controller_proc
5
+ attr_reader :client_settings
5
6
 
6
7
  def initialize(api_key, client_settings = {}, settings = {})
7
8
  @client_settings = client_settings || {}
@@ -20,6 +21,10 @@ module SmokeDetector::Providers
20
21
  ''
21
22
  end
22
23
 
24
+ def default_client_settings
25
+ {}
26
+ end
27
+
23
28
  private
24
29
 
25
30
  def client_api_key
@@ -1,9 +1,7 @@
1
+ require 'json'
1
2
  module SmokeDetector::Providers
2
3
 
3
4
  class Rollbar < Provider
4
-
5
- attr_accessor :client_host_whitelist, :client_ignore_partial_messages
6
-
7
5
  def initialize(api_key, client_settings = {}, settings = {})
8
6
  super
9
7
  ::Rollbar.configure do |c|
@@ -19,8 +17,9 @@ module SmokeDetector::Providers
19
17
  c.filepath ||= ::Rails.application.class.parent_name + '.rollbar'
20
18
  end
21
19
 
22
- @client_host_whitelist = @client_settings[:host_whitelist] || []
23
- @client_ignored_messages = @client_settings[:ignored_messages] || []
20
+ @client_settings = default_client_settings
21
+ migrate_old_client_setting_syntax(client_settings)
22
+ @client_settings.deep_merge!(client_settings) if client_settings.present?
24
23
  end
25
24
 
26
25
  def alert(exception, options = {})
@@ -36,20 +35,19 @@ module SmokeDetector::Providers
36
35
  ::Rollbar.report_message(message, level, options)
37
36
  end
38
37
 
38
+ def default_client_settings
39
+ { captureUncaught: true, payload: { environment: ::Rails.env } }
40
+ end
41
+
39
42
  def client_monitoring_code
40
- return '' if client_api_key.blank?
43
+ return '' if client_settings[:api_key].blank?
44
+ client_settings[:accessToken] = client_settings.delete(:api_key)
41
45
  @client_monitoring_code ||= <<-JS
42
46
  <script>
43
- var _rollbarConfig = {
44
- accessToken: "#{@client_api_key}",
45
- captureUncaught: true,
46
- payload: {
47
- environment: "#{::Rails.env}"
48
- },
49
- hostWhiteList: #{@client_host_whitelist.to_s},
50
- ignoredMessages: #{@client_ignored_messages.to_s}
51
- };
52
- !function(a,b){function c(b){this.shimId=++h,this.notifier=null,this.parentShim=b,this.logger=function(){},a.console&&void 0===a.console.shimId&&(this.logger=a.console.log)}function d(b,c,d){!d[4]&&a._rollbarWrappedError&&(d[4]=a._rollbarWrappedError,a._rollbarWrappedError=null),b.uncaughtError.apply(b,d),c&&c.apply(a,d)}function e(b){var d=c;return g(function(){if(this.notifier)return this.notifier[b].apply(this.notifier,arguments);var c=this,e="scope"===b;e&&(c=new d(this));var f=Array.prototype.slice.call(arguments,0),g={shim:c,method:b,args:f,ts:new Date};return a._rollbarShimQueue.push(g),e?c:void 0})}function f(a,b){if(b.hasOwnProperty&&b.hasOwnProperty("addEventListener")){var c=b.addEventListener;b.addEventListener=function(b,d,e){c.call(this,b,a.wrap(d),e)};var d=b.removeEventListener;b.removeEventListener=function(a,b,c){d.call(this,a,b&&b._wrapped?b._wrapped:b,c)}}}function g(a,b){return b=b||this.logger,function(){try{return a.apply(this,arguments)}catch(c){b("Rollbar internal error:",c)}}}var h=0;c.init=function(a,b){var e=b.globalAlias||"Rollbar";if("object"==typeof a[e])return a[e];a._rollbarShimQueue=[],a._rollbarWrappedError=null,b=b||{};var h=new c;return g(function(){if(h.configure(b),b.captureUncaught){var c=a.onerror;a.onerror=function(){var a=Array.prototype.slice.call(arguments,0);d(h,c,a)};var g,i,j=["EventTarget","Window","Node","ApplicationCache","AudioTrackList","ChannelMergerNode","CryptoOperation","EventSource","FileReader","HTMLUnknownElement","IDBDatabase","IDBRequest","IDBTransaction","KeyOperation","MediaController","MessagePort","ModalWindow","Notification","SVGElementInstance","Screen","TextTrack","TextTrackCue","TextTrackList","WebSocket","WebSocketWorker","Worker","XMLHttpRequest","XMLHttpRequestEventTarget","XMLHttpRequestUpload"];for(g=0;g<j.length;++g)i=j[g],a[i]&&a[i].prototype&&f(h,a[i].prototype)}return a[e]=h,h},h.logger)()},c.prototype.loadFull=function(a,b,c,d){var e=g(function(){var a=b.createElement("script"),e=b.getElementsByTagName("script")[0];a.src=d.rollbarJsUrl,a.async=!c,a.onload=f,e.parentNode.insertBefore(a,e)},this.logger),f=g(function(){if(void 0===a._rollbarPayloadQueue)for(var b,c,d,e,f=new Error("rollbar.js did not load");b=a._rollbarShimQueue.shift();)for(d=b.args,e=0;e<d.length;++e)if(c=d[e],"function"==typeof c){c(f);break}},this.logger);g(function(){c?e():a.addEventListener?a.addEventListener("load",e,!1):a.attachEvent("onload",e)},this.logger)()},c.prototype.wrap=function(b){try{if("function"!=typeof b)return b;if(b._isWrap)return b;if(!b._wrapped){b._wrapped=function(){try{return b.apply(this,arguments)}catch(c){throw a._rollbarWrappedError=c,c}},b._wrapped._isWrap=!0;for(var c in b)b.hasOwnProperty(c)&&(b._wrapped[c]=b[c])}return b._wrapped}catch(d){return b}};for(var i="log,debug,info,warn,warning,error,critical,global,configure,scope,uncaughtError".split(","),j=0;j<i.length;++j)c.prototype[i[j]]=e(i[j]);var k="//d37gvrvc0wt4s1.cloudfront.net/js/v1.1/rollbar.min.js";_rollbarConfig.rollbarJsUrl=_rollbarConfig.rollbarJsUrl||k;var l=c.init(a,_rollbarConfig);l.loadFull(a,b,!1,_rollbarConfig)}(window,document);
47
+ var _rollbarConfig = #{client_settings.to_json};
48
+ </script>
49
+ <script>
50
+ !function(a,b){function c(b){this.shimId=++h,this.notifier=null,this.parentShim=b,this.logger=function(){},a.console&&void 0===a.console.shimId&&(this.logger=a.console.log)}function d(b,c,d){a._rollbarWrappedError&&(d[4]||(d[4]=a._rollbarWrappedError),d[5]||(d[5]=a._rollbarWrappedError._rollbarContext),a._rollbarWrappedError=null),b.uncaughtError.apply(b,d),c&&c.apply(a,d)}function e(b){var d=c;return g(function(){if(this.notifier)return this.notifier[b].apply(this.notifier,arguments);var c=this,e="scope"===b;e&&(c=new d(this));var f=Array.prototype.slice.call(arguments,0),g={shim:c,method:b,args:f,ts:new Date};return a._rollbarShimQueue.push(g),e?c:void 0})}function f(a,b){if(b.hasOwnProperty&&b.hasOwnProperty("addEventListener")){var c=b.addEventListener;b.addEventListener=function(b,d,e){c.call(this,b,a.wrap(d),e)};var d=b.removeEventListener;b.removeEventListener=function(a,b,c){d.call(this,a,b&&b._wrapped?b._wrapped:b,c)}}}function g(a,b){return b=b||this.logger,function(){try{return a.apply(this,arguments)}catch(c){b("Rollbar internal error:",c)}}}var h=0;c.init=function(a,b){var e=b.globalAlias||"Rollbar";if("object"==typeof a[e])return a[e];a._rollbarShimQueue=[],a._rollbarWrappedError=null,b=b||{};var h=new c;return g(function(){if(h.configure(b),b.captureUncaught){var c=a.onerror;a.onerror=function(){var a=Array.prototype.slice.call(arguments,0);d(h,c,a)};var g,i,j="EventTarget,Window,Node,ApplicationCache,AudioTrackList,ChannelMergerNode,CryptoOperation,EventSource,FileReader,HTMLUnknownElement,IDBDatabase,IDBRequest,IDBTransaction,KeyOperation,MediaController,MessagePort,ModalWindow,Notification,SVGElementInstance,Screen,TextTrack,TextTrackCue,TextTrackList,WebSocket,WebSocketWorker,Worker,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload".split(",");for(g=0;g<j.length;++g)i=j[g],a[i]&&a[i].prototype&&f(h,a[i].prototype)}return a[e]=h,h},h.logger)()},c.prototype.loadFull=function(a,b,c,d,e){var f=g(function(){var a=b.createElement("script"),e=b.getElementsByTagName("script")[0];a.src=d.rollbarJsUrl,a.async=!c,a.onload=h,e.parentNode.insertBefore(a,e)},this.logger),h=g(function(){var b;if(void 0===a._rollbarPayloadQueue){var c,d,f,g;for(b=new Error("rollbar.js did not load");c=a._rollbarShimQueue.shift();)for(f=c.args,g=0;g<f.length;++g)if(d=f[g],"function"==typeof d){d(b);break}}"function"==typeof e&&e(b)},this.logger);g(function(){c?f():a.addEventListener?a.addEventListener("load",f,!1):a.attachEvent("onload",f)},this.logger)()},c.prototype.wrap=function(b,c){try{var d;if(d="function"==typeof c?c:function(){return c||{}},"function"!=typeof b)return b;if(b._isWrap)return b;if(!b._wrapped){b._wrapped=function(){try{return b.apply(this,arguments)}catch(c){throw c._rollbarContext=d(),c._rollbarContext._wrappedSource=b.toString(),a._rollbarWrappedError=c,c}},b._wrapped._isWrap=!0;for(var e in b)b.hasOwnProperty(e)&&(b._wrapped[e]=b[e])}return b._wrapped}catch(f){return b}};for(var i="log,debug,info,warn,warning,error,critical,global,configure,scope,uncaughtError".split(","),j=0;j<i.length;++j)c.prototype[i[j]]=e(i[j]);var k="//d37gvrvc0wt4s1.cloudfront.net/js/v1.1/rollbar.min.js";_rollbarConfig.rollbarJsUrl=_rollbarConfig.rollbarJsUrl||k;var l=c.init(a,_rollbarConfig);l.loadFull(a,b,!1,_rollbarConfig)}(window,document);
53
51
  </script>
54
52
  JS
55
53
  end
@@ -65,5 +63,16 @@ module SmokeDetector::Providers
65
63
  ::Rollbar.report_exception(exception, rollbar_request_data, rollbar_person_data)
66
64
  end
67
65
  end
66
+
67
+ private
68
+ def migrate_old_client_setting_syntax(settings)
69
+ return unless settings.present?
70
+ whitelist = settings.delete(:host_whitelist)
71
+ ignored_msgs = settings.delete(:ignored_messages)
72
+
73
+ settings[:hostWhiteList] = whitelist if whitelist
74
+ settings[:ignoredMessages] = ignored_msgs if ignored_msgs
75
+ settings
76
+ end
68
77
  end
69
78
  end
@@ -1,3 +1,3 @@
1
1
  module SmokeDetector
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end