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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc55dc479a1ea3b8fba17b4f2f38a493fe1c190160a004585bcbd785fb0c9d21
4
- data.tar.gz: a45754510d4490b253aeb9daec6360c37d52b662504a953a8bbb946fe134e191
3
+ metadata.gz: 139d598e50a5cc35a31ca2f292308931d02e296e7f94474c12cdf27bc10b4a62
4
+ data.tar.gz: b5f529c38a79024d63bda6c580d39d29fc46f034c0988f849c44dcec430491cc
5
5
  SHA512:
6
- metadata.gz: 50f009f45946de188c80ba59e682a3d17496d3921192bc28432cc8f911a53f752ea1aaa1bae4864f4f2605f55a4628fab6bc39b87b0a447e21843bbd0f5f5bc7
7
- data.tar.gz: 153ac10ec24214bc7edbcb70fa369cf905a6aaa2c29c547cd34a83014033798998d3401d11359344d543666297b49ab656e09dbb00a00b61eb4b81eea59758dc
6
+ metadata.gz: b2365a30d985c6a2311dbe03aff8d1f10cfd9fd97043508564173291a48e0ee7548e5915eb6f81ae74c4b6787eb64e092a77eb4e6412629b0ee8cfbf589446b8
7
+ data.tar.gz: d091a1f78b159c4f174129e2df9440b65fa87f971398c0179c85c251b74c7f5476789b822fd53ad1e76e1bc49a86d2119ee90921e7f3b9b8ee78ab4616e94115
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xhummingbird (0.1.2)
4
+ xhummingbird (0.1.3)
5
5
  ffi-rzmq
6
6
  google-protobuf
7
7
 
@@ -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
  Xhummingbird.send_trace(
6
8
  title: "CustomTagTrace",
7
9
  message: "CustomTags",
@@ -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
  begin
6
8
  raise 'Something wrong'
7
9
  rescue => e
@@ -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
  Xhummingbird.send_trace(title: "SampleTrace", message: "Something happend")
6
8
 
7
9
  sleep 1 # Await sending
@@ -3,6 +3,8 @@ require 'xhummingbird/short_name'
3
3
 
4
4
  raise "Set #{XH::Client::XH_SERVER} environment variable" unless XH.enabled?
5
5
 
6
+ XH.start
7
+
6
8
  XH.send_trace(title: "ShortNameTrace", message: "Send trace from short name reference")
7
9
 
8
10
  begin
@@ -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
@@ -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
- raise Error
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
- raise Error
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
- raise Error
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|
@@ -5,41 +5,48 @@ module Xhummingbird
5
5
  XH_SERVER = 'XH_SERVER'
6
6
 
7
7
  def initialize
8
- @mutex = Mutex.new
8
+ @pid = nil
9
+ @socket = nil
10
+ @active = false
9
11
  end
10
12
 
11
13
  def send(message)
12
- socket.send_string(message)
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
- @setup ||= !!address
22
+ @enabled ||= !!address
17
23
  end
18
24
 
19
- private
20
-
21
- def socket
22
- return @socket if defined?(@socket) && @pid == Process.pid
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
- @socket = init_socket
38
+ @pid = $$
39
+ @active = true
25
40
  end
26
41
 
27
- def init_socket
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
- tags["rack_env/" + k.to_s] = v.to_s rescue nil
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Xhummingbird
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xhummingbird
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - xmisao