aws-xray 0.32.1 → 0.32.2

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: d11b7c6ff399ca4649fb5ad82eb3c6dcf8988e77
4
- data.tar.gz: 00bcf28cadccf4d3345b8eac6fa3bcf67c40caa0
3
+ metadata.gz: 9339c52726c1286dc967332ebd1214d81dff09a7
4
+ data.tar.gz: 85c8c3eecbd5b705e05975db29e893cdd809c309
5
5
  SHA512:
6
- metadata.gz: d9c402b81de88eb7e43243886f41e1c62c0900858cd575926752468f3924ca869758da3889c48fe371abadec3347c573f19ca652a3e42cc3ba11a47fc4f5721c
7
- data.tar.gz: 9c471ba49ce067607d584ac14ca76edccf922d1d62700980de9dbd0c1b575e6adfad975ec947e4b547713f7b47c4666133607701c6b3053ba3d97ea7b15eae5b
6
+ metadata.gz: 1fec4a00dfae3a47a23f5263fbe8512cf447e9ef274518052c62078e58707a0ff014a5c7236ac844df8771574700ee9d4b6fae9938bb79ca828b6c4b0ff6cd3e
7
+ data.tar.gz: '0668ff24b6871a361b87996111bb08883407988665aaca163e34b698dd5530a26b5b5b0d00eb9045e308199ac5fb35c32bd550040e28441ac00928f41180e0c5'
data/README.md CHANGED
@@ -87,7 +87,7 @@ end
87
87
  Aws::Xray.trace(name: 'my-app-batch') do |seg|
88
88
  client.get('/foo')
89
89
 
90
- Aws::Xray::Context.current.start_subsegment(name: 'fetch-user', remote: true) do |sub|
90
+ Aws::Xray.start_subsegment(name: 'fetch-user', remote: true) do |sub|
91
91
  # DB access or something to trace.
92
92
  end
93
93
  end
@@ -113,7 +113,7 @@ Net::HTTP.start(host, port) do |http|
113
113
  end
114
114
  ```
115
115
 
116
- If you can't access headers, e.g. external client library like aws-sdk or dogapi-rb, setup subsegment name by `Aws::Xray::Context#overwrite`:
116
+ If you can't access headers, e.g. external client library like aws-sdk or dogapi-rb, setup subsegment name by `Aws::Xray.overwrite`:
117
117
 
118
118
  ```ruby
119
119
  client = Aws::Sns::Client.new
@@ -135,8 +135,8 @@ Aws::Xray.config.solr_hook_name = 'solr-development'
135
135
  Tracing context is thread local. To pass current tracing context, copy current tracing context:
136
136
 
137
137
  ```ruby
138
- Thread.new(Aws::Xray::Context.current.copy) do |context|
139
- Aws::Xray::Context.with_given_context(context) do
138
+ Thread.new(Aws::Xray.current_context.copy) do |context|
139
+ Aws::Xray.with_given_context(context) do
140
140
  # Do something
141
141
  end
142
142
  end
data/lib/aws/xray/rack.rb CHANGED
@@ -26,15 +26,13 @@ module Aws
26
26
  env[ORIGINAL_TRACE_ENV] = env[TRACE_ENV] if env[TRACE_ENV] # just for the record
27
27
  env[TRACE_ENV] = trace.to_header_value
28
28
 
29
- Context.with_new_context(@name, trace) do
30
- Context.current.start_segment do |seg|
31
- seg.set_http_request(Request.build_from_rack_env(env))
32
- status, headers, body = @app.call(env)
33
- length = headers['Content-Length'] || 0
34
- seg.set_http_response_with_error(status, length, remote: false)
35
- headers[TRACE_HEADER] = trace.to_header_value
36
- [status, headers, body]
37
- end
29
+ Aws::Xray.trace(name: @name, trace: trace) do |seg|
30
+ seg.set_http_request(Request.build_from_rack_env(env))
31
+ status, headers, body = @app.call(env)
32
+ length = headers['Content-Length'] || 0
33
+ seg.set_http_response_with_error(status, length, remote: false)
34
+ headers[TRACE_HEADER] = trace.to_header_value
35
+ [status, headers, body]
38
36
  end
