vx-instrumentation 0.1.1 → 0.1.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e38ae361a2d539a48365d64eaeb9cc905934c7b
|
4
|
+
data.tar.gz: 8eb4ea7ba4eacceb47cda77958dc1e4f4f3919c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a836d117ec05ce5200a9093ee69ad74d0e16cd86ac8e9109f6a3f14636e81721566e961a74ace09274959340ee62cabe9acd33827943046a374c5b4fce53ac4e
|
7
|
+
data.tar.gz: 3649718e03c7c01187f0553634da00ebae0965df4c2db2658587ce3585e1bcebcf2eb0b018a9a06d53b94c953b8ce792eb737faa83ca92f3081950769b6afbf4
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Vx
|
2
|
+
module Instrumentation
|
3
|
+
module Rack
|
4
|
+
|
5
|
+
HandleExceptionsMiddleware = Struct.new(:app) do
|
6
|
+
|
7
|
+
IGNORED_EXCEPTIONS = %w{
|
8
|
+
ActionController::RoutingError
|
9
|
+
}
|
10
|
+
|
11
|
+
def clean_env(env)
|
12
|
+
env = env.select{|k,v| k !~ /^(action_dispatch|puma|session|rack\.session|action_controller)/ }
|
13
|
+
env['HTTP_COOKIE'] &&= env['HTTP_COOKIE'].scan(/.{80}/).join("\n")
|
14
|
+
env
|
15
|
+
end
|
16
|
+
|
17
|
+
def notify(exception, env)
|
18
|
+
unless ignore?(exception)
|
19
|
+
Vx::Instrumentation.handle_exception(
|
20
|
+
'handle_exception.rack',
|
21
|
+
exception,
|
22
|
+
clean_env(env)
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def call(env)
|
28
|
+
begin
|
29
|
+
response = app.call(env)
|
30
|
+
rescue Exception => ex
|
31
|
+
notify ex, env
|
32
|
+
raise ex
|
33
|
+
end
|
34
|
+
|
35
|
+
if ex = framework_exception(env)
|
36
|
+
notify ex, env
|
37
|
+
end
|
38
|
+
|
39
|
+
response
|
40
|
+
end
|
41
|
+
|
42
|
+
def framework_exception(env)
|
43
|
+
env['rack.exception'] || env['action_dispatch.exception']
|
44
|
+
end
|
45
|
+
|
46
|
+
def ignore?(ex)
|
47
|
+
IGNORED_EXCEPTIONS.include? ex.class.name
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/vx/instrumentation.rb
CHANGED
@@ -2,13 +2,12 @@ require 'thread'
|
|
2
2
|
|
3
3
|
require File.expand_path("../instrumentation/version", __FILE__)
|
4
4
|
require File.expand_path("../instrumentation/logger", __FILE__)
|
5
|
-
require File.expand_path("../instrumentation/airbrake", __FILE__)
|
6
5
|
require File.expand_path("../instrumentation/stderr", __FILE__)
|
6
|
+
require File.expand_path("../instrumentation/rack/handle_exceptions_middleware", __FILE__)
|
7
7
|
|
8
8
|
module Vx
|
9
9
|
module Instrumentation
|
10
10
|
|
11
|
-
extend Airbrake
|
12
11
|
extend Stderr
|
13
12
|
|
14
13
|
DATE_FORMAT = '%Y-%m-%dT%H:%M:%S.%N%z'
|
@@ -54,9 +53,7 @@ module Vx
|
|
54
53
|
}
|
55
54
|
|
56
55
|
notify_stderr(ex)
|
57
|
-
|
58
56
|
Vx::Instrumentation::Logger.logger.error(payload)
|
59
|
-
notify_airbrake(ex, env)
|
60
57
|
end
|
61
58
|
|
62
59
|
def delivery(name, payload, tags, started, finished)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vx::Instrumentation::Rack::HandleExceptionsMiddleware do
|
4
|
+
let(:env) { {} }
|
5
|
+
let(:app) { ->(e){ e.merge(foo: :bar) } }
|
6
|
+
let(:output) { StringIO.new }
|
7
|
+
let(:middleware) { described_class.new(app) }
|
8
|
+
let(:result) {
|
9
|
+
output.rewind
|
10
|
+
c = output.read
|
11
|
+
if c.to_s != ""
|
12
|
+
JSON.parse c
|
13
|
+
end
|
14
|
+
}
|
15
|
+
|
16
|
+
before do
|
17
|
+
Vx::Instrumentation::Logger.setup output
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should work when no exceptions raised" do
|
21
|
+
expect(middleware.call(env)).to eq(foo: :bar)
|
22
|
+
expect(result).to be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should catch raised exception" do
|
26
|
+
app = ->(_) { raise RuntimeError, "Ignore Me" }
|
27
|
+
mid = described_class.new(app)
|
28
|
+
expect{ mid.call(env) }.to raise_error(RuntimeError, 'Ignore Me')
|
29
|
+
|
30
|
+
expect(result["@tags"]).to eq ["handle_exception", "rack", "exception"]
|
31
|
+
expect(result["@event"]).to eq 'handle_exception.rack'
|
32
|
+
expect(result['exception']).to eq 'RuntimeError'
|
33
|
+
expect(result['message']).to eq 'Ignore Me'
|
34
|
+
expect(result['backtrace']).to_not be_empty
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vx-instrumentation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Galinsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -81,12 +81,13 @@ files:
|
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
83
|
- lib/vx/instrumentation.rb
|
84
|
-
- lib/vx/instrumentation/airbrake.rb
|
85
84
|
- lib/vx/instrumentation/logger.rb
|
85
|
+
- lib/vx/instrumentation/rack/handle_exceptions_middleware.rb
|
86
86
|
- lib/vx/instrumentation/stderr.rb
|
87
87
|
- lib/vx/instrumentation/version.rb
|
88
88
|
- spec/lib/instrumentation_spec.rb
|
89
89
|
- spec/lib/logger_spec.rb
|
90
|
+
- spec/lib/rack/handle_exceptions_middleware_spec.rb
|
90
91
|
- spec/spec_helper.rb
|
91
92
|
- vx-instrumentation.gemspec
|
92
93
|
homepage: ''
|
@@ -109,12 +110,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
110
|
version: '0'
|
110
111
|
requirements: []
|
111
112
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.2.2
|
113
114
|
signing_key:
|
114
115
|
specification_version: 4
|
115
116
|
summary: summary
|
116
117
|
test_files:
|
117
118
|
- spec/lib/instrumentation_spec.rb
|
118
119
|
- spec/lib/logger_spec.rb
|
120
|
+
- spec/lib/rack/handle_exceptions_middleware_spec.rb
|
119
121
|
- spec/spec_helper.rb
|
120
122
|
has_rdoc:
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'airbrake'
|
2
|
-
|
3
|
-
Airbrake.configure do |config|
|
4
|
-
if ENV['AIRBRAKE_API_KEY']
|
5
|
-
$stdout.puts ' --> initializing Airbrake'
|
6
|
-
|
7
|
-
config.api_key = ENV['AIRBRAKE_API_KEY']
|
8
|
-
config.host = ENV['AIRBRAKE_HOST']
|
9
|
-
config.port = ENV['AIRBRAKE_PORT'] || 80
|
10
|
-
config.secure = config.port == 443
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module Vx
|
15
|
-
module Instrumentation
|
16
|
-
module Airbrake
|
17
|
-
|
18
|
-
def notify_airbrake(ex, env)
|
19
|
-
::Airbrake.notify ex, env
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|