appoptics_apm 4.0.3 → 4.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile_test +6 -7
  3. data/README.md +3 -3
  4. data/Rakefile +3 -2
  5. data/appoptics_apm.gemspec +2 -2
  6. data/docker-compose.yml +0 -22
  7. data/ext/oboe_metal/extconf.rb +4 -0
  8. data/lib/appoptics_apm/config.rb +11 -6
  9. data/lib/appoptics_apm/version.rb +1 -1
  10. metadata +3 -202
  11. data/gemfiles/delayed_job.gemfile +0 -36
  12. data/gemfiles/frameworks.gemfile +0 -44
  13. data/gemfiles/instrumentation_mocked.gemfile +0 -29
  14. data/gemfiles/libraries.gemfile +0 -85
  15. data/gemfiles/noop.gemfile +0 -17
  16. data/gemfiles/rails23.gemfile +0 -39
  17. data/gemfiles/rails30.gemfile +0 -42
  18. data/gemfiles/rails31.gemfile +0 -44
  19. data/gemfiles/rails32.gemfile +0 -54
  20. data/gemfiles/rails40.gemfile +0 -27
  21. data/gemfiles/rails41.gemfile +0 -27
  22. data/gemfiles/rails42.gemfile +0 -35
  23. data/gemfiles/rails50.gemfile +0 -44
  24. data/gemfiles/rails51.gemfile +0 -44
  25. data/test/benchmark/README.md +0 -65
  26. data/test/benchmark/logging_bench.rb +0 -54
  27. data/test/benchmark/with_libraries_gemfile/bunny_bench.rb +0 -69
  28. data/test/benchmark/with_rails5x_gemfile/action_controller5x_bench.rb +0 -43
  29. data/test/frameworks/apps/grape_nested.rb +0 -33
  30. data/test/frameworks/apps/grape_simple.rb +0 -80
  31. data/test/frameworks/apps/padrino_simple.rb +0 -80
  32. data/test/frameworks/apps/sinatra_simple.rb +0 -55
  33. data/test/frameworks/grape_test.rb +0 -286
  34. data/test/frameworks/padrino_test.rb +0 -222
  35. data/test/frameworks/rails3x_test.rb +0 -554
  36. data/test/frameworks/rails4x_test.rb +0 -570
  37. data/test/frameworks/rails5x_api_test.rb +0 -210
  38. data/test/frameworks/rails5x_test.rb +0 -376
  39. data/test/frameworks/rails_shared_tests.rb +0 -172
  40. data/test/frameworks/sinatra_test.rb +0 -140
  41. data/test/instrumentation/bunny_client_test.rb +0 -276
  42. data/test/instrumentation/bunny_consumer_test.rb +0 -204
  43. data/test/instrumentation/curb_test.rb +0 -398
  44. data/test/instrumentation/dalli_test.rb +0 -177
  45. data/test/instrumentation/em_http_request_test.rb +0 -89
  46. data/test/instrumentation/excon_test.rb +0 -231
  47. data/test/instrumentation/faraday_test.rb +0 -228
  48. data/test/instrumentation/http_test.rb +0 -143
  49. data/test/instrumentation/httpclient_test.rb +0 -304
  50. data/test/instrumentation/memcache_test.rb +0 -260
  51. data/test/instrumentation/memcached_test.rb +0 -229
  52. data/test/instrumentation/mongo_v1_test.rb +0 -479
  53. data/test/instrumentation/mongo_v2_index_test.rb +0 -124
  54. data/test/instrumentation/mongo_v2_test.rb +0 -584
  55. data/test/instrumentation/mongo_v2_view_test.rb +0 -435
  56. data/test/instrumentation/moped_test.rb +0 -517
  57. data/test/instrumentation/rack_test.rb +0 -165
  58. data/test/instrumentation/redis_hashes_test.rb +0 -268
  59. data/test/instrumentation/redis_keys_test.rb +0 -321
  60. data/test/instrumentation/redis_lists_test.rb +0 -310
  61. data/test/instrumentation/redis_misc_test.rb +0 -163
  62. data/test/instrumentation/redis_sets_test.rb +0 -296
  63. data/test/instrumentation/redis_sortedsets_test.rb +0 -328
  64. data/test/instrumentation/redis_strings_test.rb +0 -349
  65. data/test/instrumentation/resque_test.rb +0 -185
  66. data/test/instrumentation/rest-client_test.rb +0 -288
  67. data/test/instrumentation/sequel_mysql2_test.rb +0 -353
  68. data/test/instrumentation/sequel_mysql_test.rb +0 -334
  69. data/test/instrumentation/sequel_pg_test.rb +0 -336
  70. data/test/instrumentation/sidekiq-client_test.rb +0 -159
  71. data/test/instrumentation/sidekiq-worker_test.rb +0 -180
  72. data/test/instrumentation/twitter-cassandra_test.rb +0 -424
  73. data/test/instrumentation/typhoeus_test.rb +0 -284
  74. data/test/jobs/delayed_job/db_worker_job.rb +0 -29
  75. data/test/jobs/delayed_job/error_worker_job.rb +0 -10
  76. data/test/jobs/delayed_job/remote_call_worker_job.rb +0 -20
  77. data/test/jobs/resque/db_worker_job.rb +0 -29
  78. data/test/jobs/resque/error_worker_job.rb +0 -10
  79. data/test/jobs/resque/remote_call_worker_job.rb +0 -20
  80. data/test/jobs/sidekiq/db_worker_job.rb +0 -29
  81. data/test/jobs/sidekiq/error_worker_job.rb +0 -10
  82. data/test/jobs/sidekiq/remote_call_worker_job.rb +0 -20
  83. data/test/minitest_helper.rb +0 -277
  84. data/test/mocked/curb_mocked_test.rb +0 -324
  85. data/test/mocked/excon_mocked_test.rb +0 -174
  86. data/test/mocked/faraday_mocked_test.rb +0 -97
  87. data/test/mocked/http_mocked_test.rb +0 -135
  88. data/test/mocked/httpclient_mocked_test.rb +0 -258
  89. data/test/mocked/rest_client_mocked_test.rb +0 -109
  90. data/test/mocked/typhoeus_mocked_test.rb +0 -207
  91. data/test/models/widget.rb +0 -36
  92. data/test/noop/noop_test.rb +0 -145
  93. data/test/profiling/legacy_method_profiling_test.rb +0 -201
  94. data/test/profiling/method_profiling_test.rb +0 -631
  95. data/test/queues/delayed_job-client_test.rb +0 -95
  96. data/test/queues/delayed_job-worker_test.rb +0 -91
  97. data/test/reporter/reporter_test.rb +0 -14
  98. data/test/servers/delayed_job.rb +0 -107
  99. data/test/servers/rackapp_8101.rb +0 -29
  100. data/test/servers/rails3x_8140.rb +0 -96
  101. data/test/servers/rails4x_8140.rb +0 -96
  102. data/test/servers/rails5x_8140.rb +0 -95
  103. data/test/servers/rails5x_api_8150.rb +0 -78
  104. data/test/servers/sidekiq.rb +0 -29
  105. data/test/servers/sidekiq.yml +0 -7
  106. data/test/servers/sidekiq_initializer.rb +0 -25
  107. data/test/settings +0 -0
  108. data/test/support/auto_tracing_test.rb +0 -50
  109. data/test/support/backcompat_test.rb +0 -276
  110. data/test/support/config_test.rb +0 -149
  111. data/test/support/dnt_test.rb +0 -98
  112. data/test/support/init_report_test.rb +0 -25
  113. data/test/support/liboboe_settings_test.rb +0 -110
  114. data/test/support/logging_test.rb +0 -130
  115. data/test/support/sql_sanitize_test.rb +0 -55
  116. data/test/support/tracing_mode_test.rb +0 -33
  117. data/test/support/tvalias_test.rb +0 -15
  118. data/test/support/xtrace_test.rb +0 -41
@@ -1,20 +0,0 @@
1
- # Copyright (c) 2016 SolarWinds, LLC.
2
- # All rights reserved.
3
-
4
- class RemoteCallWorkerJob
5
- include Sidekiq::Worker
6
-
7
- def perform(*args)
8
- # Make some random Dalli (memcache) calls and top it
9
- # off with an excon call to the background rack webserver.
10
- @dc = Dalli::Client.new
11
- @dc.get(rand(10).to_s)
12
- uri = URI('http://gameface.in/gamers')
13
- http = Net::HTTP.new(uri.host, uri.port)
14
- request = Net::HTTP::Get.new(uri.request_uri)
15
- http.request(request)
16
- @dc.get(rand(10).to_s)
17
- @dc.get(rand(10).to_s)
18
- @dc.get_multi([:one, :two, :three, :four, :five, :six])
19
- end
20
- end
@@ -1,277 +0,0 @@
1
- # Copyright (c) 2016 SolarWinds, LLC.
2
- # All rights reserved.
3
-
4
- require 'rubygems'
5
- require 'bundler/setup'
6
- require 'minitest/spec'
7
- require 'minitest/autorun'
8
- require 'minitest/reporters'
9
- require 'minitest/debugger' if ENV['DEBUG']
10
-
11
- if ENV['TEST_RUNS_TO_FILE']
12
- # write to STDOUT as well as file (comes in handy with docker runs)
13
- FileUtils.mkdir_p('log') # create if it doesn't exist
14
- $out_file = File.new("log/test_runs_#{Time.now.strftime("%Y_%m_%d")}.log", 'a')
15
- $out_file.sync = true
16
- $stdout.sync = true
17
- def $stdout.write string
18
- $out_file.write string
19
- super
20
- end
21
- end
22
-
23
- puts "\n\033[1m=== TEST RUN: #{ENV['RVM_TEST']} #{ENV['BUNDLE_GEMFILE']} #{Time.now.strftime("%Y-%m-%d %H:%M")} ===\033[0m\n"
24
-
25
- ENV['RACK_ENV'] = 'test'
26
- ENV['APPOPTICS_GEM_TEST'] = 'true'
27
-
28
- #
29
- # ENV['APPOPTICS_GEM_VERBOSE'] = 'true'
30
-
31
- # FIXME: Temp hack to fix padrino-core calling RUBY_ENGINE when it's not defined under Ruby 1.9.3
32
- RUBY_ENGINE = 'ruby' unless defined?(RUBY_ENGINE)
33
-
34
- Minitest::Spec.new 'pry'
35
-
36
- MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
37
-
38
- if defined?(JRUBY_VERSION)
39
- ENV['JAVA_OPTS'] = "-J-javaagent:/usr/local/tracelytics/tracelyticsagent.jar"
40
- end
41
-
42
- Bundler.require(:default, :test)
43
-
44
- # Configure AppOpticsAPM
45
- AppOpticsAPM::Config[:verbose] = true
46
- AppOpticsAPM::Config[:tracing_mode] = "always"
47
- AppOpticsAPM::Config[:sample_rate] = 1000000
48
- AppOpticsAPM.logger.level = Logger::DEBUG
49
-
50
- # Pre-create test databases (see also .travis.yml)
51
- # puts "Pre-creating test databases"
52
- # puts %x{mysql -u root -e 'create database travis_ci_test;'}
53
- # puts %x{psql -c 'create database travis_ci_test;' -U postgres}
54
-
55
- # Our background Rack-app for http client testing
56
- require './test/servers/rackapp_8101'
57
-
58
- # Conditionally load other background servers
59
- # depending on what we're testing
60
- #
61
- case File.basename(ENV['BUNDLE_GEMFILE'])
62
- when /delayed_job/
63
- require './test/servers/delayed_job'
64
-
65
- when /rails5/
66
- require './test/servers/rails5x_8140'
67
- require './test/servers/rails5x_api_8150'
68
-
69
- when /rails4/
70
- require './test/servers/rails4x_8140'
71
-
72
- when /rails3/
73
- require './test/servers/rails3x_8140'
74
-
75
- when /frameworks/
76
- when /libraries/
77
- require 'rack/test'
78
- if RUBY_VERSION >= '2.0'
79
- # Load Sidekiq if TEST isn't defined or if it is, it calls
80
- # out the sidekiq tests
81
- if !ENV.key?('TEST') || ENV['TEST'] =~ /sidekiq/
82
- # Background Sidekiq thread
83
- require './test/servers/sidekiq.rb'
84
- end
85
- end
86
- end
87
-
88
- ##
89
- # clear_all_traces
90
- #
91
- # Truncates the trace output file to zero
92
- #
93
- def clear_all_traces
94
- if AppOpticsAPM.loaded
95
- AppOpticsAPM::Context.clear
96
- AppOpticsAPM::Reporter.clear_all_traces
97
- sleep 0.2 # it seems like the docker file system needs a bit of time to clear the file
98
- end
99
- end
100
-
101
- ##
102
- # get_all_traces
103
- #
104
- # Retrieves all traces written to the trace file
105
- #
106
- def get_all_traces
107
- if AppOpticsAPM.loaded
108
- AppOpticsAPM::Reporter.get_all_traces
109
- else
110
- []
111
- end
112
- end
113
-
114
- ##
115
- # validate_outer_layers
116
- #
117
- # Validates that the KVs in kvs are present
118
- # in event
119
- #
120
- def validate_outer_layers(traces, layer)
121
- traces.first['Layer'].must_equal layer
122
- traces.first['Label'].must_equal 'entry'
123
- traces.last['Layer'].must_equal layer
124
- traces.last['Label'].must_equal 'exit'
125
- end
126
-
127
- ##
128
- # validate_event_keys
129
- #
130
- # Validates that the KVs in kvs are present
131
- # in event
132
- #
133
- def validate_event_keys(event, kvs)
134
- kvs.each do |k, v|
135
- assert_equal true, event.key?(k), "#{k} is missing"
136
- assert event[k] == v, "#{k} != #{v} (#{event[k]})"
137
- end
138
- end
139
-
140
- ##
141
- # has_edge?
142
- #
143
- # Searches the array of <tt>traces</tt> for
144
- # <tt>edge</tt>
145
- #
146
- def has_edge?(edge, traces)
147
- traces.each do |t|
148
- if AppOpticsAPM::XTrace.edge_id(t["X-Trace"]) == edge
149
- return true
150
- end
151
- end
152
- AppOpticsAPM.logger.debug "[oboe/debug] edge #{edge} not found in traces."
153
- false
154
- end
155
-
156
- ##
157
- # valid_edges?
158
- #
159
- # Runs through the array of <tt>traces</tt> to validate
160
- # that all edges connect.
161
- #
162
- # Not that this won't work for external cross-app tracing
163
- # since we won't have those remote traces to validate
164
- # against.
165
- #
166
- def valid_edges?(traces)
167
- traces.reverse.each do |t|
168
- if t.key?("Edge")
169
- unless has_edge?(t["Edge"], traces)
170
- return false
171
- end
172
- end
173
- end
174
- true
175
- end
176
-
177
- ##
178
- # layer_has_key
179
- #
180
- # Checks an array of trace events if a specific layer (regardless of event type)
181
- # has he specified key
182
- #
183
- def layer_has_key(traces, layer, key)
184
- return false if traces.empty?
185
- has_key = false
186
-
187
- traces.each do |t|
188
- if t["Layer"] == layer and t.has_key?(key)
189
- has_key = true
190
-
191
- (t["Backtrace"].length > 0).must_equal true
192
- end
193
- end
194
-
195
- has_key.must_equal true
196
- end
197
-
198
- ##
199
- # layer_doesnt_have_key
200
- #
201
- # Checks an array of trace events to assure that a specific layer
202
- # (regardless of event type) doesn't have the specified key
203
- #
204
- def layer_doesnt_have_key(traces, layer, key)
205
- return false if traces.empty?
206
- has_key = false
207
-
208
- traces.each do |t|
209
- has_key = true if t["Layer"] == layer and t.has_key?(key)
210
- end
211
-
212
- has_key.must_equal false
213
- end
214
-
215
- ##
216
- # Checks if the transaction name corresponds to Controller.Action
217
- # if there are multiple events with Controller and/or Action, then they all have to match
218
- #
219
- def assert_controller_action(test_action)
220
- traces = get_all_traces
221
- traces.select { |tr| tr['Controller'] || tr['Action'] }.map do |tr|
222
- assert_equal(test_action, [tr['Controller'], tr['Action']].join('.'))
223
- end
224
- end
225
-
226
- def not_sampled?(xtrace)
227
- xtrace[59].to_i & 1 == 0
228
- end
229
-
230
- def sampled?(xtrace)
231
- xtrace[59].to_i & 1 == 1
232
- end
233
-
234
- def print_traces(traces, more_keys = [])
235
- indent = ''
236
- traces.each do |trace|
237
- indent += ' ' if trace["Label"] == "entry"
238
-
239
- puts "#{indent}X-Trace: #{trace["X-Trace"]}"
240
- puts "#{indent}Label: #{trace["Label"]}"
241
- puts "#{indent}Layer: #{trace["Layer"]}"
242
-
243
- more_keys.each { |key| puts "#{indent}#{key}: #{trace[key]}"}
244
-
245
- indent = indent[0...-2] if trace["Label"] == "exit"
246
- end
247
- nil
248
- end
249
-
250
- if (File.basename(ENV['BUNDLE_GEMFILE']) =~ /^frameworks/) == 0
251
- require "sinatra"
252
- ##
253
- # Sinatra and Padrino Related Helpers
254
- #
255
- # Taken from padrino-core gem
256
- #
257
- class Sinatra::Base
258
- # Allow assertions in request context
259
- include MiniTest::Assertions
260
- end
261
-
262
-
263
- class MiniTest::Spec
264
- include Rack::Test::Methods
265
-
266
- # Sets up a Sinatra::Base subclass defined with the block
267
- # given. Used in setup or individual spec methods to establish
268
- # the application.
269
- def mock_app(base=Padrino::Application, &block)
270
- @app = Sinatra.new(base, &block)
271
- end
272
-
273
- def app
274
- Rack::Lint.new(@app)
275
- end
276
- end
277
- end
@@ -1,324 +0,0 @@
1
- # Copyright (c) 2016 SolarWinds, LLC.
2
- # All rights reserved.
3
-
4
- if !defined?(JRUBY_VERSION)
5
-
6
- require 'minitest_helper'
7
- require 'webmock/minitest'
8
- require 'mocha/mini_test'
9
-
10
- class CurbMockedTest < Minitest::Test
11
-
12
- def setup
13
- AppOpticsAPM::Context.clear
14
- WebMock.enable!
15
- WebMock.reset!
16
- WebMock.disable_net_connect!
17
- AppOpticsAPM.config_lock.synchronize {
18
- @tm = AppOpticsAPM::Config[:tracing_mode]
19
- @sample_rate = AppOpticsAPM::Config[:sample_rate]
20
- }
21
- end
22
-
23
- def teardown
24
- AppOpticsAPM.config_lock.synchronize {
25
- AppOpticsAPM::Config[:tracing_mode] = @tm
26
- AppOpticsAPM::Config[:blacklist] = []
27
- AppOpticsAPM::Config[:sample_rate] = @sample_rate
28
- }
29
- WebMock.reset!
30
- WebMock.allow_net_connect!
31
- WebMock.disable!
32
- end
33
-
34
- def test_xtrace_tracing
35
- stub_request(:get, "http://127.0.0.9:8101/").to_return(status: 200, body: "", headers: {})
36
-
37
- AppOpticsAPM::API.start_trace('curb_tests') do
38
- ::Curl.get("http://127.0.0.9:8101/")
39
- end
40
-
41
- assert_requested :get, "http://127.0.0.9:8101/", times: 1
42
- assert_requested :get, "http://127.0.0.9:8101/", headers: {'X-Trace'=>/^2B[0-9,A-F]*01$/}, times: 1
43
- refute AppOpticsAPM::Context.isValid
44
- end
45
-
46
- def test_xtrace_sample_rate_0
47
- stub_request(:get, "http://127.0.0.4:8101/").to_return(status: 200, body: "", headers: {})
48
-
49
- AppOpticsAPM.config_lock.synchronize do
50
- AppOpticsAPM::Config[:sample_rate] = 0
51
- AppOpticsAPM::API.start_trace('curb_tests') do
52
- ::Curl.get("http://127.0.0.4:8101/")
53
- end
54
- end
55
-
56
- assert_requested :get, "http://127.0.0.4:8101/", times: 1
57
- assert_requested :get, "http://127.0.0.4:8101/", headers: {'X-Trace'=>/^2B[0-9,A-F]*00$/}, times: 1
58
- assert_not_requested :get, "http://127.0.0.4:8101/", headers: {'X-Trace'=>/^2B0*$/}
59
- refute AppOpticsAPM::Context.isValid
60
- end
61
-
62
- def test_xtrace_no_trace
63
- stub_request(:get, "http://127.0.0.6:8101/").to_return(status: 200, body: "", headers: {})
64
-
65
- ::Curl.get("http://127.0.0.6:8101/")
66
-
67
- assert_requested :get, "http://127.0.0.6:8101/", times: 1
68
- assert_not_requested :get, "http://127.0.0.6:8101/", headers: {'X-Trace'=>/^.*$/}
69
- end
70
-
71
- def test_blacklisted
72
- stub_request(:get, "http://127.0.0.2:8101/").to_return(status: 200, body: "", headers: {})
73
-
74
- AppOpticsAPM.config_lock.synchronize do
75
- AppOpticsAPM::Config.blacklist << '127.0.0.2'
76
- AppOpticsAPM::API.start_trace('curb_test') do
77
- ::Curl.get("http://127.0.0.2:8101/")
78
- end
79
- end
80
-
81
- assert_requested :get, "http://127.0.0.2:8101/", times: 1
82
- assert_not_requested :get, "http://127.0.0.2:8101/", headers: {'X-Trace'=>/^.*/}
83
- refute AppOpticsAPM::Context.isValid
84
- end
85
-
86
- def test_multi_get_no_trace
87
- WebMock.disable!
88
-
89
- Curl::Multi.expects(:http_without_appoptics).with do |url_confs, _multi_options|
90
- assert_equal 3, url_confs.size
91
- url_confs.each do |conf|
92
- refute conf[:headers] && conf[:headers]['X-Trace']
93
- end
94
- true
95
- end
96
-
97
- easy_options = {:follow_location => true}
98
- multi_options = {:pipeline => false}
99
-
100
- urls = []
101
- urls << "http://127.0.0.7:8101/?one=1"
102
- urls << "http://127.0.0.7:8101/?two=2"
103
- urls << "http://127.0.0.7:8101/?three=3"
104
-
105
- Curl::Multi.get(urls, easy_options, multi_options)
106
- refute AppOpticsAPM::Context.isValid
107
- end
108
-
109
- def test_multi_get_tracing
110
- WebMock.disable!
111
-
112
- Curl::Multi.expects(:http_without_appoptics).with do |url_confs, _multi_options|
113
- assert_equal 3, url_confs.size
114
- url_confs.each do |conf|
115
- headers = conf[:headers] || {}
116
- assert headers['X-Trace']
117
- assert headers['Custom']
118
- assert_match /specialvalue/, headers['Custom']
119
- assert sampled?(headers['X-Trace'])
120
- end
121
- true
122
- end
123
-
124
- easy_options = {:follow_location => true, :headers => { 'Custom' => 'specialvalue' }}
125
- multi_options = {:pipeline => false}
126
-
127
- urls = []
128
- urls << "http://127.0.0.7:8101/?one=1"
129
- urls << "http://127.0.0.7:8101/?two=2"
130
- urls << "http://127.0.0.7:8101/?three=3"
131
-
132
- AppOpticsAPM::API.start_trace('curb_tests') do
133
- Curl::Multi.get(urls, easy_options, multi_options)
134
- end
135
- refute AppOpticsAPM::Context.isValid
136
- end
137
-
138
- def test_multi_get_tracing_not_sampling
139
- WebMock.disable!
140
-
141
- Curl::Multi.expects(:http_without_appoptics).with do |url_confs, _multi_options|
142
- assert_equal 3, url_confs.size
143
- url_confs.each do |conf|
144
- headers = conf[:headers] || {}
145
- assert headers['X-Trace']
146
- assert not_sampled?(headers['X-Trace'])
147
- end
148
- true
149
- end
150
-
151
- easy_options = {:follow_location => true}
152
- multi_options = {:pipeline => false}
153
-
154
- urls = []
155
- urls << "http://127.0.0.7:8101/?one=1"
156
- urls << "http://127.0.0.7:8101/?two=2"
157
- urls << "http://127.0.0.7:8101/?three=3"
158
-
159
- AppOpticsAPM.config_lock.synchronize do
160
- AppOpticsAPM::Config[:sample_rate] = 0
161
- AppOpticsAPM::API.start_trace('curb_tests') do
162
- Curl::Multi.get(urls, easy_options, multi_options)
163
- end
164
- end
165
- refute AppOpticsAPM::Context.isValid
166
- end
167
-
168
- def test_multi_perform_no_trace
169
- WebMock.disable!
170
-
171
- urls = []
172
- urls << "http://127.0.0.1:8101/?one=1"
173
- urls << "http://127.0.0.1:8101/?two=2"
174
- urls << "http://127.0.0.1:8101/?three=3"
175
-
176
- m = Curl::Multi.new
177
- urls.each do |url|
178
- cu = Curl::Easy.new(url) do |curl|
179
- curl.follow_location = true
180
- end
181
- m.add cu
182
- end
183
-
184
- m.perform do
185
- m.requests.each do |request|
186
- refute request.headers && request.headers['X-Trace']
187
- end
188
- end
189
- end
190
-
191
- def test_multi_perform_tracing
192
- WebMock.disable!
193
-
194
- urls = []
195
- urls << "http://127.0.0.1:8101/?one=1"
196
- urls << "http://127.0.0.1:8101/?two=2"
197
- urls << "http://127.0.0.1:8101/?three=3"
198
-
199
- AppOpticsAPM::API.start_trace('curb_tests') do
200
- m = Curl::Multi.new
201
- urls.each do |url|
202
- cu = Curl::Easy.new(url) do |curl|
203
- curl.follow_location = true
204
- curl.headers = { 'Custom' => 'specialvalue' }
205
- end
206
- m.add cu
207
- end
208
-
209
- m.perform do
210
- m.requests.each do |request|
211
- assert request.headers['X-Trace']
212
- assert request.headers['Custom']
213
- assert sampled?(request.headers['X-Trace'])
214
- end
215
- end
216
- end
217
- refute AppOpticsAPM::Context.isValid
218
- end
219
-
220
- def test_multi_perform_tracing_not_sampling
221
- WebMock.disable!
222
-
223
- urls = []
224
- urls << "http://127.0.0.1:8101/?one=1"
225
- urls << "http://127.0.0.1:8101/?two=2"
226
- urls << "http://127.0.0.1:8101/?three=3"
227
-
228
- AppOpticsAPM.config_lock.synchronize do
229
- AppOpticsAPM::Config[:sample_rate] = 0
230
- AppOpticsAPM::API.start_trace('curb_tests') do
231
- m = Curl::Multi.new
232
- urls.each do |url|
233
- cu = Curl::Easy.new(url) do |curl|
234
- curl.follow_location = true
235
- end
236
- m.add cu
237
- end
238
-
239
- m.perform do
240
- m.requests.each do |request|
241
- assert request.headers['X-Trace']
242
- assert not_sampled?(request.headers['X-Trace'])
243
- refute_match /^2B0*$/, request.headers['X-Trace']
244
- end
245
- end
246
- end
247
- end
248
- refute AppOpticsAPM::Context.isValid
249
- end
250
-
251
- # preserve custom headers
252
- #
253
- # this calls Curl::Easy.http
254
- def test_preserves_custom_headers_on_get
255
- stub_request(:get, "http://127.0.0.6:8101/").to_return(status: 200, body: "", headers: {})
256
-
257
- AppOpticsAPM::API.start_trace('curb_tests') do
258
- Curl.get("http://127.0.0.6:8101/") do |curl|
259
- curl.headers = { 'Custom' => 'specialvalue' }
260
- end
261
- end
262
-
263
- assert_requested :get, "http://127.0.0.6:8101/", headers: {'Custom'=>'specialvalue'}, times: 1
264
- refute AppOpticsAPM::Context.isValid
265
- end
266
-
267
- # The following test can't use WebMock because it interferes with our instrumentation
268
- def test_preserves_custom_headers_on_http_put
269
- WebMock.disable!
270
-
271
- curl = Curl::Easy.new("http://127.0.0.1:8101/")
272
- curl.headers = { 'Custom' => 'specialvalue4' }
273
-
274
- AppOpticsAPM::API.start_trace('curb_tests') do
275
- curl.http_put nil
276
- end
277
-
278
- assert curl.headers
279
- assert curl.headers['X-Trace']
280
- assert curl.headers['Custom']
281
- assert_match /^2B[0-9,A-F]*01$/, curl.headers['X-Trace']
282
- assert_match /specialvalue4/, curl.headers['Custom']
283
- refute AppOpticsAPM::Context.isValid
284
- end
285
-
286
- def test_preserves_custom_headers_on_http_post
287
- WebMock.disable!
288
-
289
- curl = Curl::Easy.new("http://127.0.0.1:8101/")
290
- curl.headers = { 'Custom' => 'specialvalue4' }
291
-
292
- AppOpticsAPM::API.start_trace('curb_tests') do
293
- curl.http_post
294
- end
295
-
296
- assert curl.headers
297
- assert curl.headers['X-Trace']
298
- assert curl.headers['Custom']
299
- assert_match /^2B[0-9,A-F]*01$/, curl.headers['X-Trace']
300
- assert_match /specialvalue4/, curl.headers['Custom']
301
- refute AppOpticsAPM::Context.isValid
302
- end
303
-
304
- def test_preserves_custom_headers_on_perform
305
- WebMock.disable!
306
-
307
- curl = Curl::Easy.new("http://127.0.0.1:8101/")
308
- curl.headers = { 'Custom' => 'specialvalue4' }
309
-
310
- AppOpticsAPM::API.start_trace('curb_tests') do
311
- curl.perform
312
- end
313
-
314
- assert curl.headers
315
- assert curl.headers['X-Trace']
316
- assert curl.headers['Custom']
317
- assert_match /^2B[0-9,A-F]*01$/, curl.headers['X-Trace']
318
- assert_match /specialvalue4/, curl.headers['Custom']
319
- refute AppOpticsAPM::Context.isValid
320
- end
321
-
322
- end
323
- end
324
-