xhummingbird 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/examples/custom_tags.rb +2 -0
- data/examples/send_exception.rb +2 -0
- data/examples/send_trace.rb +2 -0
- data/examples/short_name.rb +2 -0
- data/examples/use_in_processes.rb +4 -0
- data/examples/use_in_threads.rb +2 -0
- data/lib/xhummingbird.rb +36 -6
- data/lib/xhummingbird/client.rb +28 -21
- data/lib/xhummingbird/rack/capture_exception.rb +5 -1
- data/lib/xhummingbird/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 139d598e50a5cc35a31ca2f292308931d02e296e7f94474c12cdf27bc10b4a62
|
4
|
+
data.tar.gz: b5f529c38a79024d63bda6c580d39d29fc46f034c0988f849c44dcec430491cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2365a30d985c6a2311dbe03aff8d1f10cfd9fd97043508564173291a48e0ee7548e5915eb6f81ae74c4b6787eb64e092a77eb4e6412629b0ee8cfbf589446b8
|
7
|
+
data.tar.gz: d091a1f78b159c4f174129e2df9440b65fa87f971398c0179c85c251b74c7f5476789b822fd53ad1e76e1bc49a86d2119ee90921e7f3b9b8ee78ab4616e94115
|
data/Gemfile.lock
CHANGED
data/examples/custom_tags.rb
CHANGED
data/examples/send_exception.rb
CHANGED
data/examples/send_trace.rb
CHANGED
data/examples/short_name.rb
CHANGED
@@ -2,10 +2,14 @@ require 'xhummingbird'
|
|
2
2
|
|
3
3
|
raise "Set #{Xhummingbird::Client::XH_SERVER} environment variable" unless Xhummingbird.enabled?
|
4
4
|
|
5
|
+
Xhummingbird.start
|
6
|
+
|
5
7
|
Xhummingbird.send_trace(title: "ParentProcess", message: "Send trace from parent process")
|
6
8
|
|
7
9
|
process_ids = 10.times.map do |i|
|
8
10
|
fork do
|
11
|
+
Xhummingbird.start
|
12
|
+
|
9
13
|
Xhummingbird.send_trace(title: "ChildProcess", message: "Send trace from child process #{i}")
|
10
14
|
|
11
15
|
sleep 1 # Await sending
|
data/examples/use_in_threads.rb
CHANGED
@@ -2,6 +2,8 @@ require 'xhummingbird'
|
|
2
2
|
|
3
3
|
raise "Set #{Xhummingbird::Client::XH_SERVER} environment variable" unless Xhummingbird.enabled?
|
4
4
|
|
5
|
+
Xhummingbird.start
|
6
|
+
|
5
7
|
threads = 10.times.map do |i|
|
6
8
|
Thread.start do
|
7
9
|
Xhummingbird.send_trace(title: "Thread", message: "Send trace from thread #{i}")
|
data/lib/xhummingbird.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
require 'singleton'
|
4
4
|
require 'ffi-rzmq'
|
5
5
|
require 'socket'
|
6
|
+
require 'logger'
|
7
|
+
require 'set'
|
6
8
|
|
7
9
|
require_relative "xhummingbird/version"
|
8
10
|
require_relative "xhummingbird/client"
|
@@ -11,7 +13,23 @@ require_relative "xhummingbird/protos/event_pb"
|
|
11
13
|
module Xhummingbird
|
12
14
|
class Error < StandardError; end
|
13
15
|
|
16
|
+
LOGGER = Logger.new(STDERR)
|
17
|
+
|
18
|
+
def self.debug(*args)
|
19
|
+
LOGGER.debug(*args) if ENV['XH_DEBUG']
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.start
|
23
|
+
debug(__method__)
|
24
|
+
|
25
|
+
Client.instance.start
|
26
|
+
|
27
|
+
send_trace(title: "Started", message: "Xhummingbird Ruby SDK started.", level: 0)
|
28
|
+
end
|
29
|
+
|
14
30
|
def self.send_trace(title:, message: "", level: 1, tags: {})
|
31
|
+
debug(__method__)
|
32
|
+
|
15
33
|
return unless enabled?
|
16
34
|
|
17
35
|
send(
|
@@ -22,11 +40,13 @@ module Xhummingbird
|
|
22
40
|
tags: default_tags.merge(format_hash(tags)),
|
23
41
|
timestamp: Time.now
|
24
42
|
)
|
25
|
-
rescue
|
26
|
-
|
43
|
+
rescue => e
|
44
|
+
debug(e)
|
27
45
|
end
|
28
46
|
|
29
47
|
def self.send_exception(exception, level: 2, tags: {})
|
48
|
+
debug(__method__)
|
49
|
+
|
30
50
|
return unless enabled?
|
31
51
|
|
32
52
|
send(
|
@@ -37,23 +57,29 @@ module Xhummingbird
|
|
37
57
|
tags: default_tags.merge(format_hash(tags)),
|
38
58
|
timestamp: Time.now
|
39
59
|
)
|
40
|
-
rescue
|
41
|
-
|
60
|
+
rescue => e
|
61
|
+
debug(e)
|
42
62
|
end
|
43
63
|
|
44
64
|
def self.send_event(**args)
|
65
|
+
debug(__method__)
|
66
|
+
|
45
67
|
return unless enabled?
|
46
68
|
|
47
69
|
send(**args)
|
48
|
-
rescue
|
49
|
-
|
70
|
+
rescue => e
|
71
|
+
debug(e)
|
50
72
|
end
|
51
73
|
|
52
74
|
def self.enabled?
|
75
|
+
debug(__method__)
|
76
|
+
|
53
77
|
Client.instance.enabled?
|
54
78
|
end
|
55
79
|
|
56
80
|
def self.default_tags
|
81
|
+
debug(__method__)
|
82
|
+
|
57
83
|
{
|
58
84
|
"default/sdk" => "Ruby #{Xhummingbird::VERSION}",
|
59
85
|
"default/hostname" => Socket.gethostname,
|
@@ -64,12 +90,16 @@ module Xhummingbird
|
|
64
90
|
end
|
65
91
|
|
66
92
|
def self.send(**args)
|
93
|
+
debug(__method__)
|
94
|
+
|
67
95
|
event = Event.new(**args)
|
68
96
|
message = Event.encode(event)
|
69
97
|
Client.instance.send(message)
|
70
98
|
end
|
71
99
|
|
72
100
|
def self.format_hash(hash)
|
101
|
+
debug(__method__)
|
102
|
+
|
73
103
|
formatted = {}
|
74
104
|
|
75
105
|
hash.each do |k, v|
|
data/lib/xhummingbird/client.rb
CHANGED
@@ -5,41 +5,48 @@ module Xhummingbird
|
|
5
5
|
XH_SERVER = 'XH_SERVER'
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
@
|
8
|
+
@pid = nil
|
9
|
+
@socket = nil
|
10
|
+
@active = false
|
9
11
|
end
|
10
12
|
|
11
13
|
def send(message)
|
12
|
-
|
14
|
+
if active?
|
15
|
+
@socket.send_string(message)
|
16
|
+
else
|
17
|
+
Xhummingbird.debug("Xhummingbird not started.")
|
18
|
+
end
|
13
19
|
end
|
14
20
|
|
15
21
|
def enabled?
|
16
|
-
@
|
22
|
+
@enabled ||= !!address
|
17
23
|
end
|
18
24
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
25
|
+
def start
|
26
|
+
ctx = ZMQ::Context.new
|
27
|
+
socket = ctx.socket(ZMQ::PUSH)
|
28
|
+
socket.connect(address)
|
29
|
+
@socket = socket
|
30
|
+
Xhummingbird.debug("Socket created (pid: #{$$})")
|
31
|
+
|
32
|
+
at_exit do
|
33
|
+
Xhummingbird.debug("at_exit started.")
|
34
|
+
@socket.close
|
35
|
+
Xhummingbird.debug("at_exit stopped.")
|
36
|
+
end
|
23
37
|
|
24
|
-
@
|
38
|
+
@pid = $$
|
39
|
+
@active = true
|
25
40
|
end
|
26
41
|
|
27
|
-
|
28
|
-
@mutex.synchronize do
|
29
|
-
return @socket if defined?(@socket) && @pid == Process.pid
|
30
|
-
|
31
|
-
@pid = Process.pid
|
32
|
-
|
33
|
-
ctx = ZMQ::Context.new
|
34
|
-
socket = ctx.socket(ZMQ::PUSH)
|
35
|
-
socket.connect(address)
|
36
|
-
|
37
|
-
@socket = socket
|
38
|
-
end
|
39
|
-
end
|
42
|
+
private
|
40
43
|
|
41
44
|
def address
|
42
45
|
ENV[XH_SERVER]
|
43
46
|
end
|
47
|
+
|
48
|
+
def active?
|
49
|
+
@pid == $$ && @socket && @active
|
50
|
+
end
|
44
51
|
end
|
45
52
|
end
|
@@ -43,7 +43,11 @@ module Xhummingbird
|
|
43
43
|
|
44
44
|
env.each do |k, v|
|
45
45
|
if CONVERT_KEYS.include?(k) || k.start_with?(HTTP_HEADER_PREFIX)
|
46
|
-
|
46
|
+
begin
|
47
|
+
tags["rack_env/" + k.to_s] = v.to_s
|
48
|
+
rescue => e
|
49
|
+
Xhummingbird.debug(e)
|
50
|
+
end
|
47
51
|
end
|
48
52
|
end
|
49
53
|
|
data/lib/xhummingbird/version.rb
CHANGED