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,288 +0,0 @@
1
- # Copyright (c) 2016 SolarWinds, LLC.
2
- # All rights reserved.
3
-
4
- require 'minitest_helper'
5
-
6
- if RUBY_VERSION >= '2.0.0'
7
- describe "RestClient" do
8
- before do
9
- clear_all_traces
10
- @collect_backtraces = AppOpticsAPM::Config[:rest_client][:collect_backtraces]
11
- end
12
-
13
- after do
14
- AppOpticsAPM::Config[:rest_client][:collect_backtraces] = @collect_backtraces
15
- end
16
-
17
- it 'RestClient should be defined and ready' do
18
- defined?(::RestClient).wont_match nil
19
- end
20
-
21
- it 'RestClient should have appoptics_apm methods defined' do
22
- [ :execute_with_appoptics ].each do |m|
23
- ::RestClient::Request.method_defined?(m).must_equal true
24
- end
25
- end
26
-
27
- it "should report rest-client version in __Init" do
28
- init_kvs = ::AppOpticsAPM::Util.build_init_report
29
-
30
- init_kvs.key?('Ruby.rest-client.Version').must_equal true
31
- init_kvs['Ruby.rest-client.Version'].must_equal ::RestClient::VERSION
32
- end
33
-
34
- it "should trace a request to an instr'd app" do
35
- response = nil
36
-
37
- AppOpticsAPM::API.start_trace('rest_client_test') do
38
- response = RestClient.get 'http://127.0.0.1:8101/'
39
- end
40
-
41
- traces = get_all_traces
42
- traces.count.must_equal 10
43
-
44
- valid_edges?(traces).must_equal true
45
- validate_outer_layers(traces, 'rest_client_test')
46
-
47
- traces[1]['Layer'].must_equal 'rest-client'
48
- traces[1]['Label'].must_equal 'entry'
49
-
50
- traces[2]['Layer'].must_equal 'net-http'
51
- traces[2]['Label'].must_equal 'entry'
52
-
53
- traces[6]['Layer'].must_equal 'net-http'
54
- traces[6]['Label'].must_equal 'info'
55
- traces[6]['IsService'].must_equal 1
56
- traces[6]['RemoteProtocol'].must_equal 'HTTP'
57
- traces[6]['RemoteHost'].must_equal '127.0.0.1:8101'
58
- traces[6]['ServiceArg'].must_equal '/'
59
- traces[6]['HTTPMethod'].must_equal 'GET'
60
- traces[6]['HTTPStatus'].must_equal "200"
61
- traces[6].key?('Backtrace').must_equal AppOpticsAPM::Config[:nethttp][:collect_backtraces]
62
-
63
- traces[7]['Layer'].must_equal 'net-http'
64
- traces[7]['Label'].must_equal 'exit'
65
-
66
- traces[8]['Layer'].must_equal 'rest-client'
67
- traces[8]['Label'].must_equal 'exit'
68
-
69
- response.headers.key?(:x_trace).wont_equal nil
70
- xtrace = response.headers[:x_trace]
71
-
72
- AppOpticsAPM::XTrace.valid?(xtrace).must_equal true
73
- end
74
-
75
- it 'should trace a raw GET request' do
76
- AppOpticsAPM::API.start_trace('rest_client_test') do
77
- RestClient.get 'http://127.0.0.1:8101/?a=1'
78
- end
79
-
80
- traces = get_all_traces
81
- traces.count.must_equal 10
82
-
83
- valid_edges?(traces).must_equal true
84
- validate_outer_layers(traces, 'rest_client_test')
85
-
86
- traces[1]['Layer'].must_equal 'rest-client'
87
- traces[1]['Label'].must_equal 'entry'
88
-
89
- traces[2]['Layer'].must_equal 'net-http'
90
- traces[2]['Label'].must_equal 'entry'
91
-
92
- traces[6]['Layer'].must_equal 'net-http'
93
- traces[6]['Label'].must_equal 'info'
94
- traces[6]['IsService'].must_equal 1
95
- traces[6]['RemoteProtocol'].must_equal 'HTTP'
96
- traces[6]['RemoteHost'].must_equal '127.0.0.1:8101'
97
- traces[6]['ServiceArg'].must_equal '/?a=1'
98
- traces[6]['HTTPMethod'].must_equal 'GET'
99
- traces[6]['HTTPStatus'].must_equal "200"
100
- traces[6].key?('Backtrace').must_equal AppOpticsAPM::Config[:nethttp][:collect_backtraces]
101
-
102
- traces[7]['Layer'].must_equal 'net-http'
103
- traces[7]['Label'].must_equal 'exit'
104
-
105
- traces[8]['Layer'].must_equal 'rest-client'
106
- traces[8]['Label'].must_equal 'exit'
107
- end
108
-
109
- it 'should trace a raw POST request' do
110
- AppOpticsAPM::API.start_trace('rest_client_test') do
111
- RestClient.post 'http://127.0.0.1:8101/', :param1 => 'one', :nested => { :param2 => 'two' }
112
- end
113
-
114
- traces = get_all_traces
115
- traces.count.must_equal 10
116
-
117
- valid_edges?(traces).must_equal true
118
- validate_outer_layers(traces, 'rest_client_test')
119
-
120
- traces[1]['Layer'].must_equal 'rest-client'
121
- traces[1]['Label'].must_equal 'entry'
122
-
123
- traces[2]['Layer'].must_equal 'net-http'
124
- traces[2]['Label'].must_equal 'entry'
125
-
126
- traces[6]['Layer'].must_equal 'net-http'
127
- traces[6]['Label'].must_equal 'info'
128
- traces[6]['IsService'].must_equal 1
129
- traces[6]['RemoteProtocol'].must_equal 'HTTP'
130
- traces[6]['RemoteHost'].must_equal '127.0.0.1:8101'
131
- traces[6]['ServiceArg'].must_equal '/'
132
- traces[6]['HTTPMethod'].must_equal 'POST'
133
- traces[6]['HTTPStatus'].must_equal "200"
134
- traces[6].key?('Backtrace').must_equal AppOpticsAPM::Config[:nethttp][:collect_backtraces]
135
-
136
- traces[7]['Layer'].must_equal 'net-http'
137
- traces[7]['Label'].must_equal 'exit'
138
-
139
- traces[8]['Layer'].must_equal 'rest-client'
140
- traces[8]['Label'].must_equal 'exit'
141
- end
142
-
143
- it 'should trace a ActiveResource style GET request' do
144
- AppOpticsAPM::API.start_trace('rest_client_test') do
145
- resource = RestClient::Resource.new 'http://127.0.0.1:8101/?a=1'
146
- resource.get
147
- end
148
-
149
- traces = get_all_traces
150
- traces.count.must_equal 10
151
-
152
- valid_edges?(traces).must_equal true
153
- validate_outer_layers(traces, 'rest_client_test')
154
-
155
- traces[1]['Layer'].must_equal 'rest-client'
156
- traces[1]['Label'].must_equal 'entry'
157
-
158
- traces[2]['Layer'].must_equal 'net-http'
159
- traces[2]['Label'].must_equal 'entry'
160
-
161
- traces[6]['Layer'].must_equal 'net-http'
162
- traces[6]['Label'].must_equal 'info'
163
- traces[6]['IsService'].must_equal 1
164
- traces[6]['RemoteProtocol'].must_equal 'HTTP'
165
- traces[6]['RemoteHost'].must_equal '127.0.0.1:8101'
166
- traces[6]['ServiceArg'].must_equal '/?a=1'
167
- traces[6]['HTTPMethod'].must_equal 'GET'
168
- traces[6]['HTTPStatus'].must_equal "200"
169
- traces[6].key?('Backtrace').must_equal AppOpticsAPM::Config[:nethttp][:collect_backtraces]
170
-
171
- traces[7]['Layer'].must_equal 'net-http'
172
- traces[7]['Label'].must_equal 'exit'
173
-
174
- traces[8]['Layer'].must_equal 'rest-client'
175
- traces[8]['Label'].must_equal 'exit'
176
- end
177
-
178
- it 'should trace requests with redirects' do
179
- response = nil
180
-
181
- AppOpticsAPM::API.start_trace('rest_client_test') do
182
- resource = RestClient::Resource.new 'http://127.0.0.1:8101/redirectme?redirect_test'
183
- response = resource.get
184
- end
185
-
186
- traces = get_all_traces
187
- traces.count.must_equal 18
188
-
189
- valid_edges?(traces).must_equal true
190
- validate_outer_layers(traces, 'rest_client_test')
191
-
192
- traces[1]['Layer'].must_equal 'rest-client'
193
- traces[1]['Label'].must_equal 'entry'
194
-
195
- traces[2]['Layer'].must_equal 'net-http'
196
- traces[2]['Label'].must_equal 'entry'
197
-
198
- traces[6]['Layer'].must_equal 'net-http'
199
- traces[6]['Label'].must_equal 'info'
200
- traces[6]['IsService'].must_equal 1
201
- traces[6]['RemoteProtocol'].must_equal 'HTTP'
202
- traces[6]['RemoteHost'].must_equal '127.0.0.1:8101'
203
- traces[6]['ServiceArg'].must_equal '/redirectme?redirect_test'
204
- traces[6]['HTTPMethod'].must_equal 'GET'
205
- traces[6]['HTTPStatus'].must_equal "301"
206
- traces[6].key?('Backtrace').must_equal AppOpticsAPM::Config[:nethttp][:collect_backtraces]
207
-
208
- traces[7]['Layer'].must_equal 'net-http'
209
- traces[7]['Label'].must_equal 'exit'
210
-
211
- traces[8]['Layer'].must_equal 'rest-client'
212
- traces[8]['Label'].must_equal 'entry'
213
-
214
- traces[9]['Layer'].must_equal 'net-http'
215
- traces[9]['Label'].must_equal 'entry'
216
-
217
- traces[13]['Layer'].must_equal 'net-http'
218
- traces[13]['Label'].must_equal 'info'
219
- traces[13]['IsService'].must_equal 1
220
- traces[13]['RemoteProtocol'].must_equal 'HTTP'
221
- traces[13]['RemoteHost'].must_equal '127.0.0.1:8101'
222
- traces[13]['ServiceArg'].must_equal '/'
223
- traces[13]['HTTPMethod'].must_equal 'GET'
224
- traces[13]['HTTPStatus'].must_equal "200"
225
- traces[13].key?('Backtrace').must_equal AppOpticsAPM::Config[:nethttp][:collect_backtraces]
226
-
227
- traces[14]['Layer'].must_equal 'net-http'
228
- traces[14]['Label'].must_equal 'exit'
229
-
230
- traces[15]['Layer'].must_equal 'rest-client'
231
- traces[15]['Label'].must_equal 'exit'
232
-
233
- traces[16]['Layer'].must_equal 'rest-client'
234
- traces[16]['Label'].must_equal 'exit'
235
- end
236
-
237
- it 'should trace and capture raised exceptions' do
238
- AppOpticsAPM::API.start_trace('rest_client_test') do
239
- begin
240
- RestClient.get 'http://s6KTgaz7636z/resource'
241
- rescue
242
- # We want an exception to be raised. Just don't raise
243
- # it beyond this point.
244
- end
245
- end
246
-
247
- traces = get_all_traces
248
- traces.count.must_equal 5
249
-
250
- valid_edges?(traces).must_equal true
251
- validate_outer_layers(traces, 'rest_client_test')
252
-
253
- traces[1]['Layer'].must_equal 'rest-client'
254
- traces[1]['Label'].must_equal 'entry'
255
-
256
- traces[2]['Layer'].must_equal 'rest-client'
257
- traces[2]['Label'].must_equal 'error'
258
- traces[2]['ErrorClass'].must_equal 'SocketError'
259
- traces[2].key?('ErrorMsg').must_equal true
260
- traces[2].key?('Backtrace').must_equal true
261
-
262
- traces[3]['Layer'].must_equal 'rest-client'
263
- traces[3]['Label'].must_equal 'exit'
264
- end
265
-
266
- it 'should obey :collect_backtraces setting when true' do
267
- AppOpticsAPM::Config[:rest_client][:collect_backtraces] = true
268
-
269
- AppOpticsAPM::API.start_trace('rest_client_test') do
270
- RestClient.get('http://127.0.0.1:8101/', {:a => 1})
271
- end
272
-
273
- traces = get_all_traces
274
- layer_has_key(traces, 'rest-client', 'Backtrace')
275
- end
276
-
277
- it 'should obey :collect_backtraces setting when false' do
278
- AppOpticsAPM::Config[:rest_client][:collect_backtraces] = false
279
-
280
- AppOpticsAPM::API.start_trace('rest_client_test') do
281
- RestClient.get('http://127.0.0.1:8101/', {:a => 1})
282
- end
283
-
284
- traces = get_all_traces
285
- layer_doesnt_have_key(traces, 'rest-client', 'Backtrace')
286
- end
287
- end
288
- end
@@ -1,353 +0,0 @@
1
- # Copyright (c) 2016 SolarWinds, LLC.
2
- # All rights reserved.
3
-
4
- require 'minitest_helper'
5
-
6
- if defined?(::Sequel) && !defined?(JRUBY_VERSION)
7
-
8
- AppOpticsAPM::Test.set_mysql2_env
9
- MYSQL2_DB = Sequel.connect(ENV['DATABASE_URL'])
10
-
11
- unless MYSQL2_DB.table_exists?(:items)
12
- MYSQL2_DB.create_table :items do
13
- primary_key :id
14
- String :name
15
- Float :price
16
- end
17
- end
18
-
19
- describe "Sequel (mysql2)" do
20
- before do
21
- clear_all_traces
22
-
23
- # These are standard entry/exit KVs that are passed up with all sequel operations
24
- @entry_kvs = {
25
- 'Layer' => 'sequel',
26
- 'Label' => 'entry',
27
- 'Database' => 'travis_ci_test',
28
- 'RemoteHost' => ENV.key?('DOCKER_MYSQL_PASS') ? 'mysql' : '127.0.0.1',
29
- 'RemotePort' => 3306 }
30
-
31
- @exit_kvs = { 'Layer' => 'sequel', 'Label' => 'exit' }
32
- @collect_backtraces = AppOpticsAPM::Config[:sequel][:collect_backtraces]
33
- @sanitize_sql = AppOpticsAPM::Config[:sanitize_sql]
34
- end
35
-
36
- after do
37
- AppOpticsAPM::Config[:sequel][:collect_backtraces] = @collect_backtraces
38
- AppOpticsAPM::Config[:sanitize_sql] = @sanitize_sql
39
- end
40
-
41
- it 'Stock sequel should be loaded, defined and ready' do
42
- defined?(::Sequel).wont_match nil
43
- end
44
-
45
- it 'sequel should have appoptics_apm methods defined' do
46
- # Sequel::Database
47
- ::Sequel::Database.method_defined?(:run_with_appoptics).must_equal true
48
-
49
- # Sequel::Dataset
50
- ::Sequel::Dataset.method_defined?(:execute_with_appoptics).must_equal true
51
- ::Sequel::Dataset.method_defined?(:execute_ddl_with_appoptics).must_equal true
52
- ::Sequel::Dataset.method_defined?(:execute_dui_with_appoptics).must_equal true
53
- ::Sequel::Dataset.method_defined?(:execute_insert_with_appoptics).must_equal true
54
- end
55
-
56
- it "should obey :collect_backtraces setting when true" do
57
- AppOpticsAPM::Config[:sequel][:collect_backtraces] = true
58
-
59
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
60
- MYSQL2_DB.run('select 1')
61
- end
62
-
63
- traces = get_all_traces
64
- layer_has_key(traces, 'sequel', 'Backtrace')
65
- end
66
-
67
- it "should obey :collect_backtraces setting when false" do
68
- AppOpticsAPM::Config[:sequel][:collect_backtraces] = false
69
-
70
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
71
- MYSQL2_DB.run('select 1')
72
- end
73
-
74
- traces = get_all_traces
75
- layer_doesnt_have_key(traces, 'sequel', 'Backtrace')
76
- end
77
-
78
- it 'should trace MYSQL2_DB.run insert' do
79
- AppOpticsAPM::Config[:sanitize_sql] = false
80
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
81
- MYSQL2_DB.run("insert into items (name, price) values ('blah', '12')")
82
- end
83
-
84
- traces = get_all_traces
85
-
86
- traces.count.must_equal 4
87
- validate_outer_layers(traces, 'sequel_test')
88
-
89
- validate_event_keys(traces[1], @entry_kvs)
90
- traces[1]['Query'].must_equal "insert into items (name, price) values ('blah', '12')"
91
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
92
- validate_event_keys(traces[2], @exit_kvs)
93
- end
94
-
95
- it 'should trace MYSQL2_DB.run select' do
96
- AppOpticsAPM::Config[:sanitize_sql] = false
97
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
98
- MYSQL2_DB.run("select 1")
99
- end
100
-
101
- traces = get_all_traces
102
-
103
- traces.count.must_equal 4
104
- validate_outer_layers(traces, 'sequel_test')
105
-
106
- validate_event_keys(traces[1], @entry_kvs)
107
- traces[1]['Query'].must_equal "select 1"
108
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
109
- validate_event_keys(traces[2], @exit_kvs)
110
- end
111
-
112
- it 'should trace a dataset insert and count' do
113
- AppOpticsAPM::Config[:sanitize_sql] = false
114
- items = MYSQL2_DB[:items]
115
- items.count
116
-
117
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
118
- items.insert(:name => 'abc', :price => 2.514)
119
- items.count
120
- end
121
-
122
- traces = get_all_traces
123
-
124
- traces.count.must_equal 6
125
- validate_outer_layers(traces, 'sequel_test')
126
-
127
- validate_event_keys(traces[1], @entry_kvs)
128
-
129
- # SQL column/value order can vary between Ruby and gem versions
130
- # Use must_include to test against one or the other
131
- [
132
- "INSERT INTO `items` (`price`, `name`) VALUES (2.514, 'abc')",
133
- "INSERT INTO `items` (`name`, `price`) VALUES ('abc', 2.514)"
134
- ].must_include traces[1]['Query']
135
-
136
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
137
- traces[2]['Layer'].must_equal "sequel"
138
- traces[2]['Label'].must_equal "exit"
139
- traces[3]['Query'].downcase.must_equal "select count(*) as `count` from `items` limit 1"
140
- validate_event_keys(traces[4], @exit_kvs)
141
- end
142
-
143
- it 'should trace a dataset insert and obey query privacy' do
144
- AppOpticsAPM::Config[:sanitize_sql] = true
145
- items = MYSQL2_DB[:items]
146
- items.count
147
-
148
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
149
- items.insert(:name => 'abc', :price => 2.514461383352462)
150
- end
151
-
152
- traces = get_all_traces
153
-
154
- traces.count.must_equal 4
155
- validate_outer_layers(traces, 'sequel_test')
156
-
157
- validate_event_keys(traces[1], @entry_kvs)
158
-
159
- # SQL column/value order can vary between Ruby and gem versions
160
- # Use must_include to test against one or the other
161
- [
162
- "INSERT INTO `items` (`price`, `name`) VALUES (?, ?)",
163
- "INSERT INTO `items` (`name`, `price`) VALUES (?, ?)"
164
- ].must_include traces[1]['Query']
165
-
166
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
167
- validate_event_keys(traces[2], @exit_kvs)
168
- end
169
-
170
- it 'should trace a dataset filter' do
171
- AppOpticsAPM::Config[:sanitize_sql] = false
172
- items = MYSQL2_DB[:items]
173
- items.count
174
-
175
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
176
- items.filter(:name => 'abc').all
177
- end
178
-
179
- traces = get_all_traces
180
-
181
- traces.count.must_equal 4
182
- validate_outer_layers(traces, 'sequel_test')
183
-
184
- validate_event_keys(traces[1], @entry_kvs)
185
- traces[1]['Query'].must_equal "SELECT * FROM `items` WHERE (`name` = 'abc')"
186
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
187
- validate_event_keys(traces[2], @exit_kvs)
188
- end
189
-
190
- it 'should trace create table' do
191
- AppOpticsAPM::Config[:sanitize_sql] = false
192
- # Drop the table if it already exists
193
- MYSQL2_DB.drop_table(:fake) if MYSQL2_DB.table_exists?(:fake)
194
-
195
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
196
- MYSQL2_DB.create_table :fake do
197
- primary_key :id
198
- String :name
199
- Float :price
200
- end
201
- end
202
-
203
- traces = get_all_traces
204
-
205
- traces.count.must_equal 4
206
- validate_outer_layers(traces, 'sequel_test')
207
-
208
- validate_event_keys(traces[1], @entry_kvs)
209
- traces[1]['Query'].must_equal "CREATE TABLE `fake` (`id` integer PRIMARY KEY AUTO_INCREMENT, `name` varchar(255), `price` double precision)"
210
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
211
- validate_event_keys(traces[2], @exit_kvs)
212
- end
213
-
214
- it 'should trace add index' do
215
- AppOpticsAPM::Config[:sanitize_sql] = false
216
- # Drop the table if it already exists
217
- MYSQL2_DB.drop_table(:fake) if MYSQL2_DB.table_exists?(:fake)
218
-
219
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
220
- MYSQL2_DB.create_table :fake do
221
- primary_key :id
222
- String :name
223
- Float :price
224
- end
225
- end
226
-
227
- traces = get_all_traces
228
-
229
- traces.count.must_equal 4
230
- validate_outer_layers(traces, 'sequel_test')
231
-
232
- validate_event_keys(traces[1], @entry_kvs)
233
- traces[1]['Query'].must_equal "CREATE TABLE `fake` (`id` integer PRIMARY KEY AUTO_INCREMENT, `name` varchar(255), `price` double precision)"
234
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
235
- validate_event_keys(traces[2], @exit_kvs)
236
- end
237
-
238
- it 'should capture and report exceptions' do
239
- begin
240
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
241
- MYSQL2_DB.run("this is bad sql")
242
- end
243
- rescue
244
- # Do nothing - we're testing exception logging
245
- end
246
-
247
- traces = get_all_traces
248
-
249
- traces.count.must_equal 5
250
- validate_outer_layers(traces, 'sequel_test')
251
-
252
- validate_event_keys(traces[1], @entry_kvs)
253
- traces[1]['Query'].must_equal "this is bad sql"
254
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
255
- traces[2]['Layer'].must_equal "sequel"
256
- traces[2]['Label'].must_equal "error"
257
- traces[2].has_key?('Backtrace').must_equal true
258
- traces[2]['ErrorClass'].must_equal "Sequel::DatabaseError"
259
- validate_event_keys(traces[3], @exit_kvs)
260
- end
261
-
262
- it 'should trace placeholder queries with bound vars' do
263
- AppOpticsAPM::Config[:sanitize_sql] = false
264
- items = MYSQL2_DB[:items]
265
- items.count
266
-
267
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
268
- ds = items.where(:name=>:$n)
269
- ds.call(:select, :n=>'abc')
270
- ds.call(:delete, :n=>'cba')
271
- end
272
-
273
- traces = get_all_traces
274
-
275
- traces.count.must_equal 6
276
- validate_outer_layers(traces, 'sequel_test')
277
-
278
- validate_event_keys(traces[1], @entry_kvs)
279
- if ::Sequel::VERSION > '4.36.0'
280
- traces[1]['Query'].must_equal "SELECT * FROM `items` WHERE (`name` = ?)"
281
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
282
- traces[3]['Query'].must_equal "DELETE FROM `items` WHERE (`name` = ?)"
283
- traces[3].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
284
- else
285
- traces[1]['Query'].must_equal "SELECT * FROM `items` WHERE (`name` = 'abc')"
286
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
287
- traces[3]['Query'].must_equal "DELETE FROM `items` WHERE (`name` = 'cba')"
288
- traces[3].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
289
- end
290
- validate_event_keys(traces[2], @exit_kvs)
291
- end
292
-
293
- it 'should trace prepared statements' do
294
- AppOpticsAPM::Config[:sanitize_sql] = false
295
- ds = MYSQL2_DB[:items].filter(:name=>:$n)
296
- ps = ds.prepare(:select, :select_by_name)
297
-
298
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
299
- ps.call(:n=>'abc')
300
- end
301
-
302
- traces = get_all_traces
303
-
304
- traces.count.must_equal 4
305
- validate_outer_layers(traces, 'sequel_test')
306
-
307
- validate_event_keys(traces[1], @entry_kvs)
308
-
309
- if ::Sequel::VERSION > '4.36.0'
310
- traces[1]['Query'].must_equal "SELECT * FROM `items` WHERE (`name` = ?)"
311
- else
312
- traces[1]['Query'].must_equal "select_by_name"
313
- end
314
-
315
- if RUBY_VERSION < "1.9"
316
- traces[1]['QueryArgs'].must_equal "abc"
317
- else
318
- traces[1]['QueryArgs'].must_equal "[\"abc\"]"
319
- end
320
- traces[1]['IsPreparedStatement'].must_equal "true"
321
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
322
- validate_event_keys(traces[2], @exit_kvs)
323
- end
324
-
325
- it 'should trace prep\'d stmnts and obey query privacy' do
326
- AppOpticsAPM::Config[:sanitize_sql] = true
327
- ds = MYSQL2_DB[:items].filter(:name=>:$n)
328
- ps = ds.prepare(:select, :select_by_name)
329
-
330
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
331
- ps.call(:n=>'abc')
332
- end
333
-
334
- traces = get_all_traces
335
-
336
- traces.count.must_equal 4
337
- validate_outer_layers(traces, 'sequel_test')
338
-
339
- validate_event_keys(traces[1], @entry_kvs)
340
-
341
- if ::Sequel::VERSION > '4.36.0'
342
- traces[1]['Query'].must_equal "SELECT * FROM `items` WHERE (`name` = ?)"
343
- else
344
- traces[1]['Query'].must_equal "select_by_name"
345
- end
346
-
347
- traces[1]['QueryArgs'].must_be_nil
348
- traces[1]['IsPreparedStatement'].must_equal "true"
349
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
350
- validate_event_keys(traces[2], @exit_kvs)
351
- end
352
- end
353
- end