xhummingbird 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile.lock +2 -2
- data/examples/custom_tags.rb +21 -0
- data/lib/xhummingbird.rb +19 -8
- data/lib/xhummingbird/rack.rb +1 -0
- data/lib/xhummingbird/rack/capture_exception.rb +37 -0
- data/lib/xhummingbird/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f5561122802f0f1a8c90a640b69802ed5dff468da607b47c7bfbff63eaf893c
|
4
|
+
data.tar.gz: 871d26b48fb2a0dc04b8ec266c497b6366f04261e1af5c1012144f2ba9c21bfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1600c2a4cefa208e379da4313ff4a7bf9f66a21e56cfee784b24a479aa6e827c27a85be32657ceabf9c5fc796e17b3ea3f6b5c694c560f0da8f5141db628cb28
|
7
|
+
data.tar.gz: ce403ecee0b90f896d1af6c5e760c6066abdb5ff57c444d15f4401c663e49ba47328bffa34f28524ae9895d0b0da3568055eadd03af472e734a8a5e1dab141e0
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
xhummingbird (0.1.
|
4
|
+
xhummingbird (0.1.1)
|
5
5
|
ffi-rzmq
|
6
6
|
google-protobuf
|
7
7
|
|
@@ -14,7 +14,7 @@ GEM
|
|
14
14
|
ffi-rzmq-core (>= 1.0.7)
|
15
15
|
ffi-rzmq-core (1.0.7)
|
16
16
|
ffi
|
17
|
-
google-protobuf (3.15.
|
17
|
+
google-protobuf (3.15.6-x86_64-linux)
|
18
18
|
minitest (5.14.4)
|
19
19
|
parallel (1.20.1)
|
20
20
|
parser (3.0.0.0)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'xhummingbird'
|
2
|
+
|
3
|
+
raise "Set #{Xhummingbird::Client::XH_SERVER} environment variable" unless Xhummingbird.enabled?
|
4
|
+
|
5
|
+
Xhummingbird.send_trace(
|
6
|
+
title: "CustomTagTrace",
|
7
|
+
message: "CustomTags",
|
8
|
+
tags: {
|
9
|
+
tag_a: 42,
|
10
|
+
tag_b: "foo",
|
11
|
+
tag_c: :bar
|
12
|
+
}
|
13
|
+
)
|
14
|
+
|
15
|
+
begin
|
16
|
+
raise 'Something wrong'
|
17
|
+
rescue => e
|
18
|
+
Xhummingbird.send_exception(e, tags: {path: __FILE__})
|
19
|
+
end
|
20
|
+
|
21
|
+
sleep 1 # Await sending
|
data/lib/xhummingbird.rb
CHANGED
@@ -11,7 +11,7 @@ require_relative "xhummingbird/protos/event_pb"
|
|
11
11
|
module Xhummingbird
|
12
12
|
class Error < StandardError; end
|
13
13
|
|
14
|
-
def self.send_trace(title:, message: "", level: 1)
|
14
|
+
def self.send_trace(title:, message: "", level: 1, tags: {})
|
15
15
|
return unless enabled?
|
16
16
|
|
17
17
|
send(
|
@@ -19,14 +19,14 @@ module Xhummingbird
|
|
19
19
|
title: title.to_s,
|
20
20
|
message: message.to_s,
|
21
21
|
trace: caller,
|
22
|
-
tags: default_tags,
|
22
|
+
tags: default_tags.merge(format_hash(tags)),
|
23
23
|
timestamp: Time.now
|
24
24
|
)
|
25
25
|
rescue
|
26
26
|
raise Error
|
27
27
|
end
|
28
28
|
|
29
|
-
def self.send_exception(exception, level: 2)
|
29
|
+
def self.send_exception(exception, level: 2, tags: {})
|
30
30
|
return unless enabled?
|
31
31
|
|
32
32
|
send(
|
@@ -34,7 +34,7 @@ module Xhummingbird
|
|
34
34
|
title: exception.class.name,
|
35
35
|
message: exception.message,
|
36
36
|
trace: exception.backtrace,
|
37
|
-
tags: default_tags,
|
37
|
+
tags: default_tags.merge(format_hash(tags)),
|
38
38
|
timestamp: Time.now
|
39
39
|
)
|
40
40
|
rescue
|
@@ -55,10 +55,11 @@ module Xhummingbird
|
|
55
55
|
|
56
56
|
def self.default_tags
|
57
57
|
{
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
"default/sdk" => "Ruby #{Xhummingbird::VERSION}",
|
59
|
+
"default/hostname" => Socket.gethostname,
|
60
|
+
"default/ruby_version" => RUBY_VERSION,
|
61
|
+
"default/pid" => Process.pid.to_s,
|
62
|
+
"default/thread_object_id" => Thread.current.object_id.to_s
|
62
63
|
}
|
63
64
|
end
|
64
65
|
|
@@ -67,4 +68,14 @@ module Xhummingbird
|
|
67
68
|
message = Event.encode(event)
|
68
69
|
Client.instance.send(message)
|
69
70
|
end
|
71
|
+
|
72
|
+
def self.format_hash(hash)
|
73
|
+
formatted = {}
|
74
|
+
|
75
|
+
hash.each do |k, v|
|
76
|
+
formatted[k.to_s] = v.to_s
|
77
|
+
end
|
78
|
+
|
79
|
+
formatted
|
80
|
+
end
|
70
81
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'rack/capture_exception'
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Xhummingbird
|
2
|
+
module Rack
|
3
|
+
class CaptureException
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
p env
|
10
|
+
|
11
|
+
begin
|
12
|
+
response = @app.call(env)
|
13
|
+
rescue => e
|
14
|
+
Xhummingbird.send_exception(e, tags: convert_to_rack_tags(env))
|
15
|
+
end
|
16
|
+
|
17
|
+
error = env['rack.exception'] || env['sinatra.error']
|
18
|
+
|
19
|
+
Xhummingbird.send_exception(error, tags: convert_to_rack_tags(env)) if error
|
20
|
+
|
21
|
+
response
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def convert_to_rack_tags(env)
|
27
|
+
tags = {}
|
28
|
+
|
29
|
+
env.each do |k, v|
|
30
|
+
tags["rack_env/" + k.to_s] = v.to_s rescue nil
|
31
|
+
end
|
32
|
+
|
33
|
+
tags
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/xhummingbird/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xhummingbird
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xmisao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi-rzmq
|
@@ -47,6 +47,7 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
49
|
- ".rubocop.yml"
|
50
|
+
- ".ruby-version"
|
50
51
|
- CODE_OF_CONDUCT.md
|
51
52
|
- Gemfile
|
52
53
|
- Gemfile.lock
|
@@ -55,6 +56,7 @@ files:
|
|
55
56
|
- Rakefile
|
56
57
|
- bin/console
|
57
58
|
- bin/setup
|
59
|
+
- examples/custom_tags.rb
|
58
60
|
- examples/send_exception.rb
|
59
61
|
- examples/send_trace.rb
|
60
62
|
- examples/short_name.rb
|
@@ -63,6 +65,8 @@ files:
|
|
63
65
|
- lib/xhummingbird.rb
|
64
66
|
- lib/xhummingbird/client.rb
|
65
67
|
- lib/xhummingbird/protos/event_pb.rb
|
68
|
+
- lib/xhummingbird/rack.rb
|
69
|
+
- lib/xhummingbird/rack/capture_exception.rb
|
66
70
|
- lib/xhummingbird/short_name.rb
|
67
71
|
- lib/xhummingbird/version.rb
|
68
72
|
- xhummingbird.gemspec
|