vx-instrumentation 0.0.8 → 0.1.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 +4 -4
- data/lib/vx/instrumentation/airbrake.rb +24 -0
- data/lib/vx/instrumentation/logger.rb +2 -3
- data/lib/vx/instrumentation/version.rb +1 -1
- data/lib/vx/instrumentation.rb +7 -15
- data/vx-instrumentation.gemspec +1 -0
- metadata +17 -9
- data/lib/vx/instrumentation/action_dispatch.rb +0 -23
- data/lib/vx/instrumentation/active_record.rb +0 -33
- data/lib/vx/instrumentation/amqp_consumer.rb +0 -9
- data/lib/vx/instrumentation/faraday.rb +0 -31
- data/lib/vx/instrumentation/rails.rb +0 -9
- data/lib/vx/instrumentation/subscriber.rb +0 -33
- data/lib/vx/instrumentation/worker.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40c7266e5a8ccd0a4ebfa9ac92855c007a866e60
|
4
|
+
data.tar.gz: cc745d13d1d3290c3fcdb88b0a85be2f5c6662f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a039d63e7b290a1cde70cc63b47ddb46c4d6833926786d331893b1e0b752cafb2f2466c68ff16aa30f035e8b57a624026db0af55b53d6c5cb02ba7a46abdbbc0
|
7
|
+
data.tar.gz: 32720993fd5304a49b0387e35474886d2f513367d873d7b2eeb299dfd26d9123157f40564d0e6860bd7fbd6d1aa41412241cf0f8e9f9f957ded51aea72d62ab4
|
@@ -0,0 +1,24 @@
|
|
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
|
@@ -17,8 +17,8 @@ module Vx
|
|
17
17
|
begin
|
18
18
|
@device.send(sym, *args, &block)
|
19
19
|
rescue Exception => e
|
20
|
-
$stderr.puts "#{e.class.to_s}
|
21
|
-
$stderr.puts e.backtrace.map{|b| "
|
20
|
+
$stderr.puts "#{e.class.to_s}, #{e.message.inspect} [#{sym.inspect} #{args.inspect}]"
|
21
|
+
$stderr.puts e.backtrace.map{|b| "\t#{b}" }.join("\n")
|
22
22
|
end
|
23
23
|
else
|
24
24
|
super
|
@@ -35,7 +35,6 @@ module Vx
|
|
35
35
|
def setup(target)
|
36
36
|
log = ::Logger.new(target)
|
37
37
|
log.formatter = Formatter
|
38
|
-
$stdout.puts " --> #{self.to_s} to #{target}"
|
39
38
|
@logger = new(log)
|
40
39
|
end
|
41
40
|
end
|
data/lib/vx/instrumentation.rb
CHANGED
@@ -1,31 +1,23 @@
|
|
1
1
|
require 'thread'
|
2
2
|
|
3
|
-
require File.expand_path("../instrumentation/version",
|
4
|
-
require File.expand_path("../instrumentation/logger",
|
5
|
-
require File.expand_path("../instrumentation/
|
6
|
-
|
7
|
-
require File.expand_path("../instrumentation/faraday", __FILE__)
|
8
|
-
require File.expand_path("../instrumentation/active_record", __FILE__)
|
9
|
-
require File.expand_path("../instrumentation/action_dispatch", __FILE__)
|
10
|
-
require File.expand_path("../instrumentation/rails", __FILE__)
|
11
|
-
require File.expand_path("../instrumentation/amqp_consumer", __FILE__)
|
12
|
-
require File.expand_path("../instrumentation/worker", __FILE__)
|
3
|
+
require File.expand_path("../instrumentation/version", __FILE__)
|
4
|
+
require File.expand_path("../instrumentation/logger", __FILE__)
|
5
|
+
require File.expand_path("../instrumentation/airbrake", __FILE__)
|
13
6
|
|
14
7
|
module Vx
|
15
8
|
module Instrumentation
|
16
9
|
|
10
|
+
extend Airbrake
|
11
|
+
|
17
12
|
DATE_FORMAT = '%Y-%m-%dT%H:%M:%S.%N%z'
|
18
13
|
THREAD_KEY = 'vx_instrumentation_keys'
|
19
14
|
|
20
15
|
extend self
|
21
16
|
|
22
17
|
def install(target, log_level = 0)
|
18
|
+
$stdout.puts " --> initializing Vx::Instrumentation, log stored in #{target}"
|
23
19
|
Instrumentation::Logger.setup target
|
24
20
|
Instrumentation::Logger.logger.level = log_level
|
25
|
-
ObjectSpace.each_object(Class) do |c|
|
26
|
-
next unless c.superclass == Instrumentation::Subscriber
|
27
|
-
c.install
|
28
|
-
end
|
29
21
|
end
|
30
22
|
|
31
23
|
def with(new_keys)
|
@@ -59,6 +51,7 @@ module Vx
|
|
59
51
|
backtrace: (ex.backtrace || []).map(&:to_s).join("\n"),
|
60
52
|
}
|
61
53
|
Vx::Instrumentation::Logger.logger.error(payload)
|
54
|
+
notify_airbrake(ex, env)
|
62
55
|
end
|
63
56
|
|
64
57
|
def delivery(name, payload, tags, started, finished)
|
@@ -73,7 +66,6 @@ module Vx
|
|
73
66
|
"@tags" => tags
|
74
67
|
)
|
75
68
|
end
|
76
|
-
|
77
69
|
end
|
78
70
|
|
79
71
|
end
|
data/vx-instrumentation.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_runtime_dependency 'activesupport', '~> 4.0'
|
22
|
+
spec.add_runtime_dependency 'airbrake'
|
22
23
|
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.5"
|
24
25
|
spec.add_development_dependency "rake"
|
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.0
|
4
|
+
version: 0.1.0
|
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-02-
|
11
|
+
date: 2014-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: airbrake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,15 +81,9 @@ files:
|
|
67
81
|
- README.md
|
68
82
|
- Rakefile
|
69
83
|
- lib/vx/instrumentation.rb
|
70
|
-
- lib/vx/instrumentation/
|
71
|
-
- lib/vx/instrumentation/active_record.rb
|
72
|
-
- lib/vx/instrumentation/amqp_consumer.rb
|
73
|
-
- lib/vx/instrumentation/faraday.rb
|
84
|
+
- lib/vx/instrumentation/airbrake.rb
|
74
85
|
- lib/vx/instrumentation/logger.rb
|
75
|
-
- lib/vx/instrumentation/rails.rb
|
76
|
-
- lib/vx/instrumentation/subscriber.rb
|
77
86
|
- lib/vx/instrumentation/version.rb
|
78
|
-
- lib/vx/instrumentation/worker.rb
|
79
87
|
- spec/lib/instrumentation_spec.rb
|
80
88
|
- spec/lib/logger_spec.rb
|
81
89
|
- spec/spec_helper.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'pp'
|
2
|
-
|
3
|
-
module Vx
|
4
|
-
module Instrumentation
|
5
|
-
class ActionDispatch < Subscriber
|
6
|
-
|
7
|
-
event(/\.action_dispatch$/)
|
8
|
-
|
9
|
-
def process
|
10
|
-
req = payload.delete(:request)
|
11
|
-
self.payload = {
|
12
|
-
path: req.fullpath,
|
13
|
-
ip: req.remote_ip,
|
14
|
-
method: req.method,
|
15
|
-
referer: req.referer,
|
16
|
-
content_length: req.content_length,
|
17
|
-
user_agent: req.user_agent
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Vx
|
2
|
-
module Instrumentation
|
3
|
-
class ActiveRecord < Subscriber
|
4
|
-
|
5
|
-
event(/\.active_record$/)
|
6
|
-
|
7
|
-
def process
|
8
|
-
self.payload = {
|
9
|
-
sql: payload[:sql].gsub("\n", ' ').gsub(/ +/, ' ').strip,
|
10
|
-
binds: render_binds,
|
11
|
-
name: payload[:name],
|
12
|
-
duration: payload[:duration]
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def render_binds
|
19
|
-
(payload[:binds] || []).map do |column, value|
|
20
|
-
if column
|
21
|
-
if column.binary?
|
22
|
-
value = "<#{value.bytesize} bytes of binary data>"
|
23
|
-
end
|
24
|
-
[column.name, value]
|
25
|
-
else
|
26
|
-
[nil, value]
|
27
|
-
end
|
28
|
-
end.inspect
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Vx
|
2
|
-
module Instrumentation
|
3
|
-
class Faraday < Subscriber
|
4
|
-
|
5
|
-
event 'request.faraday'
|
6
|
-
|
7
|
-
def process
|
8
|
-
self.name = 'request.http'
|
9
|
-
self.payload = {
|
10
|
-
method: payload[:method],
|
11
|
-
url: payload[:url].to_s,
|
12
|
-
status: payload[:status],
|
13
|
-
response_headers: render_http_header(payload[:response_headers]),
|
14
|
-
request_headers: render_http_header(payload[:request_headers])
|
15
|
-
}
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def render_http_header(headers)
|
21
|
-
headers.map do |key,value|
|
22
|
-
if %{ PRIVATE-TOKEN Authorization }.include?(key)
|
23
|
-
value = value.gsub(/./, "*")
|
24
|
-
end
|
25
|
-
"#{key}: #{value}"
|
26
|
-
end.join("\n")
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
require 'active_support/notifications'
|
3
|
-
|
4
|
-
module Vx
|
5
|
-
module Instrumentation
|
6
|
-
Subscriber = Struct.new(:name, :payload, :tags) do
|
7
|
-
|
8
|
-
def process ; end
|
9
|
-
|
10
|
-
class << self
|
11
|
-
|
12
|
-
def install
|
13
|
-
ev = event || /.*/
|
14
|
-
$stdout.puts " --> add instrumentation #{self.to_s} to #{ev.inspect}"
|
15
|
-
ActiveSupport::Notifications.subscribe(ev) do |name, started, finished, uid, payload|
|
16
|
-
if name[0] != '!'
|
17
|
-
tags = name.split(".")
|
18
|
-
inst = new(name, payload, tags).tap(&:process)
|
19
|
-
Instrumentation.delivery(inst.name, inst.payload, inst.tags.uniq, started, finished)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def event(name = nil)
|
25
|
-
@event = name if name
|
26
|
-
@event
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|