aws-xray 0.12.2 → 0.13.0.beta1
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/example/Procfile +4 -4
- data/example/recipe_app_config.ru +8 -4
- data/lib/aws/xray/context.rb +19 -0
- data/lib/aws/xray/faraday.rb +2 -1
- data/lib/aws/xray/hooks/net_http.rb +51 -0
- data/lib/aws/xray/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0018b35cfa2fd693eac3478688682d814dc98e9
|
4
|
+
data.tar.gz: 5ee596913c20b16a040484f2d0888ccb28ada64a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f78e9501736f39266e1c496bf4c2f3c7bd7b974176763bc665fcd7e7a2d848d8925f2fb93d85449abbfb10e680fd4111eb32056bfcf4b0fd868fd1a6bb8d022
|
7
|
+
data.tar.gz: 527bcf973e2862796405774ee187ca10bc4f4eeb0dd20f09142e2e1cab5f37502ff7548f431cd40bda045118a39a6546ad3e6c084650fde91b886aa89c4a952b
|
data/example/Procfile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
front: env RECIPE_APP=127.0.0.1:3001 bundle exec rackup fron_app_config.ru -o 127.0.0.1 -p 3000
|
2
|
-
recipe: env USER_APP=127.0.0.1:3002 CAMPAIN_APP=127.0.0.1:3003 bundle exec rackup recipe_app_config.ru -o 127.0.0.1 -p 3001
|
3
|
-
user: bundle exec rackup user_app_config.ru -o 127.0.0.1 -p 3002
|
4
|
-
campain: bundle exec rackup campain_app_config.ru -o 127.0.0.1 -p 3003
|
1
|
+
front: env AWS_XRAY_LOCATION=localhost:2000 RECIPE_APP=127.0.0.1:3001 bundle exec rackup fron_app_config.ru -o 127.0.0.1 -p 3000
|
2
|
+
recipe: env AWS_XRAY_LOCATION=localhost:2000 USER_APP=127.0.0.1:3002 CAMPAIN_APP=127.0.0.1:3003 bundle exec rackup recipe_app_config.ru -o 127.0.0.1 -p 3001
|
3
|
+
user: env AWS_XRAY_LOCATION=localhost:2000 bundle exec rackup user_app_config.ru -o 127.0.0.1 -p 3002
|
4
|
+
campain: env AWS_XRAY_LOCATION=localhost:2000 bundle exec rackup campain_app_config.ru -o 127.0.0.1 -p 3003
|
5
5
|
agent: socat UDP-RECVFROM:2000,fork STDOUT
|
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'pry'
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
|
2
5
|
require 'faraday'
|
3
6
|
require 'aws-xray'
|
7
|
+
require 'aws/xray/hooks/net_http'
|
4
8
|
|
5
9
|
user_app = ENV.fetch('USER_APP') # host:port
|
6
10
|
campain_app = ENV.fetch('CAMPAIN_APP') # host:port
|
@@ -15,11 +19,11 @@ run Proc.new {|env|
|
|
15
19
|
end
|
16
20
|
user_res = user_client.get('/')
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
uri = URI("http://#{campain_app}")
|
23
|
+
host, port = campain_app.split(':')
|
24
|
+
campain_res = Net::HTTP.start(host, port) do |http|
|
25
|
+
http.request(Net::HTTP::Get.new(uri))
|
21
26
|
end
|
22
|
-
campain_res = campain_client.get('/')
|
23
27
|
|
24
28
|
body = "awesome recipe by #{user_res.body}"
|
25
29
|
if campain_res.body == '1'
|
data/lib/aws/xray/context.rb
CHANGED
@@ -68,6 +68,7 @@ module Aws
|
|
68
68
|
@client = client
|
69
69
|
@trace = trace
|
70
70
|
@base_segment_id = base_segment_id
|
71
|
+
@disabled_ids = []
|
71
72
|
end
|
72
73
|
|
73
74
|
# Curretly context object is thread safe, so copying is not necessary,
|
@@ -122,6 +123,24 @@ module Aws
|
|
122
123
|
@client.send_segment(sub)
|
123
124
|
end
|
124
125
|
end
|
126
|
+
|
127
|
+
# Temporary disabling tracing for given id in given block.
|
128
|
+
# CAUTION: the disabling will NOT be propagated between threads!!
|
129
|
+
#
|
130
|
+
# @param [Symbol] id must be unique between tracing methods.
|
131
|
+
def disable_trace(id)
|
132
|
+
@disabled_ids << id
|
133
|
+
|
134
|
+
begin
|
135
|
+
yield
|
136
|
+
ensure
|
137
|
+
@disabled_ids.delete(id)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def disabled?(id)
|
142
|
+
@disabled_ids.include?(id)
|
143
|
+
end
|
125
144
|
end
|
126
145
|
end
|
127
146
|
end
|
data/lib/aws/xray/faraday.rb
CHANGED
@@ -21,7 +21,8 @@ module Aws
|
|
21
21
|
req_env.request_headers[TRACE_HEADER] = propagate_trace.to_header_value
|
22
22
|
sub.set_http_request(Request.build_from_faraday_env(req_env))
|
23
23
|
|
24
|
-
@app.call(req_env)
|
24
|
+
res = Context.current.disable_trace(:net_http) { @app.call(req_env) }
|
25
|
+
res.on_complete do |res_env|
|
25
26
|
sub.set_http_response(res_env.status, res_env.response_headers['Content-Length'])
|
26
27
|
case res_env.status
|
27
28
|
when 499
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
module Xray
|
5
|
+
module Hooks
|
6
|
+
module NetHttp
|
7
|
+
def request(req, *args)
|
8
|
+
return super unless Context.started?
|
9
|
+
return super if Context.current.disabled?(:net_http)
|
10
|
+
|
11
|
+
uri = URI('')
|
12
|
+
uri.scheme = use_ssl? ? 'https' : 'http'
|
13
|
+
uri.host = address
|
14
|
+
uri.port = port
|
15
|
+
uri.path = URI(req.path).path
|
16
|
+
request_record = Request.build(
|
17
|
+
method: req.method,
|
18
|
+
url: uri.to_s,
|
19
|
+
user_agent: req['User-Agent'],
|
20
|
+
)
|
21
|
+
Context.current.child_trace(remote: true, name: address) do |sub|
|
22
|
+
propagate_trace = sub.generate_trace
|
23
|
+
req[TRACE_HEADER] = propagate_trace.to_header_value
|
24
|
+
sub.set_http_request(request_record)
|
25
|
+
|
26
|
+
res = super
|
27
|
+
|
28
|
+
sub.set_http_response(res.code.to_i, res['Content-Length'])
|
29
|
+
case res.code.to_i
|
30
|
+
when 499
|
31
|
+
cause = Cause.new(stack: caller, message: 'Got 499', type: 'http_request_error')
|
32
|
+
sub.set_error(error: true, throttle: true, cause: cause)
|
33
|
+
when 400..498
|
34
|
+
cause = Cause.new(stack: caller, message: 'Got 4xx', type: 'http_request_error')
|
35
|
+
sub.set_error(error: true, cause: cause)
|
36
|
+
when 500..599
|
37
|
+
cause = Cause.new(stack: caller, message: 'Got 5xx', type: 'http_request_error')
|
38
|
+
sub.set_error(fault: true, remote: true, cause: cause)
|
39
|
+
else
|
40
|
+
# pass
|
41
|
+
end
|
42
|
+
|
43
|
+
res
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Net::HTTP.prepend(Aws::Xray::Hooks::NetHttp)
|
data/lib/aws/xray/version.rb
CHANGED
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.
|
4
|
+
version: 0.13.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taiki Ono
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- lib/aws/xray/error.rb
|
145
145
|
- lib/aws/xray/faraday.rb
|
146
146
|
- lib/aws/xray/header_parser.rb
|
147
|
+
- lib/aws/xray/hooks/net_http.rb
|
147
148
|
- lib/aws/xray/rack.rb
|
148
149
|
- lib/aws/xray/rails.rb
|
149
150
|
- lib/aws/xray/request.rb
|
@@ -170,9 +171,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
170
171
|
version: '0'
|
171
172
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
173
|
requirements:
|
173
|
-
- - "
|
174
|
+
- - ">"
|
174
175
|
- !ruby/object:Gem::Version
|
175
|
-
version:
|
176
|
+
version: 1.3.1
|
176
177
|
requirements: []
|
177
178
|
rubyforge_project:
|
178
179
|
rubygems_version: 2.6.11
|