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,334 +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) && (RUBY_VERSION < "2.4")
7
-
8
- AppOpticsAPM::Test.set_mysql_env
9
- MYSQL_DB = Sequel.connect(ENV['DATABASE_URL'])
10
-
11
- unless MYSQL_DB.table_exists?(:items)
12
- MYSQL_DB.create_table :items do
13
- primary_key :id
14
- String :name
15
- Float :price
16
- end
17
- end
18
-
19
- describe "Sequel (mysql)" 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
- MYSQL_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
- MYSQL_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 MYSQL_DB.run insert' do
79
- AppOpticsAPM::Config[:sanitize_sql] = false
80
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
81
- MYSQL_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 MYSQL_DB.run select' do
96
- AppOpticsAPM::Config[:sanitize_sql] = false
97
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
98
- MYSQL_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 = MYSQL_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 = MYSQL_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 = MYSQL_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
- MYSQL_DB.drop_table(:fake) if MYSQL_DB.table_exists?(:fake)
194
-
195
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
196
- MYSQL_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
- MYSQL_DB.drop_table(:fake) if MYSQL_DB.table_exists?(:fake)
218
-
219
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
220
- MYSQL_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
- MYSQL_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 = MYSQL_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
- traces[1]['Query'].must_equal "SELECT * FROM `items` WHERE (`name` = 'abc')"
280
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
281
- traces[3]['Query'].must_equal "DELETE FROM `items` WHERE (`name` = 'cba')"
282
- traces[3].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
283
- validate_event_keys(traces[2], @exit_kvs)
284
- end
285
-
286
- it 'should trace prepared statements' do
287
- AppOpticsAPM::Config[:sanitize_sql] = false
288
- ds = MYSQL_DB[:items].filter(:name=>:$n)
289
- ps = ds.prepare(:select, :select_by_name)
290
-
291
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
292
- ps.call(:n=>'abc')
293
- end
294
-
295
- traces = get_all_traces
296
-
297
- traces.count.must_equal 4
298
- validate_outer_layers(traces, 'sequel_test')
299
-
300
- validate_event_keys(traces[1], @entry_kvs)
301
- traces[1]['Query'].must_equal "select_by_name"
302
- if RUBY_VERSION < "1.9"
303
- traces[1]['QueryArgs'].must_equal "abc"
304
- else
305
- traces[1]['QueryArgs'].must_equal "[\"abc\"]"
306
- end
307
- traces[1]['IsPreparedStatement'].must_equal "true"
308
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
309
- validate_event_keys(traces[2], @exit_kvs)
310
- end
311
-
312
- it 'should trace prep\'d stmnts and obey query privacy' do
313
- AppOpticsAPM::Config[:sanitize_sql] = true
314
- ds = MYSQL_DB[:items].filter(:name=>:$n)
315
- ps = ds.prepare(:select, :select_by_name)
316
-
317
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
318
- ps.call(:n=>'abc')
319
- end
320
-
321
- traces = get_all_traces
322
-
323
- traces.count.must_equal 4
324
- validate_outer_layers(traces, 'sequel_test')
325
-
326
- validate_event_keys(traces[1], @entry_kvs)
327
- traces[1]['Query'].must_equal "select_by_name"
328
- traces[1]['QueryArgs'].must_be_nil
329
- traces[1]['IsPreparedStatement'].must_equal "true"
330
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
331
- validate_event_keys(traces[2], @exit_kvs)
332
- end
333
- end
334
- end
@@ -1,336 +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_postgresql_env
9
- PG_DB = Sequel.connect(ENV['DATABASE_URL'])
10
-
11
- unless PG_DB.table_exists?(:items)
12
- PG_DB.create_table :items do
13
- primary_key :id
14
- String :name
15
- Float :price
16
- end
17
- end
18
-
19
- describe "Sequel (postgres)" 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' => '127.0.0.1',
29
- 'RemotePort' => 5432 }
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
- PG_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
- PG_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 PG_DB.run insert' do
79
- AppOpticsAPM::Config[:sanitize_sql] = false
80
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
81
- PG_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 PG_DB.run select' do
96
- AppOpticsAPM::Config[:sanitize_sql] = false
97
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
98
- PG_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 = PG_DB[:items]
115
- # Preload the primary key to avoid breaking tests with the seemingly
116
- # random lookup (random due to random test order)
117
- PG_DB.primary_key(:items)
118
-
119
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
120
- items.insert(:name => 'abc', :price => 2.514)
121
- items.count
122
- end
123
-
124
- traces = get_all_traces
125
-
126
- traces.count.must_equal 6
127
- validate_outer_layers(traces, 'sequel_test')
128
-
129
- validate_event_keys(traces[1], @entry_kvs)
130
-
131
- # SQL column/value order can vary between Ruby and gem versions
132
- # Use must_include to test against one or the other
133
- [
134
- "INSERT INTO \"items\" (\"price\", \"name\") VALUES (2.514, 'abc') RETURNING \"id\"",
135
- "INSERT INTO \"items\" (\"name\", \"price\") VALUES ('abc', 2.514) RETURNING \"id\""
136
- ].must_include traces[1]['Query']
137
-
138
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
139
- traces[2]['Layer'].must_equal "sequel"
140
- traces[2]['Label'].must_equal "exit"
141
- traces[3]['Query'].downcase.must_equal "select count(*) as \"count\" from \"items\" limit 1"
142
- validate_event_keys(traces[4], @exit_kvs)
143
- end
144
-
145
- it 'should trace a dataset insert and obey query privacy' do
146
- AppOpticsAPM::Config[:sanitize_sql] = true
147
- items = PG_DB[:items]
148
- # Preload the primary key to avoid breaking tests with the seemingly
149
- # random lookup (random due to random test order)
150
- PG_DB.primary_key(:items)
151
-
152
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
153
- items.insert(:name => 'abc', :price => 2.514461383352462)
154
- end
155
-
156
- traces = get_all_traces
157
-
158
- traces.count.must_equal 4
159
- validate_outer_layers(traces, 'sequel_test')
160
-
161
- validate_event_keys(traces[1], @entry_kvs)
162
-
163
- # SQL column/value order can vary between Ruby and gem versions
164
- # Use must_include to test against one or the other
165
- [
166
- "INSERT INTO \"items\" (\"price\", \"name\") VALUES (?, ?) RETURNING \"id\"",
167
- "INSERT INTO \"items\" (\"name\", \"price\") VALUES (?, ?) RETURNING \"id\""
168
- ].must_include traces[1]['Query']
169
-
170
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
171
- validate_event_keys(traces[2], @exit_kvs)
172
- end
173
-
174
- it 'should trace a dataset filter' do
175
- AppOpticsAPM::Config[:sanitize_sql] = false
176
- items = PG_DB[:items]
177
- items.count
178
-
179
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
180
- items.filter(:name => 'abc').all
181
- end
182
-
183
- traces = get_all_traces
184
-
185
- traces.count.must_equal 4
186
- validate_outer_layers(traces, 'sequel_test')
187
-
188
- validate_event_keys(traces[1], @entry_kvs)
189
- traces[1]['Query'].must_equal "SELECT * FROM \"items\" WHERE (\"name\" = 'abc')"
190
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
191
- validate_event_keys(traces[2], @exit_kvs)
192
- end
193
-
194
- it 'should trace create table' do
195
- # Drop the table if it already exists
196
- PG_DB.drop_table(:fake) if PG_DB.table_exists?(:fake)
197
-
198
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
199
- PG_DB.create_table :fake do
200
- primary_key :id
201
- String :name
202
- Float :price
203
- end
204
- end
205
-
206
- traces = get_all_traces
207
-
208
- traces.count.must_equal 4
209
- validate_outer_layers(traces, 'sequel_test')
210
-
211
- validate_event_keys(traces[1], @entry_kvs)
212
- traces[1]['Query'].must_equal "CREATE TABLE \"fake\" (\"id\" serial PRIMARY KEY, \"name\" text, \"price\" double precision)"
213
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
214
- validate_event_keys(traces[2], @exit_kvs)
215
- end
216
-
217
- it 'should trace add index' do
218
- # Drop the table if it already exists
219
- PG_DB.drop_table(:fake) if PG_DB.table_exists?(:fake)
220
-
221
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
222
- PG_DB.create_table :fake do
223
- primary_key :id
224
- String :name
225
- Float :price
226
- end
227
- end
228
-
229
- traces = get_all_traces
230
-
231
- traces.count.must_equal 4
232
- validate_outer_layers(traces, 'sequel_test')
233
-
234
- validate_event_keys(traces[1], @entry_kvs)
235
- traces[1]['Query'].must_equal "CREATE TABLE \"fake\" (\"id\" serial PRIMARY KEY, \"name\" text, \"price\" double precision)"
236
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
237
- validate_event_keys(traces[2], @exit_kvs)
238
- end
239
-
240
- it 'should capture and report exceptions' do
241
- begin
242
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
243
- PG_DB.run("this is bad sql")
244
- end
245
- rescue
246
- # Do nothing - we're testing exception logging
247
- end
248
-
249
- traces = get_all_traces
250
-
251
- traces.count.must_equal 5
252
- validate_outer_layers(traces, 'sequel_test')
253
-
254
- validate_event_keys(traces[1], @entry_kvs)
255
- traces[1]['Query'].must_equal "this is bad sql"
256
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
257
- traces[2]['Layer'].must_equal "sequel"
258
- traces[2]['Label'].must_equal "error"
259
- traces[2].has_key?('Backtrace').must_equal true
260
- traces[2]['ErrorClass'].must_equal "Sequel::DatabaseError"
261
- validate_event_keys(traces[3], @exit_kvs)
262
- end
263
-
264
- it 'should trace placeholder queries with bound vars' do
265
- AppOpticsAPM::Config[:sanitize_sql] = false
266
- items = PG_DB[:items]
267
- items.count
268
-
269
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
270
- ds = items.where(:name=>:$n)
271
- ds.call(:select, :n=>'abc')
272
- ds.call(:delete, :n=>'cba')
273
- end
274
-
275
- traces = get_all_traces
276
-
277
- traces.count.must_equal 6
278
- validate_outer_layers(traces, 'sequel_test')
279
-
280
- validate_event_keys(traces[1], @entry_kvs)
281
- traces[1]['Query'].must_equal "SELECT * FROM \"items\" WHERE (\"name\" = $1)"
282
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
283
- traces[3]['Query'].must_equal "DELETE FROM \"items\" WHERE (\"name\" = $1)"
284
- traces[3].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
285
- validate_event_keys(traces[2], @exit_kvs)
286
- end
287
-
288
- it 'should trace prepared statements' do
289
- AppOpticsAPM::Config[:sanitize_sql] = false
290
- ds = PG_DB[:items].filter(:name=>:$n)
291
- ps = ds.prepare(:select, :select_by_name)
292
-
293
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
294
- ps.call(:n=>'abc')
295
- end
296
-
297
- traces = get_all_traces
298
-
299
- traces.count.must_equal 4
300
- validate_outer_layers(traces, 'sequel_test')
301
-
302
- validate_event_keys(traces[1], @entry_kvs)
303
- traces[1]['Query'].must_equal "select_by_name"
304
- if RUBY_VERSION < "1.9"
305
- traces[1]['QueryArgs'].must_equal "abc"
306
- else
307
- traces[1]['QueryArgs'].must_equal "[\"abc\"]"
308
- end
309
- traces[1]['IsPreparedStatement'].must_equal "true"
310
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
311
- validate_event_keys(traces[2], @exit_kvs)
312
- end
313
-
314
- it 'should trace prep\'d stmnts and obey query privacy' do
315
- AppOpticsAPM::Config[:sanitize_sql] = true
316
- ds = PG_DB[:items].filter(:name=>:$n)
317
- ps = ds.prepare(:select, :select_by_name)
318
-
319
- AppOpticsAPM::API.start_trace('sequel_test', '', {}) do
320
- ps.call(:n=>'abc')
321
- end
322
-
323
- traces = get_all_traces
324
-
325
- traces.count.must_equal 4
326
- validate_outer_layers(traces, 'sequel_test')
327
-
328
- validate_event_keys(traces[1], @entry_kvs)
329
- traces[1]['Query'].must_equal "select_by_name"
330
- traces[1]['QueryArgs'].must_be_nil
331
- traces[1]['IsPreparedStatement'].must_equal "true"
332
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:sequel][:collect_backtraces]
333
- validate_event_keys(traces[2], @exit_kvs)
334
- end
335
- end
336
- end