instana 1.13.0 → 1.193.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +200 -133
  3. data/.editorconfig +10 -0
  4. data/.gitignore +3 -0
  5. data/.rubocop.yml +5 -1147
  6. data/.rubocop_todo.yml +1140 -0
  7. data/Appraisals +100 -0
  8. data/Gemfile +11 -32
  9. data/Rakefile +16 -39
  10. data/bin/console +5 -4
  11. data/gemfiles/.bundle/config +1 -2
  12. data/gemfiles/cuba_30.gemfile +15 -0
  13. data/gemfiles/dalli_20.gemfile +15 -0
  14. data/gemfiles/excon_02.gemfile +15 -0
  15. data/gemfiles/graphql_10.gemfile +15 -0
  16. data/gemfiles/grpc_10.gemfile +15 -0
  17. data/gemfiles/net_http_01.gemfile +14 -0
  18. data/gemfiles/rack_16.gemfile +15 -0
  19. data/gemfiles/rack_20.gemfile +15 -0
  20. data/gemfiles/rails_42.gemfile +18 -0
  21. data/gemfiles/rails_50.gemfile +18 -0
  22. data/gemfiles/rails_52.gemfile +18 -0
  23. data/gemfiles/rails_60.gemfile +18 -0
  24. data/gemfiles/redis_40.gemfile +15 -0
  25. data/gemfiles/resque_122.gemfile +16 -0
  26. data/gemfiles/resque_20.gemfile +15 -0
  27. data/gemfiles/rest_client_16.gemfile +15 -0
  28. data/gemfiles/rest_client_20.gemfile +15 -0
  29. data/gemfiles/roda_20.gemfile +15 -0
  30. data/gemfiles/roda_30.gemfile +15 -0
  31. data/gemfiles/sidekiq_42.gemfile +15 -0
  32. data/gemfiles/sidekiq_50.gemfile +15 -0
  33. data/gemfiles/sinatra_14.gemfile +15 -0
  34. data/instana.gemspec +1 -7
  35. data/lib/instana/activator.rb +41 -0
  36. data/lib/instana/activators/action_controller_api.rb +18 -0
  37. data/lib/instana/activators/action_controller_base.rb +18 -0
  38. data/lib/instana/activators/action_view.rb +18 -0
  39. data/lib/instana/activators/active_record.rb +18 -0
  40. data/lib/instana/activators/cuba.rb +18 -0
  41. data/lib/instana/activators/dalli.rb +20 -0
  42. data/lib/instana/activators/excon.rb +17 -0
  43. data/lib/instana/activators/graphql.rb +19 -0
  44. data/lib/instana/activators/grpc_client.rb +17 -0
  45. data/lib/instana/activators/grpc_server.rb +17 -0
  46. data/lib/instana/activators/net_http.rb +17 -0
  47. data/lib/instana/activators/rack.rb +13 -0
  48. data/lib/instana/activators/rails.rb +15 -0
  49. data/lib/instana/activators/redis.rb +17 -0
  50. data/lib/instana/activators/resque_client.rb +18 -0
  51. data/lib/instana/activators/resque_worker.rb +30 -0
  52. data/lib/instana/activators/rest_client.rb +17 -0
  53. data/lib/instana/activators/roda.rb +18 -0
  54. data/lib/instana/activators/sidekiq_client.rb +21 -0
  55. data/lib/instana/activators/sidekiq_worker.rb +21 -0
  56. data/lib/instana/activators/sinatra.rb +18 -0
  57. data/lib/instana/config.rb +11 -0
  58. data/lib/instana/frameworks/cuba.rb +6 -13
  59. data/lib/instana/frameworks/rails.rb +20 -33
  60. data/lib/instana/frameworks/roda.rb +7 -13
  61. data/lib/instana/frameworks/sinatra.rb +1 -8
  62. data/lib/instana/instrumentation/action_controller.rb +81 -0
  63. data/lib/instana/instrumentation/action_view.rb +27 -0
  64. data/lib/instana/instrumentation/active_record.rb +47 -0
  65. data/lib/instana/instrumentation/dalli.rb +7 -18
  66. data/lib/instana/instrumentation/excon.rb +51 -57
  67. data/lib/instana/instrumentation/graphql.rb +75 -0
  68. data/lib/instana/instrumentation/grpc.rb +70 -66
  69. data/lib/instana/instrumentation/instrumented_request.rb +69 -0
  70. data/lib/instana/instrumentation/net-http.rb +43 -47
  71. data/lib/instana/instrumentation/rack.rb +14 -53
  72. data/lib/instana/instrumentation/redis.rb +10 -18
  73. data/lib/instana/instrumentation/resque.rb +14 -50
  74. data/lib/instana/instrumentation/rest-client.rb +2 -17
  75. data/lib/instana/instrumentation/sidekiq-client.rb +0 -9
  76. data/lib/instana/instrumentation/sidekiq-worker.rb +0 -9
  77. data/lib/instana/secrets.rb +7 -7
  78. data/lib/instana/setup.rb +3 -1
  79. data/lib/instana/tracer.rb +6 -0
  80. data/lib/instana/tracing/span.rb +14 -10
  81. data/lib/instana/util.rb +15 -69
  82. data/lib/instana/version.rb +1 -1
  83. data/test/activator_test.rb +27 -0
  84. data/test/frameworks/cuba_test.rb +38 -40
  85. data/test/frameworks/roda_test.rb +39 -41
  86. data/test/frameworks/sinatra_test.rb +61 -64
  87. data/test/instrumentation/excon_test.rb +1 -2
  88. data/test/instrumentation/graphql_test.rb +116 -0
  89. data/test/instrumentation/grpc_test.rb +2 -1
  90. data/test/instrumentation/{net-http_test.rb → net_http_test.rb} +1 -0
  91. data/test/instrumentation/rack_instrumented_request_test.rb +84 -0
  92. data/test/{frameworks → instrumentation}/rack_test.rb +32 -20
  93. data/test/{frameworks/rails/actioncontroller_test.rb → instrumentation/rails_action_controller_test.rb} +37 -21
  94. data/test/instrumentation/rails_action_view_test.rb +138 -0
  95. data/test/instrumentation/rails_active_record_test.rb +121 -0
  96. data/test/instrumentation/redis_test.rb +10 -0
  97. data/test/instrumentation/resque_test.rb +3 -11
  98. data/test/instrumentation/{rest-client_test.rb → rest_client_test.rb} +6 -0
  99. data/test/instrumentation/sidekiq-client_test.rb +1 -0
  100. data/test/instrumentation/sidekiq-worker_test.rb +1 -0
  101. data/test/support/apps/active_record/active_record.rb +21 -0
  102. data/test/{servers/grpc_50051.rb → support/apps/grpc/boot.rb} +1 -1
  103. data/test/{apps → support/apps/grpc}/grpc_server.rb +0 -0
  104. data/test/{servers/rackapp_6511.rb → support/apps/http_endpoint/boot.rb} +0 -0
  105. data/test/{servers/rails_3205.rb → support/apps/rails/boot.rb} +8 -14
  106. data/test/{models → support/apps/rails/models}/block.rb +1 -1
  107. data/test/{models → support/apps/rails/models}/block6.rb +0 -0
  108. data/test/support/apps/resque/boot.rb +2 -0
  109. data/test/{jobs → support/apps/resque/jobs}/resque_error_job.rb +0 -0
  110. data/test/{jobs → support/apps/resque/jobs}/resque_fast_job.rb +0 -0
  111. data/test/support/apps/sidekiq/boot.rb +21 -0
  112. data/test/{jobs → support/apps/sidekiq/jobs}/sidekiq_job_1.rb +0 -0
  113. data/test/{jobs → support/apps/sidekiq/jobs}/sidekiq_job_2.rb +0 -0
  114. data/test/{servers → support/apps}/sidekiq/worker.rb +2 -2
  115. data/test/support/helpers.rb +94 -0
  116. data/test/test_helper.rb +24 -144
  117. data/test/tracing/id_management_test.rb +4 -66
  118. metadata +106 -95
  119. data/gemfiles/libraries.gemfile +0 -71
  120. data/gemfiles/rails32.gemfile +0 -51
  121. data/gemfiles/rails42.gemfile +0 -50
  122. data/gemfiles/rails50.gemfile +0 -52
  123. data/gemfiles/rails52.gemfile +0 -52
  124. data/gemfiles/rails60.gemfile +0 -72
  125. data/lib/instana/frameworks/instrumentation/abstract_mysql_adapter.rb +0 -58
  126. data/lib/instana/frameworks/instrumentation/action_controller.rb +0 -194
  127. data/lib/instana/frameworks/instrumentation/action_view.rb +0 -43
  128. data/lib/instana/frameworks/instrumentation/active_record.rb +0 -27
  129. data/lib/instana/frameworks/instrumentation/mysql2_adapter.rb +0 -81
  130. data/lib/instana/frameworks/instrumentation/mysql_adapter.rb +0 -56
  131. data/lib/instana/frameworks/instrumentation/postgresql_adapter.rb +0 -85
  132. data/lib/instana/instrumentation.rb +0 -25
  133. data/lib/instana/test.rb +0 -43
  134. data/test/apps/cuba.rb +0 -19
  135. data/test/apps/roda.rb +0 -13
  136. data/test/apps/sinatra.rb +0 -9
  137. data/test/frameworks/rails/actionview3_test.rb +0 -210
  138. data/test/frameworks/rails/actionview4_test.rb +0 -208
  139. data/test/frameworks/rails/actionview5_test.rb +0 -221
  140. data/test/frameworks/rails/activerecord_test.rb +0 -227
  141. data/test/servers/helpers/sidekiq_worker_initializer.rb +0 -27
