aws-xray 0.32.1 → 0.32.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/aws/xray/rack.rb +7 -9
- data/lib/aws/xray/subsegment.rb +5 -0
- data/lib/aws/xray/version.rb +1 -1
- data/lib/aws/xray.rb +57 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9339c52726c1286dc967332ebd1214d81dff09a7
|
4
|
+
data.tar.gz: 85c8c3eecbd5b705e05975db29e893cdd809c309
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
139
|
-
Aws::Xray
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
|
data/lib/aws/xray/subsegment.rb
CHANGED
@@ -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:)
|
data/lib/aws/xray/version.rb
CHANGED
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|