aws-xray 0.6.1 → 0.7.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: '0976ec151baafd973cfcb253bb8c72ceeceb1425'
4
- data.tar.gz: b91bd7bf26e3fae566c962a4bd5f3a72d316ca1f
3
+ metadata.gz: 2e3c5e5103576cdd8082e34375764847e25f0ba3
4
+ data.tar.gz: fd6877a751905e3387625c230f9f7615a1265035
5
5
  SHA512:
6
- metadata.gz: d2f85373ef66e1faa436030a78e58c3b88ef0b076d941b32c81f0d748b105a7a0a30c8b87241cc6dfafd5c4bbc96663c531282511ee4e53f32626aa0f54beb62
7
- data.tar.gz: 00ad0675fca0043ea74a72579871253aa8780aa1e5dfe99d161466d3722d9f86ffe92c05b70d5caed9bf962d25520909119717c72c120ae22222cec56e9cdfc5
6
+ metadata.gz: 76c31717fe55d97fa6fc548f06f4ca827fd08b60fe61f4c055dc16d85ede43188e2ce1bdc34e8773e0de71a6a6155950c7544424773c72a52e0e3653c653b6db
7
+ data.tar.gz: 2efe2933ccd9ca9cb31e9367115fca96ebdd6ee30f3f9cfb42b0e8689009700f77c129b8cb4d123fba61517741e0cb4f34d3d33674edd01f80e0cf8de9309d30
data/.travis.yml CHANGED
@@ -4,7 +4,6 @@ branches:
4
4
  only:
5
5
  - master
6
6
  rvm:
7
- - 2.1
8
- - 2.2
7
+ - 2.2.7
9
8
  - 2.3
10
9
  - 2.4
data/README.md CHANGED
@@ -98,7 +98,7 @@ end
98
98
  ```
99
99
 
100
100
  ## Configurations
101
- ### Xray agent location
101
+ ### X-Ray agent location
102
102
  In container environments, we often run xray agent container beside application container.
103
103
  For that case, pass `AWS_XRAY_LOCATION` environment variable to container to specify host and port of xray agent.
104
104
 
@@ -106,7 +106,13 @@ For that case, pass `AWS_XRAY_LOCATION` environment variable to container to spe
106
106
  docker run --link xray:xray --env AWS_XRAY_LOCATION=xray:2000 my-application
107
107
  ```
108
108
 
109
- ### Recording pplication version
109
+ ### Excluded paths
110
+ To avoid tracing health checking requests, use "excluded paths" configuration.
111
+
112
+ - Environment variable: `AWS_XRAY_EXCLUDED_PATHS=/health_check,/another_check`
113
+ - Global configuration: `Aws::Xray.config.excluded_paths = %w[/health_check /another_check]`
114
+
115
+ ### Recording application version
110
116
  aws-xray automatically tries to set application version by reading `app_root/REVISION` file.
111
117
  If you want to set another version, set it with:
112
118
 
data/aws-xray.gemspec CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'faraday'
25
25
  spec.add_development_dependency 'bundler'
26
26
  spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rack-test'
27
28
  spec.add_development_dependency 'rspec'
28
29
  spec.add_development_dependency 'pry-byebug'
29
30
  end
@@ -9,8 +9,17 @@ module Aws
9
9
  DEFAULT_HOST = option ? option.split(':').first : 'localhost'
10
10
  DEFAULT_PORT = option ? Integer(option.split(':').last) : 2000
11
11
 
12
+ name_option = ENV['AWS_XRAY_NAME']
13
+ DEFAULT_NAME = name_option ? name_option : nil
14
+
15
+ path_option = ENV['AWS_XRAY_EXCLUDED_PATHS']
16
+ DEFAULT_EXCLUDED_PATHS = path_option ? path_option.split(',') : []
17
+
12
18
  # @return [String] name Logical service name for this application.
13
- attr_accessor :name
19
+ def name
20
+ @name ||= DEFAULT_NAME
21
+ end
22
+ attr_writer :name
14
23
 
15
24
  # @return [Hash] client_options For xray-agent client.
16
25
  # - host: e.g. '127.0.0.1'
@@ -21,6 +30,12 @@ module Aws
21
30
  end
22
31
  attr_writer :client_options
23
32
 
33
+ # @return [Array<String>]
34
+ def excluded_paths
35
+ @excluded_paths ||= DEFAULT_EXCLUDED_PATHS
36
+ end
37
+ attr_writer :excluded_paths
38
+
24
39
  # @return [String]
25
40
  def version
26
41
  @version ||= VersionDetector.new.call
data/lib/aws/xray/rack.rb CHANGED
@@ -8,19 +8,29 @@ module Aws
8
8
  class Rack
9
9
  TRACE_ENV = 'HTTP_X_AMZN_TRACE_ID'.freeze
10
10
 
11
- # TODO: excluded_paths, included_paths
12
- #
13
11
  # @param [Hash] client_options For xray-agent client.
14
12
  # - host: e.g. '127.0.0.1'
15
13
  # - port: e.g. 2000
16
14
  # - sock: test purpose.
17
- def initialize(app, client_options: {})
15
+ # @param [Array<String>] excluded_paths for health-check endpoints etc...
16
+ def initialize(app, client_options: {}, excluded_paths: [])
18
17
  @app = app
19
18
  @name = Aws::Xray.config.name || raise(MissingNameError)
20
19
  @client = Client.new(Aws::Xray.config.client_options.merge(client_options))
20
+ @excluded_paths = excluded_paths + Aws::Xray.config.excluded_paths
21
21
  end
22
22
 
23
23
  def call(env)
24
+ if @excluded_paths.include?(env['PATH_INFO'])
25
+ @app.call(env)
26
+ else
27
+ call_with_tracing(env)
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def call_with_tracing(env)
24
34
  header_value = env[TRACE_ENV]
25
35
  trace = if header_value
26
36
  Trace.build_from_header_value(header_value)
@@ -4,7 +4,15 @@ module Aws
4
4
  module Xray
5
5
  class Railtie < ::Rails::Railtie
6
6
  initializer 'aws-xray.set_name' do |app|
7
- Aws::Xray.config.name = app.class.parent_name.underscore.gsub(/(\/|_)/, '-')
7
+ unless Aws::Xray.config.name
8
+ app_name = app.class.parent_name.underscore.gsub(/(\/|_)/, '-')
9
+
10
+ if Rails.env.production?
11
+ Aws::Xray.config.name = app_name
12
+ else
13
+ Aws::Xray.config.name = "#{app_name}-#{Rails.env}"
14
+ end
15
+ end
8
16
  end
9
17
 
10
18
  initializer 'aws-xray.rack_middleware' do |app|
@@ -78,7 +78,7 @@ module Aws
78
78
  id: @id,
79
79
  trace_id: @trace_id,
80
80
  start_time: @start_time,
81
- annotation: @annotation,
81
+ annotations: @annotation,
82
82
  metadata: @metadata,
83
83
  }
84
84
  if @version
@@ -1,5 +1,5 @@
1
1
  module Aws
2
2
  module Xray
3
- VERSION = '0.6.1'
3
+ VERSION = '0.7.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.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taiki Ono
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement