aws-xray 0.17.2 → 0.18.0.beta1

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: 3deda3f256b5d2af42eb41c05b185a251778d92b
4
- data.tar.gz: faa78fd4d89cb7395d1c522ce9ed783aef81a1b8
3
+ metadata.gz: 9f6fc4b5ed63083e7023dea1ee6922e7af1bc9a4
4
+ data.tar.gz: cc4fb9f2dc6577c02b500592a951fa728a7307c2
5
5
  SHA512:
6
- metadata.gz: 17165b0eca79f5cdd7ad3bf905190a0890b9b8e43373e8a000bb98fec27c83624d38bfa7c2f046f28f5f92742f47de11d808db508f370d14c36c1c92a787d459
7
- data.tar.gz: bf10745ef15b498e5f4f0e771c6b67304445586867224ef4ce151561b1eef5e1fb46baaf16863db666e1822670282ac61bf9a4eff537e754612517893124f901
6
+ metadata.gz: 37c71b2c1c758525fc7ad708b7453a3ce78f8f508bfd7c2201530d0e55fd9ce09e2734ab180a63dd704499fc06ef817f77c976dd35e043abb4b5cd1bee794c16
7
+ data.tar.gz: c77cb5dc31a323e2e735b4e0632bd31fad70049e6e2babce0d728d24a6bfb41fb502b34d1ff9bc3dcd0aa8d55128e92f4eac5a12f101b803dd758aa84d811d43
data/lib/aws/xray.rb CHANGED
@@ -1,10 +1,16 @@
1
1
  require 'aws/xray/version'
2
2
  require 'aws/xray/errors'
3
- require 'aws/xray/rack'
4
- require 'aws/xray/faraday'
3
+ require 'aws/xray/trace'
4
+ require 'aws/xray/client'
5
+ require 'aws/xray/context'
6
+ require 'aws/xray/worker'
7
+
5
8
  require 'aws/xray/configuration'
6
9
  require 'aws/xray/sockets'
7
10
 
11
+ require 'aws/xray/rack'
12
+ require 'aws/xray/faraday'
13
+
8
14
  module Aws
9
15
  module Xray
10
16
  TRACE_HEADER = 'X-Amzn-Trace-Id'.freeze
@@ -19,6 +19,25 @@ module Aws
19
19
  # @param [Aws::Xray::Segment] segment
20
20
  def send_segment(segment)
21
21
  payload = %!{"format": "json", "version": 1}\n#{segment.to_json}\n!
22
+
23
+ begin
24
+ if @sock # test env or not aws-xray is not enabled
25
+ send_payload(payload)
26
+ else # production env
27
+ Worker.post(payload, self.copy)
28
+ end
29
+ rescue QueueIsFullError => e
30
+ begin
31
+ Aws::Xray.config.segment_sending_error_handler.call(e, payload, host: @host, port: @port)
32
+ rescue Exception => e
33
+ $stderr.puts("Error handler `#{Aws::Xray.config.segment_sending_error_handler}` raised an error: #{e}\n#{e.backtrace.join("\n")}")
34
+ end
35
+ end
36
+ end
37
+
38
+ # Will be called in other threads.
39
+ # @param [String] payload
40
+ def send_payload(payload)
22
41
  sock = @sock || UDPSocket.new
23
42
 
24
43
  begin
@@ -77,6 +77,19 @@ module Aws
77
77
  end
78
78
  # @param [Proc] segment_sending_error_handler Callable object
79
79
  attr_writer :segment_sending_error_handler
80
+
81
+ # @return [Aws::Xray::Worker::Configuration]
82
+ def worker
83
+ @worker ||= Aws::Xray::Worker::Configuration.new
84
+ end
85
+ # Set given configuration and reset workers according to the given
86
+ # configuration.
87
+ # @param [Aws::Xray::Worker::Configuration] conf
88
+ def worker=(conf)
89
+ @worker = conf
90
+ Aws::Xray::Worker.reset(conf)
91
+ conf
92
+ end
80
93
  end
81
94
  end
82
95
  end
@@ -26,5 +26,14 @@ module Aws
26
26
  super("Can not send all bytes: expected #{payload_len} but #{sent_len} sent")
27
27
  end
28
28
  end
29
+
30
+ class QueueIsFullError < BaseError
31
+ attr_reader :error
32
+
33
+ def initialize(error)
34
+ @error = error
35
+ super('The queue exceeds max size')
36
+ end
37
+ end
29
38
  end
30
39
  end
data/lib/aws/xray/rack.rb CHANGED
@@ -1,7 +1,3 @@
1
- require 'aws/xray/trace'
2
- require 'aws/xray/client'
3
- require 'aws/xray/context'
4
-
5
1
  module Aws
6
2
  module Xray
7
3
  class Rack
@@ -1,5 +1,5 @@
1
1
  module Aws
2
2
  module Xray
3
- VERSION = '0.17.2'
3
+ VERSION = '0.18.0.beta1'
4
4
  end
5
5
  end
@@ -0,0 +1,56 @@
1
+ module Aws
2
+ module Xray
3
+ class Worker
4
+ class Configuration
5
+ attr_reader :num, :max_queue_size
6
+
7
+ def initialize(num: 10, max_queue_size: 1000)
8
+ @num = num
9
+ @max_queue_size = max_queue_size
10
+ end
11
+ end
12
+
13
+ class Item < Struct.new(:payload, :client)
14
+ end
15
+
16
+ class << self
17
+ # @param [String] payload to send
18
+ # @param [Aws::Xray::Client] client
19
+ def post(payload, client)
20
+ @queue.push(Item.new(payload, client.copy))
21
+ rescue ThreadError => e
22
+ raise QueueIsFullError.new(e)
23
+ end
24
+
25
+ # @param [Aws::Xray::Worker::Configuration] config
26
+ def reset(config)
27
+ @queue = Thread::SizedQueue.new(config.max_queue_size)
28
+ @workers.each(&:kill) if defined?(@workers) && !@workers.empty?
29
+ @workers = Array.new(config.num) { new(@queue).run }
30
+ end
31
+ # Call `.reset` after class definetion section.
32
+ end
33
+
34
+ def initialize(queue)
35
+ @queue = queue
36
+ end
37
+
38
+ def run
39
+ th = Thread.new(@queue) do |queue|
40
+ loop do
41
+ item = queue.pop
42
+ if item.is_a?(Item)
43
+ item.client.send_payload(item.payload)
44
+ else
45
+ # TODO
46
+ end
47
+ end
48
+ end
49
+ th.abort_on_exception = true
50
+ th
51
+ end
52
+
53
+ reset(Aws::Xray::Worker::Configuration.new)
54
+ end
55
+ end
56
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-xray
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.2
4
+ version: 0.18.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taiki Ono
@@ -186,6 +186,7 @@ files:
186
186
  - lib/aws/xray/trace.rb
187
187
  - lib/aws/xray/version.rb
188
188
  - lib/aws/xray/version_detector.rb
189
+ - lib/aws/xray/worker.rb
189
190
  - prepare_release.rb
190
191
  homepage: https://github.com/taiki45/aws-xray
191
192
  licenses:
@@ -202,9 +203,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
203
  version: '0'
203
204
  required_rubygems_version: !ruby/object:Gem::Requirement
204
205
  requirements:
205
- - - ">="
206
+ - - ">"
206
207
  - !ruby/object:Gem::Version
207
- version: '0'
208
+ version: 1.3.1
208
209
  requirements: []
209
210
  rubyforge_project:
210
211
  rubygems_version: 2.5.2