appoptics_apm 4.0.2 → 4.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/Dockerfile_test +7 -6
  4. data/Rakefile +2 -0
  5. data/docker-compose.yml +22 -0
  6. data/gemfiles/noop.gemfile +17 -0
  7. data/lib/appoptics_apm.rb +2 -2
  8. data/lib/appoptics_apm/api.rb +1 -2
  9. data/lib/appoptics_apm/api/layerinit.rb +3 -1
  10. data/lib/appoptics_apm/api/logging.rb +25 -25
  11. data/lib/appoptics_apm/api/memcache.rb +3 -1
  12. data/lib/appoptics_apm/api/profiling.rb +39 -33
  13. data/lib/appoptics_apm/api/tracing.rb +23 -13
  14. data/lib/appoptics_apm/api/util.rb +1 -1
  15. data/lib/appoptics_apm/base.rb +1 -0
  16. data/lib/appoptics_apm/frameworks/sinatra/templates.rb +1 -1
  17. data/lib/appoptics_apm/inst/rack.rb +135 -111
  18. data/lib/appoptics_apm/instrumentation.rb +1 -1
  19. data/lib/appoptics_apm/version.rb +1 -1
  20. data/test/instrumentation/httpclient_test.rb +4 -20
  21. data/test/instrumentation/mongo_v1_test.rb +1 -1
  22. data/test/instrumentation/rack_test.rb +1 -1
  23. data/test/instrumentation/sequel_mysql2_test.rb +1 -1
  24. data/test/instrumentation/sequel_mysql_test.rb +1 -1
  25. data/test/instrumentation/sequel_pg_test.rb +1 -1
  26. data/test/instrumentation/twitter-cassandra_test.rb +1 -1
  27. data/test/minitest_helper.rb +1 -0
  28. data/test/mocked/curb_mocked_test.rb +14 -1
  29. data/test/mocked/excon_mocked_test.rb +12 -4
  30. data/test/mocked/faraday_mocked_test.rb +5 -1
  31. data/test/mocked/http_mocked_test.rb +6 -0
  32. data/test/mocked/httpclient_mocked_test.rb +14 -1
  33. data/test/mocked/rest_client_mocked_test.rb +7 -1
  34. data/test/mocked/typhoeus_mocked_test.rb +15 -0
  35. data/test/noop/noop_test.rb +145 -0
  36. metadata +5 -4
  37. data/test/support/noop_test.rb +0 -88
@@ -8,12 +8,14 @@ unless defined?(JRUBY_VERSION)
8
8
  class TyphoeusMockedTest < Minitest::Test
9
9
 
10
10
  def setup
11
+ AppOpticsAPM::Context.clear
11
12
  AppOpticsAPM.config_lock.synchronize do
12
13
  @sample_rate = AppOpticsAPM::Config[:sample_rate]
13
14
  end
14
15
  end
15
16
 
16
17
  def teardown
18
+ AppOpticsAPM::Context.clear
17
19
  AppOpticsAPM.config_lock.synchronize do
18
20
  AppOpticsAPM::Config[:sample_rate] = @sample_rate
19
21
  AppOpticsAPM::Config[:blacklist] = []
@@ -30,6 +32,8 @@ unless defined?(JRUBY_VERSION)
30
32
  assert request.options[:headers]['X-Trace']
31
33
  assert_match /^2B[0-9,A-F]*01$/,request.options[:headers]['X-Trace']
32
34
  end
35
+
36
+ refute AppOpticsAPM::Context.isValid
33
37
  end
34
38
 
35
39
  def test_tracing_not_sampling
@@ -44,6 +48,7 @@ unless defined?(JRUBY_VERSION)
44
48
  refute_match /^2B0*$/, request.options[:headers]['X-Trace']
45
49
  end
46
50
  end
51
+ refute AppOpticsAPM::Context.isValid
47
52
  end
48
53
 
49
54
  def test_no_xtrace
@@ -51,6 +56,7 @@ unless defined?(JRUBY_VERSION)
51
56
  request.run
52
57
 
53
58
  refute request.options[:headers]['X-Trace']
59
+ refute AppOpticsAPM::Context.isValid
54
60
  end
55
61
 
56
62
  def test_blacklisted
@@ -63,6 +69,7 @@ unless defined?(JRUBY_VERSION)
63
69
  refute request.options[:headers]['X-Trace']
64
70
  end
65
71
  end
72
+ refute AppOpticsAPM::Context.isValid
66
73
  end
67
74
 
68
75
  def test_not_sampling_blacklisted
@@ -76,6 +83,7 @@ unless defined?(JRUBY_VERSION)
76
83
  refute request.options[:headers]['X-Trace']
77
84
  end