@@ -34,12 +34,3 @@ module Instana
34
34
  end
35
35
  end
36
36
  end
37
-
38
- if defined?(::Sidekiq) && ::Instana.config[:'sidekiq-client'][:enabled]
39
- ::Sidekiq.configure_client do |cfg|
40
- cfg.client_middleware do |chain|
41
- ::Instana.logger.debug "Instrumenting Sidekiq client"
42
- chain.add ::Instana::Instrumentation::SidekiqClient
43
- end
44
- end
45
- end
@@ -43,12 +43,3 @@ module Instana
43
43
  end
44
44
  end
45
45
  end
46
-
47
- if defined?(::Sidekiq) && ::Instana.config[:'sidekiq-worker'][:enabled]
48
- ::Sidekiq.configure_server do |cfg|
49
- cfg.server_middleware do |chain|
50
- ::Instana.logger.debug "Instrumenting Sidekiq worker"
51
- chain.add ::Instana::Instrumentation::SidekiqWorker
52
- end
53
- end
54
- end
@@ -2,25 +2,25 @@ require 'uri'
2
2
  require 'cgi'
3
3
 
4
4
  module Instana
5
- class Secrets
5
+ class Secrets
6
6
  def remove_from_query(str, secret_values = Instana.agent.secret_values)
7
7
  return str unless secret_values
