rails_riemann_middleware 0.6.0 → 0.7.0
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 +7 -0
- data/README.md +29 -1
- data/lib/rails_riemann_middleware/duration.rb +4 -3
- data/lib/rails_riemann_middleware/exception_notification.rb +4 -3
- data/lib/rails_riemann_middleware/headers.rb +4 -3
- data/lib/rails_riemann_middleware/rails_exception_notifier.rb +25 -0
- data/lib/rails_riemann_middleware/version.rb +1 -1
- data/lib/rails_riemann_middleware.rb +3 -15
- data/specs/{notifier_spec.rb → rails_exception_notifier_spec.rb} +22 -3
- metadata +15 -13
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5c54c3065cac2c767f26a82c65b1b2e2aba85dd0
|
4
|
+
data.tar.gz: 205f6789a8724cfd452fde70c767cee6f48aaa2f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2f894756e9f09ee625ef4f2f77d950568b6ae2765153da66e3189f11e8d147e13eb55d867a005766020b0e2cfcb10bfb9fddcc7c231fa18eb41616d7800aa66b
|
7
|
+
data.tar.gz: 2f68c002683ccfe1d398575e3d01b80efc8a8fe139795341c08fca367ff187e6f2ca1f8f2d947e917ce4ae81c6fcd5ce82ebfd7a598aedfb3d6b53f80d4483fd
|
data/README.md
CHANGED
@@ -22,8 +22,36 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
Add the following to your specific rails enviroment.
|
24
24
|
|
25
|
+
config.riemann_options = (:riemann_host => "riemann_host_name")
|
26
|
+
|
25
27
|
config.middleware.use(RailsRiemannMiddleware::Notifier,
|
26
|
-
|
28
|
+
config.riemann_options)
|
29
|
+
|
30
|
+
If you would like to pull custom headers out of the env for reporting,
|
31
|
+
you can add
|
32
|
+
|
33
|
+
:additional_headers => ['SOME_HEADER', 'SOME_OTHER_HEADER']
|
34
|
+
|
35
|
+
Those will be reported for both exceptions and duration events. If the
|
36
|
+
header is not defined, it will be reported as 'N/A'.
|
37
|
+
|
38
|
+
## ExceptionNotification 3.x API
|
39
|
+
|
40
|
+
If you, like us, are transitioning from the exception\_notification gem,
|
41
|
+
we support the API from the 3.x version of that gem for explicit calls
|
42
|
+
to the exception notifier. For example, if you are catching exceptions in
|
43
|
+
your controllers (preventing them from bubbling up automatically), you can
|
44
|
+
call:
|
45
|
+
|
46
|
+
RailsRiemannMiddleware::RailsExceptionNotifier.exception_notification(env, error)
|
47
|
+
|
48
|
+
In your models or other background processes, you can call:
|
49
|
+
|
50
|
+
RailsRiemannMiddleware::RailsExceptionNotifier.background_exception_notification(error)
|
51
|
+
|
52
|
+
To use this extra functionality, you have to
|
53
|
+
|
54
|
+
require 'rails_riemann_middleware/rails_exception_notifier'
|
27
55
|
|
28
56
|
## Running Tests
|
29
57
|
|
@@ -3,10 +3,11 @@ require "rails_riemann_middleware/headers"
|
|
3
3
|
module RailsRiemannMiddleware
|
4
4
|
|
5
5
|
class Duration
|
6
|
-
attr_reader :event, :env, :start_time
|
6
|
+
attr_reader :event, :env, :start_time, :headers
|
7
7
|
|
8
|
-
def initialize(event, env, start_time)
|
8
|
+
def initialize(event, env, start_time, options={})
|
9
9
|
@event, @env, @start_time = event, env, start_time
|
10
|
+
@headers = options.fetch(:headers, [])
|
10
11
|
end
|
11
12
|
|
12
13
|
def send
|
@@ -22,7 +23,7 @@ module RailsRiemannMiddleware
|
|
22
23
|
:state => 'info',
|
23
24
|
:metric => duration,
|
24
25
|
:tags => ["duration"],
|
25
|
-
:description => Headers.new(env).to_s
|
26
|
+
:description => Headers.new(env, headers).to_s
|
26
27
|
}
|
27
28
|
msg
|
28
29
|
end
|
@@ -3,10 +3,11 @@ require "rails_riemann_middleware/headers"
|
|
3
3
|
module RailsRiemannMiddleware
|
4
4
|
|
5
5
|
class ExceptionNotification
|
6
|
-
attr_reader :event, :env, :exception
|
6
|
+
attr_reader :event, :env, :exception, :headers
|
7
7
|
|
8
|
-
def initialize(event, env, exception)
|
8
|
+
def initialize(event, env, exception, options={})
|
9
9
|
@event, @env, @exception = event, env, exception
|
10
|
+
@headers = options.fetch(:headers, [])
|
10
11
|
end
|
11
12
|
|
12
13
|
def send
|
@@ -34,7 +35,7 @@ module RailsRiemannMiddleware
|
|
34
35
|
def backtrace
|
35
36
|
e = ["#{exception.to_s}"]
|
36
37
|
e << "----------------------------------------"
|
37
|
-
e += Headers.new(env).to_a
|
38
|
+
e += Headers.new(env, headers).to_a
|
38
39
|
e << "----------------------------------------\n"
|
39
40
|
e += exception.backtrace
|
40
41
|
e.join("\n")[0..8000]
|
@@ -2,14 +2,15 @@ module RailsRiemannMiddleware
|
|
2
2
|
|
3
3
|
class Headers
|
4
4
|
|
5
|
-
attr_reader :env
|
5
|
+
attr_reader :env, :custom_headers
|
6
6
|
|
7
|
-
def initialize(env)
|
7
|
+
def initialize(env, custom_headers=[])
|
8
8
|
@env = env
|
9
|
+
@custom_headers = custom_headers
|
9
10
|
end
|
10
11
|
|
11
12
|
def keys
|
12
|
-
%w{REQUEST_METHOD REQUEST_URI PATH_INFO HTTP_X_REAL_IP HTTP_USER_AGENT HTTP_REFERER}
|
13
|
+
%w{REQUEST_METHOD REQUEST_URI PATH_INFO HTTP_X_REAL_IP HTTP_USER_AGENT HTTP_REFERER} + custom_headers
|
13
14
|
end
|
14
15
|
|
15
16
|
def to_a
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RailsRiemannMiddleware
|
2
|
+
class RailsExceptionNotifier
|
3
|
+
def self.exception_notification(env, exception, options={})
|
4
|
+
app = options.fetch(:app) {Rails.application}
|
5
|
+
options = app.config.riemann_options.merge(options)
|
6
|
+
headers = options.delete(:additional_headers)
|
7
|
+
|
8
|
+
event = Event.new(options)
|
9
|
+
|
10
|
+
ExceptionNotification.new(event, env, exception,
|
11
|
+
headers: headers)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.background_exception_notification(exception, options={})
|
15
|
+
app = options.fetch(:app) {Rails.application}
|
16
|
+
options = app.config.riemann_options.merge(options)
|
17
|
+
headers = options.delete(:additional_headers)
|
18
|
+
|
19
|
+
event = Event.new(options)
|
20
|
+
env = {}
|
21
|
+
|
22
|
+
ExceptionNotification.new(event, env, exception)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -6,7 +6,7 @@ require "rails_riemann_middleware/exception_notification"
|
|
6
6
|
module RailsRiemannMiddleware
|
7
7
|
|
8
8
|
class Notifier
|
9
|
-
attr_reader :event, :send_durations, :send_exceptions
|
9
|
+
attr_reader :event, :send_durations, :send_exceptions, :options
|
10
10
|
|
11
11
|
def initialize(app, options = {})
|
12
12
|
@app, @options = app, options
|
@@ -19,22 +19,10 @@ module RailsRiemannMiddleware
|
|
19
19
|
start_time = Time.now
|
20
20
|
@app.call(env)
|
21
21
|
rescue Exception => exception
|
22
|
-
ExceptionNotification.new(event, env, exception).send if send_exceptions
|
22
|
+
ExceptionNotification.new(event, env, exception, options).send if send_exceptions
|
23
23
|
raise exception
|
24
24
|
ensure
|
25
|
-
Duration.new(event, env, start_time).send if send_durations
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.exception_notification(env, exception)
|
29
|
-
event = Event.new
|
30
|
-
ExceptionNotification.new(event, env, exception)
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.background_exception_notification(exception)
|
34
|
-
event = Event.new
|
35
|
-
env = {}
|
36
|
-
ExceptionNotification.new(event, env, exception)
|
25
|
+
Duration.new(event, env, start_time, options).send if send_durations
|
37
26
|
end
|
38
27
|
end
|
39
|
-
|
40
28
|
end
|
@@ -1,8 +1,27 @@
|
|
1
1
|
require_relative 'spec_helper'
|
2
2
|
require 'rails_riemann_middleware'
|
3
|
+
require 'rails_riemann_middleware/rails_exception_notifier'
|
4
|
+
|
5
|
+
class DummyAppConfig
|
6
|
+
def riemann_options
|
7
|
+
{}
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class DummyApplication
|
12
|
+
def config
|
13
|
+
DummyAppConfig.new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module Rails
|
18
|
+
def self.application
|
19
|
+
DummyApplication.new
|
20
|
+
end
|
21
|
+
end
|
3
22
|
|
4
23
|
module RailsRiemannMiddleware
|
5
|
-
describe
|
24
|
+
describe RailsExceptionNotifier do
|
6
25
|
let(:exception_notification_new) { MiniTest::Mock.new }
|
7
26
|
let(:error) { Object.new }
|
8
27
|
|
@@ -15,7 +34,7 @@ module RailsRiemannMiddleware
|
|
15
34
|
end
|
16
35
|
|
17
36
|
ExceptionNotification.stub(:new, exception_notification_new) do
|
18
|
-
|
37
|
+
RailsExceptionNotifier.exception_notification(env, error)
|
19
38
|
end
|
20
39
|
exception_notification_new.verify
|
21
40
|
end
|
@@ -28,7 +47,7 @@ module RailsRiemannMiddleware
|
|
28
47
|
end
|
29
48
|
|
30
49
|
ExceptionNotification.stub(:new, exception_notification_new) do
|
31
|
-
|
50
|
+
RailsExceptionNotifier.background_exception_notification(error)
|
32
51
|
end
|
33
52
|
exception_notification_new.verify
|
34
53
|
end
|
metadata
CHANGED
@@ -1,27 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_riemann_middleware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.7.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Richard Outten
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-04-21 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: riemann-client
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 0.2.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.0
|
25
27
|
description: Rack middleware for sending data to riemann
|
26
28
|
email:
|
27
29
|
- outtenr@gmail.com
|
@@ -39,36 +41,36 @@ files:
|
|
39
41
|
- lib/rails_riemann_middleware/event.rb
|
40
42
|
- lib/rails_riemann_middleware/exception_notification.rb
|
41
43
|
- lib/rails_riemann_middleware/headers.rb
|
44
|
+
- lib/rails_riemann_middleware/rails_exception_notifier.rb
|
42
45
|
- lib/rails_riemann_middleware/version.rb
|
43
46
|
- rails_riemann_middleware.gemspec
|
44
47
|
- specs/duration_spec.rb
|
45
48
|
- specs/exception_notification_spec.rb
|
46
|
-
- specs/
|
49
|
+
- specs/rails_exception_notifier_spec.rb
|
47
50
|
- specs/spec_helper.rb
|
48
51
|
homepage: ''
|
49
52
|
licenses:
|
50
53
|
- MIT
|
54
|
+
metadata: {}
|
51
55
|
post_install_message:
|
52
56
|
rdoc_options: []
|
53
57
|
require_paths:
|
54
58
|
- lib
|
55
59
|
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
60
|
requirements:
|
58
|
-
- -
|
61
|
+
- - '>='
|
59
62
|
- !ruby/object:Gem::Version
|
60
63
|
version: '0'
|
61
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
-
none: false
|
63
65
|
requirements:
|
64
|
-
- -
|
66
|
+
- - '>='
|
65
67
|
- !ruby/object:Gem::Version
|
66
68
|
version: '0'
|
67
69
|
requirements: []
|
68
70
|
rubyforge_project:
|
69
|
-
rubygems_version:
|
71
|
+
rubygems_version: 2.0.3
|
70
72
|
signing_key:
|
71
|
-
specification_version:
|
73
|
+
specification_version: 4
|
72
74
|
summary: Rack middleware for sending data to riemann
|
73
75
|
test_files: []
|
74
76
|
has_rdoc:
|