78
85
  end
86
+ refute AppOpticsAPM::Context.isValid
79
87
  end
80
88
 
81
89
  def test_preserves_custom_headers
@@ -86,6 +94,7 @@ unless defined?(JRUBY_VERSION)
86
94
  assert request.options[:headers]['Custom']
87
95
  assert_match /specialvalue/, request.options[:headers]['Custom']
88
96
  end
97
+ refute AppOpticsAPM::Context.isValid
89
98
  end
90
99
 
91
100
 
@@ -105,6 +114,7 @@ unless defined?(JRUBY_VERSION)
105
114
  assert request_2.options[:headers]['X-Trace'], "There is an X-Trace header"
106
115
  assert_match /^2B[0-9,A-F]*01$/, request_2.options[:headers]['X-Trace']
107
116
  end
117
+ refute AppOpticsAPM::Context.isValid
108
118
  end
109
119
 
110
120
  def test_hydra_tracing_not_sampling
@@ -126,6 +136,7 @@ unless defined?(JRUBY_VERSION)
126
136
  refute_match /^2B0*$/, request_2.options[:headers]['X-Trace']
127
137
  end
128
138
  end
139
+ refute AppOpticsAPM::Context.isValid
129
140
  end
130
141
 
131
142
  def test_hydra_no_xtrace
@@ -138,6 +149,7 @@ unless defined?(JRUBY_VERSION)
138
149
 
139
150
  refute request_1.options[:headers]['X-Trace'], "There should not be an X-Trace header"
140
151
  refute request_2.options[:headers]['X-Trace'], "There should not be an X-Trace header"
152
+ refute AppOpticsAPM::Context.isValid
141
153
  end
142
154
 
143
155
  def test_hydra_blacklisted
@@ -155,6 +167,7 @@ unless defined?(JRUBY_VERSION)
155
167
  refute request_2.options[:headers]['X-Trace'], "There should not be an X-Trace header"
156
168
  end
157
169
  end
170
+ refute AppOpticsAPM::Context.isValid
158
171
  end
159
172
 
160
173
  def test_hydra_not_sampling_blacklisted
@@ -173,6 +186,7 @@ unless defined?(JRUBY_VERSION)
173
186
  refute request_2.options[:headers]['X-Trace'], "There should not be an X-Trace header"
174
187
  end
175
188
  end
189
+ refute AppOpticsAPM::Context.isValid
176
190
  end
177
191
 
178
192
 
@@ -186,6 +200,7 @@ unless defined?(JRUBY_VERSION)
186
200
  assert request.options[:headers]['Custom']
187
201
  assert_match /specialvalue/, request.options[:headers]['Custom']
188
202
  end
203
+ refute AppOpticsAPM::Context.isValid
189
204
  end
190
205
 
191
206
  end
@@ -0,0 +1,145 @@
1
+ # Copyright (c) 2016 SolarWinds, LLC.
2
+ # All rights reserved.
3
+ #
4
+
5
+ # Force noop by setting the platform to something we don't support
6
+ RUBY_PLATFORM = 'noop'
7
+
8
+ # These tests assert:
9
+ # - that there is no instrumentation nor tracing in noop mode
10
+ # - that the 'official' SDK methods don't create
11
+
12
+ require 'minitest_helper'
13
+ require 'rack/lobster'
14
+ require 'net/http'
15
+
16
+ class NoopTest < Minitest::Test
17
+ include Rack::Test::Methods
18
+
19
+ class ArrayTest < Array; end
20
+
21
+ def setup
22
+ clear_all_traces
23
+ end
24
+
25
+ def app
26
+ @app = Rack::Builder.new {
27
+ use Rack::CommonLogger
28
+ use Rack::ShowExceptions
29
+ use AppOpticsAPM::Rack
30
+ map '/lobster' do
31
+ use Rack::Lint
32
+ run Rack::Lobster.new
33
+ end
34
+ }
35
+ end
36
+
37
+ def test_requests_still_work
38
+ get '/lobster'
39
+ traces = get_all_traces
40
+ assert_equal 0, traces.count, 'generate no traces'
41
+ assert AppOpticsAPM::Rack.noop?, 'This is not running in noop mode.'
42
+ end
43
+
44
+ def test_appoptics_config_doesnt_barf
45
+ tm = AppOpticsAPM::Config[:tracing_mode]
46
+ vb = AppOpticsAPM::Config[:verbose]
47
+ la = AppOpticsAPM::Config[:rack][:log_args]
48
+
49
+ # Test that we can set various things into AppOpticsAPM::Config still
50
+ AppOpticsAPM::Config[:tracing_mode] = :always
51
+ AppOpticsAPM::Config[:verbose] = false
52
+ AppOpticsAPM::Config[:rack][:log_args] = true
53
+
54
+ assert_equal :always, AppOpticsAPM::Config[:tracing_mode]
55
+ assert_equal false, AppOpticsAPM::Config[:verbose]
56
+ assert_equal true, AppOpticsAPM::Config[:rack][:log_args]
57
+
58
+ # Restore the originals
59
+ AppOpticsAPM::Config[:tracing_mode] = tm
60
+ AppOpticsAPM::Config[:verbose] = vb
61
+ AppOpticsAPM::Config[:rack][:log_args] = la
62
+ end
63
+
64
+ # ===== Make sure the AppOpticsAPM::Inst module does not exist ============================
65
+ # this is the module in which all the instrumented methods are defined
66
+ def test_not_instrumented
67
+ refute ::AppOpticsAPM.const_defined?('Inst'), 'This should be noop mode, but instrumentation was found.'
68
+ end
69
+
70
+ # ===== Make sure the frameworks are not instrumented =====================================
71
+ def test_rails_not_instrumented
72
+ refute ::AppOpticsAPM.const_defined?('Rails'), 'This should be noop mode, but Rails is instrumented.'
73
+ end
74
+
75
+ def test_sinatra_not_instrumented
76
+ refute ::AppOpticsAPM.const_defined?('Sinatra'), 'This should be noop mode, but Sinatra is instrumented.'
77
+ end
78
+
79
+ def test_grape_not_instrumented
80
+ refute ::AppOpticsAPM.const_defined?('Grape'), 'This should be noop mode, but Grape is instrumented.'
81
+ end
82
+
83
+ def test_padrino_not_instrumented
84
+ refute ::AppOpticsAPM.const_defined?('Padrino'), 'This should be noop mode, but Padrino is instrumented.'
85
+ end
86
+
87
+ # ===== Make sure the methods we document as SDK don't barf in noop mode ==================
88
+
89
+ def test_start_trace_doesnt_barf
90
+ AppOpticsAPM::API.start_trace('noop_test') do
91
+ AppOpticsAPM::API.trace('blah_block') do
92
+ "this block should not be traced"
93
+ end
94
+ end
95
+
96
+ traces = get_all_traces
97
+ assert_equal 0, traces.count, "generate no traces"
98
+ end
99
+
100
+ def test_trace_doesnt_barf
101
+ AppOpticsAPM::API.trace('noop_test') do
102
+ "this block should not be traced"
103
+ end
104
+
105
+ traces = get_all_traces
106
+ assert_equal 0, traces.count, "generate no traces"
107
+ end
108
+
109
+ def test_method_profiling_doesnt_barf
110
+ AppOpticsAPM::API.profile_method(ArrayTest, :sort)
111
+
112
+ x = ArrayTest.new
113
+ x.push(1).push(3).push(2)
114
+ assert_equal [1, 2, 3], x.sort
115
+
116
+ traces = get_all_traces
117
+ assert_equal 0, traces.count, "generate no traces" end
118
+
119
+ def test_profile_doesnt_barf
120
+ def fib(n)
121
+ return n if n <= 1
122
+ n + fib(n-1)
123
+ end
124
+
125
+ def computation(n)
126
+ AppOpticsAPM::API.profile('fib', { :n => n }) do
127
+ fib(n)
128
+ end
129
+ end
130
+
131
+ result = computation(4)
132
+ assert_equal 10, result
133
+
134
+
135
+ traces = get_all_traces
136
+ assert_equal 0, traces.count, "generate no traces" end
137
+
138
+ def test_log_info_doesnt_barf
139
+ AppOpticsAPM::API.log_info(nil, {:ok => :yeah })
140
+
141
+ traces = get_all_traces
142
+ assert_equal 0, traces.count, "generate no traces"
143
+ end
144
+ end
145
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appoptics_apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.2
4
+ version: 4.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maia Engeli
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-01-30 00:00:00.000000000 Z
13
+ date: 2018-02-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -174,6 +174,7 @@ files:
174
174
  - gemfiles/frameworks.gemfile
175
175
  - gemfiles/instrumentation_mocked.gemfile
176
176
  - gemfiles/libraries.gemfile
177
+ - gemfiles/noop.gemfile
177
178
  - gemfiles/rails23.gemfile
178
179
  - gemfiles/rails30.gemfile
179
180
  - gemfiles/rails31.gemfile
@@ -330,6 +331,7 @@ files:
330
331
  - test/mocked/rest_client_mocked_test.rb
331
332
  - test/mocked/typhoeus_mocked_test.rb
332
333
  - test/models/widget.rb
334
+ - test/noop/noop_test.rb
333
335
  - test/profiling/legacy_method_profiling_test.rb
334
336
  - test/profiling/method_profiling_test.rb
335
337
  - test/queues/delayed_job-client_test.rb
@@ -352,7 +354,6 @@ files:
352
354
  - test/support/init_report_test.rb
353
355
  - test/support/liboboe_settings_test.rb
354
356
  - test/support/logging_test.rb
355
- - test/support/noop_test.rb
356
357
  - test/support/sql_sanitize_test.rb
357
358
  - test/support/tracing_mode_test.rb
358
359
  - test/support/tvalias_test.rb
@@ -393,6 +394,7 @@ test_files:
393
394
  - test/mocked/faraday_mocked_test.rb
394
395
  - test/mocked/typhoeus_mocked_test.rb
395
396
  - test/mocked/curb_mocked_test.rb
397
+ - test/noop/noop_test.rb
396
398
  - test/reporter/reporter_test.rb
397
399
  - test/models/widget.rb
398
400
  - test/instrumentation/sequel_mysql_test.rb
@@ -430,7 +432,6 @@ test_files:
430
432
  - test/instrumentation/httpclient_test.rb
431
433
  - test/support/config_test.rb
432
434
  - test/support/xtrace_test.rb
433
- - test/support/noop_test.rb
434
435
  - test/support/tracing_mode_test.rb
435
436
  - test/support/init_report_test.rb
436
437
  - test/support/backcompat_test.rb
@@ -1,88 +0,0 @@
1
- # Copyright (c) 2016 SolarWinds, LLC.
2
- # All rights reserved.
3
-
4
- require 'minitest_helper'
5
- require 'rack/test'
6
- require 'rack/lobster'
7
- require 'appoptics_apm/inst/rack'
8
- require 'net/http'
9
-
10
- class NoopTest < Minitest::Test
11
- include Rack::Test::Methods
12
-
13
- class ArrayTest < Array; end
14
-
15
- def setup
16
- AppOpticsAPM.loaded = false
17
- end
18
-
19
- def teardown
20
- AppOpticsAPM.loaded = true
21
- end
22
-
23
- def app
24
- @app = Rack::Builder.new {
25
- use Rack::CommonLogger
26
- use Rack::ShowExceptions
27
- use AppOpticsAPM::Rack
28
- map "/lobster" do
29
- use Rack::Lint
30
- run Rack::Lobster.new
31
- end
32
- }
33
- end
34
-
35
- def test_requests_still_work
36
- clear_all_traces
37
-
38
- get "/lobster"
39
-
40
- traces = get_all_traces
41
- assert_equal 0, traces.count, "generate no traces"
42
- end
43
-
44
- def test_tracing_api_doesnt_barf
45
- AppOpticsAPM::API.start_trace('noop_test') do
46
- AppOpticsAPM::API.trace('blah_block') do
47
- "this block should not be traced"
48
- end
49
- end
50
-
51
- AppOpticsAPM::API.log_start('noop_test')
52
- AppOpticsAPM::API.log_info(nil, {:ok => :yeah })
53
- AppOpticsAPM::API.log_exception(nil, Exception.new("yeah ok"))
54
- AppOpticsAPM::API.log_end('noop_test')
55
-
56
- traces = get_all_traces
57
- assert_equal 0, traces.count, "generate no traces"
58
- end
59
-
60
- def test_method_profiling_doesnt_barf
61
- AppOpticsAPM::API.profile_method(ArrayTest, :sort)
62
-
63
- x = ArrayTest.new
64
- x.push(1).push(3).push(2)
65
- assert_equal [1, 2, 3], x.sort
66
- end
67
-
68
- def test_appoptics_config_doesnt_barf
69
- tm = AppOpticsAPM::Config[:tracing_mode]
70
- vb = AppOpticsAPM::Config[:verbose]
71
- la = AppOpticsAPM::Config[:rack][:log_args]
72
-
73
- # Test that we can set various things into AppOpticsAPM::Config still
74
- AppOpticsAPM::Config[:tracing_mode] = :always
75
- AppOpticsAPM::Config[:verbose] = false
76
- AppOpticsAPM::Config[:rack][:log_args] = true
77
-
78
- assert_equal :always, AppOpticsAPM::Config[:tracing_mode]
79
- assert_equal false, AppOpticsAPM::Config[:verbose]
80
- assert_equal true, AppOpticsAPM::Config[:rack][:log_args]
81
-
82
- # Restore the originals
83
- AppOpticsAPM::Config[:tracing_mode] = tm
84
- AppOpticsAPM::Config[:verbose] = vb
85
- AppOpticsAPM::Config[:rack][:log_args] = la
86
- end
87
- end
88
-