8
-
8
+
9
9
  url = URI(str)
10
- params = CGI.parse(url.query)
11
-
10
+ params = CGI.parse(url.query || '')
11
+
12
12
  redacted = params.map do |k, v|
13
13
  needs_redaction = secret_values['list']
14
14
  .any? { |t| matcher(secret_values['matcher']).(t,k) }
15
15
  [k, needs_redaction ? '<redacted>' : v]
16
16
  end
17
-
17
+
18
18
  url.query = URI.encode_www_form(redacted)
19
19
  CGI.unescape(url.to_s)
20
20
  end
21
-
21
+
22
22
  private
23
-
23
+
24
24
  def matcher(name)
25
25
  case name
26
26
  when 'equals-ignore-case'
data/lib/instana/setup.rb CHANGED
@@ -7,10 +7,12 @@ require "instana/collector"
7
7
  require "instana/secrets"
8
8
  require "instana/tracer"
9
9
  require "instana/tracing/processor"
10
- require "instana/instrumentation"
10
+
11
+ require 'instana/activator'
11
12
 
12
13
  ::Instana.setup
13
14
  ::Instana.agent.setup
15
+ ::Instana::Activator.start
14
16
 
15
17
  # Register the metric collectors
16
18
  unless RUBY_PLATFORM == 'java'.freeze
@@ -100,6 +100,12 @@ module Instana
100
100
  else
101
101
  self.current_span = Span.new(name)
102
102
  end
103
+
104
+ if incoming_context.is_a?(Hash) && incoming_context[:correlation] && !incoming_context[:correlation].empty?
105
+ self.current_span[:crid] = incoming_context[:correlation][:id]
106
+ self.current_span[:crtp] = incoming_context[:correlation][:type]
107
+ end
108
+
103
109
  self.current_span.set_tags(kvs) unless kvs.empty?
104
110
  self.current_span
105
111
  end
@@ -3,8 +3,8 @@ module Instana
3
3
  REGISTERED_SPANS = [ :actioncontroller, :actionview, :activerecord, :excon,
4
4
  :memcache, :'net-http', :rack, :render, :'rpc-client',
5
5
  :'rpc-server', :'sidekiq-client', :'sidekiq-worker',
6
- :redis, :'resque-client', :'resque-worker' ].freeze
7
- ENTRY_SPANS = [ :rack, :'resque-worker', :'rpc-server', :'sidekiq-worker' ].freeze
6
+ :redis, :'resque-client', :'resque-worker', :'graphql.server' ].freeze
7
+ ENTRY_SPANS = [ :rack, :'resque-worker', :'rpc-server', :'sidekiq-worker', :'graphql.server' ].freeze
8
8
  EXIT_SPANS = [ :activerecord, :excon, :'net-http', :'resque-client',
9
9
  :'rpc-client', :'sidekiq-client', :redis ].freeze
10
10
  HTTP_SPANS = [ :rack, :excon, :'net-http' ].freeze
@@ -57,9 +57,6 @@ module Instana
57
57
  end
58
58
 
59
59
  if ::Instana.config[:collect_backtraces]
60
- # For entry spans, add a backtrace fingerprint
61
- add_stack(limit: 2) if ENTRY_SPANS.include?(name)
62
-
63
60
  # Attach a backtrace to all exit spans
64
61
  add_stack if EXIT_SPANS.include?(name)
65
62
  end
@@ -76,9 +73,11 @@ module Instana
76
73
  #
77
74
  # @param limit [Integer] Limit the backtrace to the top <limit> frames
78
75
  #
79
- def add_stack(limit: nil, stack: Kernel.caller)
76
+ def add_stack(limit: 30, stack: Kernel.caller)
80
77
  frame_count = 0
78
+ sanitized_stack = []
81
79
  @data[:stack] = []
80
+ limit = 40 if limit > 40
82
81
 
83
82
  stack.each do |i|
84
83
  # If the stack has the full instana gem version in it's path
@@ -86,18 +85,23 @@ module Instana
86
85
  if !i.match(/instana\/instrumentation\/rack.rb/).nil? ||
87
86
  (i.match(::Instana::VERSION_FULL).nil? && i.match('lib/instana/').nil?)
88
87
 
89
- break if limit && frame_count >= limit
90
-
91
88
  x = i.split(':')
92
89
 
