wat_catcher 0.10.8 → 0.10.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 070f613f1ee147040280aa28a22e2fcfb989f5d7
4
- data.tar.gz: eb7f3a5b2bc60730da99376d3b03277317488d44
3
+ metadata.gz: 712be060f30a0d18b0801b6dfdcfff48fe5bde00
4
+ data.tar.gz: df3885aed59be97cb8136995ee4558baf571d704
5
5
  SHA512:
6
- metadata.gz: c06265056133d54901ef3a8be4e6fe68658be835ae079006b770113bd363a069b009b9e252385376ca1e7c1802df99e2f9cbcec68e839ad94a15ae0d0d230267
7
- data.tar.gz: 07462e84a3dc28252f4fa13473c9a20596a82d3ec7d3256611cb508bd2eb6c0831b7f6ad321180b4cc1abe20f66082df7274f641a478b1990ce413331dd693a7
6
+ metadata.gz: 79380328041b6d62094cf628aec75d91a937914cf10b4f9eb387b5ecc735041f411e856579db6f1abc1277761840972e7e941d2549d484874188d226c72a8985
7
+ data.tar.gz: 9e9f68302a48c01e6082ffb2011f788f47c906ff237cdbbecfed4b288f9c47897d8ddc86ad92771276b0115cca3a75f0426f752e5f66ffc309713f2e29d0cf43
data/Gemfile.lock CHANGED
@@ -1,10 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wat_catcher (0.10.8)
4
+ wat_catcher (0.10.9)
5
5
  coffee-rails
6
6
  httpclient
7
7
  rails (>= 4.2.0)
8
+ statsd-ruby
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
@@ -76,7 +77,7 @@ GEM
76
77
  guard (>= 2.1.0)
77
78
  guard-compat (~> 1.1)
78
79
  guard-compat (1.2.1)
79
- httpclient (2.8.2.4)
80
+ httpclient (2.8.3)
80
81
  i18n (0.7.0)
81
82
  jasmine (2.4.0)
82
83
  jasmine-core (~> 2.4)
@@ -173,6 +174,7 @@ GEM
173
174
  activesupport (>= 4.0)
174
175
  sprockets (>= 3.0.0)
175
176
  sqlite3 (1.3.11)
177
+ statsd-ruby (1.3.0)
176
178
  thor (0.19.4)
177
179
  thread_safe (0.3.5)
178
180
  tzinfo (1.2.2)
data/README.md CHANGED
@@ -66,6 +66,32 @@ YourApp::Application.configure do
66
66
  end
67
67
  ```
68
68
 
69
+ #### Adding Telemetry
70
+ In `config/wat_catcher.yml`:
71
+
72
+ ```yml
73
+ production: &default
74
+ statsd_host: statsd.service.consul
75
+ statsd_port: 9125
76
+ metrics_disabled: false # defaults to true
77
+ ```
78
+
79
+ Alternatively, this can be configured in `config/application.rb` or environment file (e.g. `config/environments/production.rb`).
80
+ ```ruby
81
+ module YourApp
82
+ class Application < Rails::Application
83
+ WatCatcher.configuration.statsd_host = "statsd.service.consul"
84
+ WatCatcher.configuration.statsd_port = 9125
85
+ WatCatcher.configuration.metrics_disabled = false
86
+ end
87
+ end
88
+ ```
89
+
90
+ ```ruby
91
+ YourApp::Application.configure do
92
+ WatCatcher.configuration.metrics_disabled = false
93
+ end
94
+ ```
69
95
 
70
96
  ### Mount the engine in your app for javascript errors
71
97
  To get around cross-origin issues, an engine was created that accepts POSTs of client exceptions and puts a sidekiq
data/lib/wat_catcher.rb CHANGED
@@ -1,5 +1,7 @@
1
+ require 'statsd'
1
2
  require "wat_catcher/version"
2
3
 
4
+ require "wat_catcher/metrics"
3
5
  require "wat_catcher/report"
4
6
  require "wat_catcher/poster"
5
7
  require "wat_catcher/wattle_helper"
@@ -0,0 +1,29 @@
1
+ module WatCatcher
2
+ class Metrics
3
+ attr_writer :host, :port
4
+
5
+ def host
6
+ @host ||= 'localhost'
7
+ end
8
+
9
+ def port
10
+ @port ||= 9125
11
+ end
12
+
13
+ def client
14
+ ::Statsd.new @host, @port
15
+ end
16
+
17
+ def increment(metric, sample_rate=1)
18
+ client.increment metric, sample_rate
19
+ end
20
+
21
+ def decrement(metric, sample_rate=1)
22
+ client.increment metric, sample_rate
23
+ end
24
+
25
+ def set(metric, value, sample_rate=1)
26
+ client.set metric, value, sample_rate
27
+ end
28
+ end
29
+ end
@@ -9,6 +9,7 @@ module WatCatcher
9
9
  self.user = user
10
10
  send_report
11
11
  log_report
12
+ instrument_report unless metrics_disabled?
12
13
  end
13
14
 
14
15
  def send_report
@@ -21,6 +22,38 @@ module WatCatcher
21
22
  Rails.logger.error( "WatCatcher::error: " + base_description.tap {|x| x.delete(:rails_root) }.to_json )
22
23
  end
23
24
 
25
+ def metrics_disabled?
26
+ WatCatcher.configuration.metrics_disabled = true if WatCatcher.configuration.metrics_disabled.nil?
27
+ WatCatcher.configuration.metrics_disabled
28
+ end
29
+
30
+ def metrics_reporter
31
+ @reporter ||= ::WatCatcher::Metrics.new
32
+ @reporter.host = WatCatcher.configuration.statsd_host
33
+ @reporter.port = WatCatcher.configuration.statsd_port
34
+
35
+ @reporter
36
+ end
37
+
38
+ def metrics_namespace
39
+ "#{base_description[:app_name]}.#{base_description[:app_env]}".downcase
40
+ end
41
+
42
+ def instrument_report
43
+ return if WatCatcher.configuration.disabled
44
+
45
+ # increment graphite counter, ':' is used to seperate metric from metric value -- therefore, replace ':' with '_'
46
+ # e.g. kairos.staging.exceptions.NoMethodError.frequency is count of `NoMethodError`s during sample period (60s)
47
+ #
48
+ # for application-aggregated
49
+ metrics_reporter.increment "#{metrics_namespace}.wat.#{exception_description[:error_class].gsub ':', '_'}.frequency"
50
+ # for server-aggregated
51
+ metrics_reporter.increment "#{metrics_namespace}.#{base_description[:hostname]}.wat.#{exception_description[:error_class].gsub ':', '_'}.frequency"
52
+
53
+ # emit an event that an exception was raised
54
+ metrics_reporter.set "#{metrics_namespace}.#{base_description[:hostname]}.wat.#{base_description[:error_class]}.occurance", base_description[:captured_at]
55
+ end
56
+
24
57
  def params
25
58
  { wat: base_description
26
59
  .merge(user_description)
@@ -1,3 +1,3 @@
1
1
  module WatCatcher
2
- VERSION = "0.10.8"
2
+ VERSION = "0.10.9"
3
3
  end
data/wat_catcher.gemspec CHANGED
@@ -30,4 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_runtime_dependency 'coffee-rails'
31
31
  spec.add_runtime_dependency 'rails', '>= 4.2.0'
32
32
  spec.add_runtime_dependency 'httpclient'
33
+ spec.add_runtime_dependency 'statsd-ruby'
33
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wat_catcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.8
4
+ version: 0.10.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Constantine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-06 00:00:00.000000000 Z
11
+ date: 2017-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: statsd-ruby
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  description: Catch your wats
168
182
  email:
169
183
  - cconstan@gmail.com
@@ -186,6 +200,7 @@ files:
186
200
  - config/routes.rb
187
201
  - lib/wat_catcher.rb
188
202
  - lib/wat_catcher/engine.rb
203
+ - lib/wat_catcher/metrics.rb
189
204
  - lib/wat_catcher/poster.rb
190
205
  - lib/wat_catcher/rack_middleware.rb
191
206
  - lib/wat_catcher/railtie.rb