39
37
  end
40
38
 
@@ -10,6 +10,11 @@ module Aws
10
10
  new(name: name, trace: trace, parent_id: parent_id, remote: remote)
11
11
  end
12
12
 
13
+ # Build a subsegment as null object.
14
+ def self.build_null
15
+ build(Trace.generate, SecureRandom.hex(8), remote: true, name: '')
16
+ end
17
+
13
18
  TYPE_NAME = 'subsegment'.freeze
14
19
 
15
20
  def initialize(name:, trace:, parent_id:, remote:)
@@ -1,5 +1,5 @@
1
1
  module Aws
2
2
  module Xray
3
- VERSION = '0.32.1'
3
+ VERSION = '0.32.2'
4
4
  end
5
5
  end
data/lib/aws/xray.rb CHANGED
@@ -22,24 +22,66 @@ module Aws
22
22
  end
23
23
  Worker.reset(Worker::Configuration.new)
24
24
 
25
- # @param [String] name a logical name of this tracing context.
26
- def self.trace(name: nil)
27
- name = name || config.name || raise(MissingNameError)
28
- Context.with_new_context(name, Trace.generate) do
29
- Context.current.start_segment do |seg|
30
- yield seg
25
+ class << self
26
+ # @param [String] name a logical name of this tracing context.
27
+ # @return [Object] result of given block
28
+ def trace(name: nil, trace: Trace.generate)
29
+ name = name || config.name || raise(MissingNameError)
30
+ Context.with_new_context(name, trace) do
31
+ Context.current.start_segment do |seg|
32
+ yield seg
33
+ end
31
34
  end
32
35
  end
33
- end
34
36
 
35
- # Overwrite under lying tracing name at once. If current context does not
36
- # set to current thread, do nothing.
37
- # @param [String] name
38
- def self.overwrite(name:, &block)
39
- if Context.started?
40
- Context.current.overwrite(name: name, &block)
41
- else
42
- block.call
37
+ # @return [Boolean] whether tracing context is started or not.
38
+ def started?
39
+ Context.started?
40
+ end
41
+
42
+ # @return [Aws::Xray::Context]
43
+ # @raise [Aws::Xray::NotSetError] when the current context is not yet set.
44
+ # Call this method after start tracing with `Aws::Xray.trace`.
45
+ def current_context
46
+ Context.current
47
+ end
48
+
49
+ # @param [Aws::Xray::Context] context copied context
50
+ # @return [Object] result of given block
51
+ def with_given_context(context, &block)
52
+ Context.with_given_context(context, &block)
53
+ end
54
+
55
+ # @yield [Aws::Xray::Subsegment] null subsegment
56
+ # @return [Object] result of given block
57
+ def start_subsegment(name:, remote:, &block)
58
+ if started?
59
+ current_context.start_subsegment(name: name, remote: remote, &block)
60
+ else
61
+ block.call(Subsegment.build_null)
62
+ end
63
+ end
64
+
65
+ # @param [Symbol] id
66
+ # @return [Object] result of given block
67
+ def disable_trace(id, &block)
68
+ if started?
69
+ current_context.disable_trace(id, &block)
70
+ else
71
+ block.call
72
+ end
73
+ end
74
+
75
+ # Overwrite under lying tracing name at once. If current context is not
76
+ # set to current thread, do nothing.
77
+ # @param [String] name
78
+ # @return [Object] result of given block
79
+ def overwrite(name:, &block)
80
+ if started?
81
+ current_context.overwrite(name: name, &block)
82
+ else
83
+ block.call
84
+ end
43
85
  end
44
86
  end
45
87
  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.32.1
4
+ version: 0.32.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taiki Ono