aws-xray 0.14.0 → 0.15.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e367a0bf45a2a7055628dc8e2f41626f164ece6a
4
- data.tar.gz: 0da9a4d1438e8ffe38f369c341af17f44342b0b3
3
+ metadata.gz: 299ef3e4e20724f082b232846ec09d48257cf4e7
4
+ data.tar.gz: d66f81590342387f0dcdf80981aea4ec95fd9449
5
5
  SHA512:
6
- metadata.gz: c287819c6e3ea6b726675c420aec2f1a2ca94f315c85a4feba9e019e26f68a9ab59adfc8e02b7f6a3d42d40a449168031695e3f9f05bb6b501f79c25350a2860
7
- data.tar.gz: 6ec72a4fa10a76c7ed6ff305a93d7a821fa2a002dcf04e27431673ac7c273afee571b90538e64e3ce3f160ad842f77bd9f3521185f8cfd3cdd5f302a2215575f
6
+ metadata.gz: 364d93ef9043a99cc26383d1d6fe5f563fa580b9aaa2b4b7fc733eb4089de5602a66c8c61b002c2e2a7c7c92d6525ced5b12b7e461602a00f402c05a621ac8e8
7
+ data.tar.gz: 90c80537e55f225c5d797684e10472e56f617c6e5c7b3a9edcf237da933966dc82e9a6fa7f5068466e787733871f23811a336591fd32d47107701c355db8686c
data/README.md CHANGED
@@ -8,9 +8,10 @@ It enables you to capture in-coming HTTP requests and out-going HTTP requests an
8
8
  AWS X-Ray is a ditributed tracing system. See more detail about AWS X-Ray at [official document](http://docs.aws.amazon.com/xray/latest/devguide/aws-xray.html).
9
9
 
10
10
  ## Features
11
+ - Propagatin support in both single and multi thread environment.
11
12
  - Rack middleware.
12
13
  - Faraday middleware.
13
- - Propagatin support in both single and multi thread environment.
14
+ - net/http hook.
14
15
  - Tracing HTTP request/response.
15
16
  - Tracing errors.
16
17
  - Annotation and metadata support.
@@ -88,6 +89,35 @@ Aws::Xray.trace(name: 'my-app-batch') do |seg|
88
89
  end
89
90
  ```
90
91
 
92
+ ### Hooks
93
+ You can enable all the hooks with:
94
+
95
+ ```ruby
96
+ # Gemfile
97
+ gem 'aws-xray', require: 'aws/xray/hooks/all'
98
+ ```
99
+
100
+ #### net/http hook
101
+ To monkey patch net/http and records out-going http requests automatically, just require `aws/xray/hooks/net_http`:
102
+
103
+ If you can pass headers for net/http client, you can setup subsegment name via `X-Aws-Xray-Name` header:
104
+
105
+ ```ruby
106
+ Net::HTTP.start(host, port) do |http|
107
+ req = Net::HTTP::Get.new(uri, { 'X-Aws-Xray-Name' => 'target-app' })
108
+ http.request(req)
109
+ end
110
+ ```
111
+
112
+ 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`:
113
+
114
+ ```ruby
115
+ client = Aws::Sns::Client.new
116
+ response = Aws::Xray::Context.current.overwrite(name: 'sns') do
117
+ client.create_topic(...)
118
+ end
119
+ ```
120
+
91
121
  ### Multi threaded environment
92
122
  Tracing context is thread local. To pass current tracing context, copy current tracing context:
93
123
 
@@ -148,7 +148,7 @@ module Aws
148
148
  # CAUTION: the injection will NOT be propagated between threads!!
149
149
  #
150
150
  # @param [String] name
151
- def overwrite_sub_segment(name:)
151
+ def overwrite(name:)
152
152
  @sub_segment_name = name.to_s
153
153
 
154
154
  begin
@@ -0,0 +1 @@
1
+ require 'aws/xray/hooks/net_http'
@@ -4,6 +4,8 @@ module Aws
4
4
  module Xray
5
5
  module Hooks
6
6
  module NetHttp
7
+ NAME_HEADER = 'X-Aws-Xray-Name'.freeze
8
+
7
9
  def request(req, *args)
8
10
  return super unless Context.started?
9
11
  return super if Context.current.disabled?(:net_http)
@@ -18,7 +20,8 @@ module Aws
18
20
  url: uri.to_s,
19
21
  user_agent: req['User-Agent'],
20
22
  )
21
- Context.current.child_trace(remote: true, name: address) do |sub|
23
+ name = req[NAME_HEADER] || req['Host'] || address
24
+ Context.current.child_trace(remote: true, name: name) do |sub|
22
25
  propagate_trace = sub.generate_trace
23
26
  req[TRACE_HEADER] = propagate_trace.to_header_value
24
27
  sub.set_http_request(request_record)
@@ -1,5 +1,5 @@
1
1
  module Aws
2
2
  module Xray
3
- VERSION = '0.14.0'
3
+ VERSION = '0.15.0'
4
4
  end
5
5
  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.14.0
4
+ version: 0.15.0
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/all.rb
147
148
  - lib/aws/xray/hooks/net_http.rb
148
149
  - lib/aws/xray/rack.rb
149
150
  - lib/aws/xray/rails.rb