93
- @data[:stack] << {
90
+ sanitized_stack << {
94
91
  :c => x[0],
95
92
  :n => x[1],
96
93
  :m => x[2]
97
94
  }
98
- frame_count = frame_count + 1 if limit
99
95
  end
100
96
  end
97
+
98
+ if sanitized_stack.length > limit
99
+ # (limit * -1) gives us negative form of <limit> used for
100
+ # slicing from the end of the list. e.g. stack[-30, 30]
101
+ @data[:stack] = sanitized_stack[limit*-1, limit]
102
+ else
103
+ @data[:stack] = sanitized_stack
104
+ end
101
105
  end
102
106
 
103
107
  # Log an error into the span
data/lib/instana/util.rb CHANGED
@@ -2,46 +2,6 @@ module Instana
2
2
  module Util
3
3
  class << self
4
4
  ID_RANGE = -2**63..2**63-1
5
-
6
- # An agnostic approach to method aliasing.
7
- #
8
- # @param klass [Object] The class or module that holds the method to be alias'd.
9
- # @param method [Symbol] The name of the method to be aliased.
10
- #
11
- def method_alias(klass, method)
12
- if klass.method_defined?(method.to_sym) ||
13
- klass.private_method_defined?(method.to_sym)
14
-
15
- with = "#{method}_with_instana"
16
- without = "#{method}_without_instana"
17
-
18
- klass.class_eval do
19
- alias_method without, method.to_s
20
- alias_method method.to_s, with
21
- end
22
- else
23
- ::Instana.logger.debug "No such method (#{method}) to alias on #{klass}"
24
- end
25
- end
26
-
27
- # Calls on target_class to 'extend' cls
28
- #
29
- # @param target_cls [Object] the class/module to do the 'extending'
30
- # @param cls [Object] the class/module to be 'extended'
31
- #
32
- def send_extend(target_cls, cls)
33
- target_cls.send(:extend, cls) if defined?(target_cls)
34
- end
35
-
36
- # Calls on <target_cls> to include <cls> into itself.
37
- #
38
- # @param target_cls [Object] the class/module to do the 'including'
39
- # @param cls [Object] the class/module to be 'included'
40
- #
41
- def send_include(target_cls, cls)
42
- target_cls.send(:include, cls) if defined?(target_cls)
43
- end
44
-
45
5
  # Debugging helper method
46
6
  #
47
7
  def pry!
@@ -225,53 +185,39 @@ module Instana
225
185
  (time.to_f * 1000).floor
226
186
  end
227
187
 
228
- # Generate a random 64bit ID
188
+ # Generate a random 64bit/128bit ID
189
+ #
190
+ # @param size [Integer] Number of 64 bit integers used to generate the id
229
191
  #
230
- # @return [Integer] a random 64bit integer
192
+ # @return [String] a random 64bit/128bit hex encoded string
231
193
  #
232
- def generate_id
233
- # Max value is 9223372036854775807 (signed long in Java)
234
- rand(ID_RANGE)
194
+ def generate_id(size = 1)
195
+ Array.new(size) { rand(ID_RANGE) }
196
+ .pack('q>*')
197
+ .unpack('H*')
198
+ .first
235
199
  end
236
200
 
237
201
  # Convert an ID to a value appropriate to pass in a header.
238
202
  #
239
- # @param id [Integer] the id to be converted
203
+ # @param id [String] the id to be converted
240
204
  #
241
205
  # @return [String]
242
206
  #
243
207
  def id_to_header(id)
244
- unless id.is_a?(Integer) || id.is_a?(String)
245
- Instana.logger.debug "id_to_header received a #{id.class}: returning empty string"
246
- return String.new
247
- end
248
- [id.to_i].pack('q>').unpack('H*')[0].gsub(/^0+/, '')
249
- rescue => e
250
- Instana.logger.info "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
251
- Instana.logger.debug { e.backtrace.join("\r\n") }
208
+ return '' unless id.is_a?(String)
209
+ # Only send 64bit IDs downstream for now
210
+ id.length == 32 ? id[16..-1] : id
252
211
  end
253
212
 
254
213
  # Convert a received header value into a valid ID
255
214
  #
256
215
  # @param header_id [String] the header value to be converted
257
216
  #
258
- # @return [Integer]
217
+ # @return [String]
259
218
  #
260
219
  def header_to_id(header_id)
261
- if !header_id.is_a?(String)
262
- Instana.logger.debug "header_to_id received a #{header_id.class}: returning 0"
263
- return 0
264
- end
265
- if header_id.length < 16
266
- # The header is less than 16 chars. Prepend
267
- # zeros so we can convert correctly
268
- missing = 16 - header_id.length
269
- header_id = ("0" * missing) + header_id
270
- end
271
- [header_id].pack("H*").unpack("q>")[0]
272
- rescue => e
273
- Instana.logger.info "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
274
- Instana.logger.debug { e.backtrace.join("\r\n") }
220
+ header_id.is_a?(String) && header_id.match(/\A[a-z\d]{16,32}\z/i) ? header_id : ''
275
221
  end
276
222
  end
277
223
  end
@@ -1,4 +1,4 @@
1
1
  module Instana
2
- VERSION = "1.13.0"
2
+ VERSION = "1.193.3"
3
3
  VERSION_FULL = "instana-#{VERSION}"
4
4
  end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ class ActivatorTest < Minitest::Test
4
+ def test_start
5
+ refute_nil Instana::Activator.trace_point
6
+ assert Instana::Activator.trace_point.enabled?
7
+ end
8
+
9
+ def test_klass_call
10
+ assert_equal [], Instana::Activator.call
11
+ end
12
+
13
+ def test_instance_call
14
+ subject = Class.new(Instana::Activator) do
15
+ def can_instrument?
16
+ true
17
+ end
18
+
19
+ def instrument
20
+ true
21
+ end
22
+ end
23
+
24
+ assert_equal 1, Instana::Activator.call.length
25
+ assert subject.call
26
+ end
27
+ end
@@ -1,57 +1,55 @@
1
- if defined?(::Cuba)
2
- require 'test_helper'
3
- require File.expand_path(File.dirname(__FILE__) + '/../apps/cuba')
4
- require 'rack/test'
1
+ require 'test_helper'
2
+ require 'rack/test'
5
3
 
6
- class CubaTest < Minitest::Test
7
- include Rack::Test::Methods
4
+ class CubaTest < Minitest::Test
5
+ include Rack::Test::Methods
6
+ APP = Rack::Builder.parse_file('test/support/apps/cuba/config.ru').first
8
7
 
9
- def app
10
- Cuba
11
- end
8
+ def app
9
+ APP
10
+ end
12
11
 
13
- def test_basic_get
14
- clear_all!
12
+ def test_basic_get
13
+ clear_all!
15
14
 
16
- r = get '/hello'
17
- assert last_response.ok?
15
+ r = get '/hello'
16
+ assert last_response.ok?
18
17
 
19
- assert r.headers.key?("X-Instana-T")
20
- assert r.headers.key?("X-Instana-S")
18
+ assert r.headers.key?("X-Instana-T")
19
+ assert r.headers.key?("X-Instana-S")
21
20
 
22
- spans = ::Instana.processor.queued_spans
23
- assert_equal 1, spans.count
21
+ spans = ::Instana.processor.queued_spans
22
+ assert_equal 1, spans.count
24
23
 
25
- first_span = spans.first
26
- assert_equal :rack, first_span[:n]
27
- assert first_span.key?(:data)
28
- assert first_span[:data].key?(:http)
24
+ first_span = spans.first
25
+ assert_equal :rack, first_span[:n]
26
+ assert first_span.key?(:data)
27
+ assert first_span[:data].key?(:http)
29
28
 
30
- assert first_span[:data][:http].key?(:method)
31
- assert_equal "GET", first_span[:data][:http][:method]
29
+ assert first_span[:data][:http].key?(:method)
30
+ assert_equal "GET", first_span[:data][:http][:method]
32
31
 
33
- assert first_span[:data][:http].key?(:url)
34
- assert_equal "/hello", first_span[:data][:http][:url]
32
+ assert first_span[:data][:http].key?(:url)
33
+ assert_equal "/hello", first_span[:data][:http][:url]
35
34
 
36
- assert first_span[:data][:http].key?(:status)
37
- assert_equal 200, first_span[:data][:http][:status]
35
+ assert first_span[:data][:http].key?(:status)
36
+ assert_equal 200, first_span[:data][:http][:status]
38
37
 
39
- assert first_span[:data][:http].key?(:host)
40
- assert_equal "example.org", first_span[:data][:http][:host]
41
- end
38
+ assert first_span[:data][:http].key?(:host)
39
+ assert_equal "example.org", first_span[:data][:http][:host]
40
+ end
42
41
 
43
- def test_path_template
44
- clear_all!
42
+ def test_path_template
43
+ clear_all!
45
44
 
46
- r = get '/greet/instana'
47
- assert last_response.ok?
45
+ r = get '/greet/instana'
46
+ assert last_response.ok?
48
47
 
49
- spans = ::Instana.processor.queued_spans
50
- assert_equal 1, spans.count
48
+ spans = ::Instana.processor.queued_spans
49
+ assert_equal 1, spans.count
51
50
 
52
- first_span = spans.first
53
- assert_equal :rack, first_span[:n]
54
- assert_equal '/greet/{name}', first_span[:data][:http][:path_tpl]
55
- end
51
+ first_span = spans.first
52
+ assert_equal :rack, first_span[:n]
53
+ assert_equal '/greet/{name}', first_span[:data][:http][:path_tpl]
56
54
  end
57
55
  end
@@ -1,58 +1,56 @@
1
1
 
2
- if defined?(::Roda)
3
- require 'test_helper'
4
- require File.expand_path(File.dirname(__FILE__) + '/../apps/roda')
5
- require 'rack/test'
2
+ require 'test_helper'
3
+ require 'rack/test'
6
4
 
7
- class RodaTest < Minitest::Test
8
- include Rack::Test::Methods
5
+ class RodaTest < Minitest::Test
6
+ include Rack::Test::Methods
7
+ APP = Rack::Builder.parse_file('test/support/apps/roda/config.ru').first
9
8
 
10
- def app
11
- InstanaRodaApp
12
- end
9
+ def app
10
+ APP
11
+ end
12
+
13
+ def test_basic_get
14
+ clear_all!
13
15
 
14
- def test_basic_get
15
- clear_all!
16
+ r = get '/hello'
17
+ assert last_response.ok?
16
18
 
17
- r = get '/hello'
18
- assert last_response.ok?
19
+ assert r.headers.key?("X-Instana-T")
20
+ assert r.headers.key?("X-Instana-S")
19
21
 
20
- assert r.headers.key?("X-Instana-T")
21
- assert r.headers.key?("X-Instana-S")
22
+ spans = ::Instana.processor.queued_spans
23
+ assert_equal 1, spans.count
22
24
 
23
- spans = ::Instana.processor.queued_spans
24
- assert_equal 1, spans.count
25
+ first_span = spans.first
26
+ assert_equal :rack, first_span[:n]
27
+ assert first_span.key?(:data)
28
+ assert first_span[:data].key?(:http)
25
29
 
26
- first_span = spans.first
27
- assert_equal :rack, first_span[:n]
28
- assert first_span.key?(:data)
29
- assert first_span[:data].key?(:http)
30
+ assert first_span[:data][:http].key?(:method)
31
+ assert_equal "GET", first_span[:data][:http][:method]
30
32
 
31
- assert first_span[:data][:http].key?(:method)
32
- assert_equal "GET", first_span[:data][:http][:method]
33
+ assert first_span[:data][:http].key?(:url)
34
+ assert_equal "/hello", first_span[:data][:http][:url]
33
35
 
34
- assert first_span[:data][:http].key?(:url)
35
- assert_equal "/hello", first_span[:data][:http][:url]
36
+ assert first_span[:data][:http].key?(:status)
37
+ assert_equal 200, first_span[:data][:http][:status]
36
38
 
37
- assert first_span[:data][:http].key?(:status)
38
- assert_equal 200, first_span[:data][:http][:status]
39
+ assert first_span[:data][:http].key?(:host)
40
+ assert_equal "example.org", first_span[:data][:http][:host]
41
+ end
39
42
 
40
- assert first_span[:data][:http].key?(:host)
41
- assert_equal "example.org", first_span[:data][:http][:host]
42
- end
43
-
44
- def test_path_template
45
- clear_all!
43
+ def test_path_template
44
+ clear_all!
46
45
 
47
- r = get '/greet/instana'
48
- assert last_response.ok?
46
+ r = get '/greet/instana'
47
+ assert last_response.ok?
49
48
 
50
- spans = ::Instana.processor.queued_spans
51
- assert_equal 1, spans.count
49
+ spans = ::Instana.processor.queued_spans
50
+ assert_equal 1, spans.count
52
51
 
53
- first_span = spans.first
54
- assert_equal :rack, first_span[:n]
55
- assert_equal '/greet/{name}', first_span[:data][:http][:path_tpl]
56
- end
52
+ first_span = spans.first
53
+ assert_equal :rack, first_span[:n]
54
+ assert_equal '/greet/{name}', first_span[:data][:http][:path_tpl]
57
55
  end
58
56
  end