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,124 +0,0 @@
1
- # Copyright (c) 2016 SolarWinds, LLC.
2
- # All rights reserved.
3
-
4
- require 'minitest_helper'
5
-
6
- unless ENV['APPOPTICS_MONGO_SERVER']
7
- ENV['APPOPTICS_MONGO_SERVER'] = "127.0.0.1:27017"
8
- end
9
-
10
- if defined?(::Mongo::VERSION) && Mongo::VERSION >= '2.0.0'
11
- describe "MongoIndex" do
12
- before do
13
- clear_all_traces
14
-
15
- @client = Mongo::Client.new([ ENV['APPOPTICS_MONGO_SERVER'] ], :database => "appoptics_apm-#{ENV['RACK_ENV']}")
16
- if Mongo::VERSION < '2.2'
17
- Mongo::Logger.logger.level = Logger::INFO
18
- else
19
- @client.logger.level = Logger::INFO
20
- end
21
- @db = @client.database
22
-
23
- @collections = @db.collection_names
24
- @testCollection = @client[:test_collection]
25
- @testCollection.create unless @collections.include? "test_collection"
26
-
27
- # These are standard entry/exit KVs that are passed up with all mongo operations
28
- @entry_kvs = {
29
- 'Layer' => 'mongo',
30
- 'Label' => 'entry',
31
- 'Flavor' => 'mongodb',
32
- 'Database' => 'appoptics_apm-test',
33
- 'RemoteHost' => ENV['APPOPTICS_MONGO_SERVER'] }
34
-
35
- @exit_kvs = { 'Layer' => 'mongo', 'Label' => 'exit' }
36
- @collect_backtraces = AppOpticsAPM::Config[:mongo][:collect_backtraces]
37
- end
38
-
39
- after do
40
- AppOpticsAPM::Config[:mongo][:collect_backtraces] = @collect_backtraces
41
- end
42
-
43
- it "should trace create_one" do
44
- coll = @db[:test_collection]
45
- coll.indexes.drop_all
46
-
47
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
48
- coll.indexes.create_one({ :name => 1 })
49
- end
50
-
51
- traces = get_all_traces
52
- traces.count.must_equal 4
53
-
54
- validate_outer_layers(traces, 'mongo_test')
55
- validate_event_keys(traces[1], @entry_kvs)
56
- validate_event_keys(traces[2], @exit_kvs)
57
-
58
- traces[1]['Collection'].must_equal "test_collection"
59
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
60
- traces[1]['QueryOp'].must_equal "create_one"
61
- end
62
-
63
- it "should trace create_many" do
64
- coll = @db[:test_collection]
65
- coll.indexes.drop_all
66
-
67
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
68
- coll.indexes.create_many([ { :key => {:asdf => 1}, :unique => false },
69
- { :key => {:age => -1}, :background => true} ])
70
- end
71
-
72
- traces = get_all_traces
73
- traces.count.must_equal 4
74
-
75
- validate_outer_layers(traces, 'mongo_test')
76
- validate_event_keys(traces[1], @entry_kvs)
77
- validate_event_keys(traces[2], @exit_kvs)
78
-
79
- traces[1]['Collection'].must_equal "test_collection"
80
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
81
- traces[1]['QueryOp'].must_equal "create_many"
82
- end
83
-
84
- it "should trace drop_one" do
85
- coll = @db[:test_collection]
86
- coll.indexes.create_one({ :name => 1 })
87
-
88
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
89
- coll.indexes.drop_one('name_1')
90
- end
91
-
92
- traces = get_all_traces
93
- traces.count.must_equal 4
94
-
95
- validate_outer_layers(traces, 'mongo_test')
96
- validate_event_keys(traces[1], @entry_kvs)
97
- validate_event_keys(traces[2], @exit_kvs)
98
-
99
- traces[1]['Collection'].must_equal "test_collection"
100
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
101
- traces[1]['QueryOp'].must_equal "drop_one"
102
- end
103
-
104
- it "should trace drop_all" do
105
- coll = @db[:test_collection]
106
- coll.indexes.create_one({ :name => 1 })
107
-
108
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
109
- coll.indexes.drop_all
110
- end
111
-
112
- traces = get_all_traces
113
- traces.count.must_equal 4
114
-
115
- validate_outer_layers(traces, 'mongo_test')
116
- validate_event_keys(traces[1], @entry_kvs)
117
- validate_event_keys(traces[2], @exit_kvs)
118
-
119
- traces[1]['Collection'].must_equal "test_collection"
120
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
121
- traces[1]['QueryOp'].must_equal "drop_all"
122
- end
123
- end
124
- end
@@ -1,584 +0,0 @@
1
- # Copyright (c) 2016 SolarWinds, LLC.
2
- # All rights reserved.
3
-
4
- require 'minitest_helper'
5
-
6
- ENV['APPOPTICS_MONGO_SERVER'] = "127.0.0.1:27017" unless ENV['APPOPTICS_MONGO_SERVER']
7
- ENV['APPOPTICS_MONGO_SERVER'] += ":27017" unless ENV['APPOPTICS_MONGO_SERVER'] =~ /\:27017$/
8
-
9
- if defined?(::Mongo::VERSION) && Mongo::VERSION >= '2.0.0'
10
- describe "MongoCollection" do
11
- before do
12
- clear_all_traces
13
-
14
- @client = Mongo::Client.new([ ENV['APPOPTICS_MONGO_SERVER'] ], :database => "appoptics_apm-#{ENV['RACK_ENV']}")
15
- @db = @client.database
16
-
17
- if Mongo::VERSION < '2.2'
18
- Mongo::Logger.logger.level = Logger::INFO
19
- else
20
- @client.logger.level = Logger::INFO
21
- end
22
-
23
- @collections = @db.collection_names
24
- @testCollection = @client[:test_collection]
25
- @testCollection.create unless @collections.include? "test_collection"
26
-
27
- # These are standard entry/exit KVs that are passed up with all mongo operations
28
- @entry_kvs = {
29
- 'Layer' => 'mongo',
30
- 'Label' => 'entry',
31
- 'Flavor' => 'mongodb',
32
- 'Database' => 'appoptics_apm-test',
33
- 'RemoteHost' => ENV['APPOPTICS_MONGO_SERVER'] }
34
-
35
- @exit_kvs = { 'Layer' => 'mongo', 'Label' => 'exit' }
36
- @collect_backtraces = AppOpticsAPM::Config[:mongo][:collect_backtraces]
37
- end
38
-
39
- after do
40
- AppOpticsAPM::Config[:mongo][:collect_backtraces] = @collect_backtraces
41
-
42
- if @db.collection_names.include?("temp_collection")
43
- @db[:temp_collection].drop
44
- end
45
- end
46
-
47
- it "should trace collection creation" do
48
- r = nil
49
- collection = @db[:temp_collection]
50
- AppOpticsAPM::API.start_trace('mongo_test', nil, {}) do
51
- r = collection.create
52
- end
53
-
54
- traces = get_all_traces
55
- traces.count.must_equal 4
56
-
57
- r.must_be_instance_of ::Mongo::Operation::Result
58
- if Mongo::VERSION < '2.2'
59
- r.successful?.must_equal true
60
- else
61
- r.ok?.must_equal true
62
- end
63
-
64
- validate_outer_layers(traces, 'mongo_test')
65
- validate_event_keys(traces[1], @entry_kvs)
66
- validate_event_keys(traces[2], @exit_kvs)
67
-
68
- traces[1]['QueryOp'].must_equal "create"
69
- traces[1]['New_Collection_Name'].must_equal "temp_collection"
70
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
71
- end
72
-
73
- it "should trace drop_collection" do
74
- r = nil
75
- collection = @db[:deleteme_collection]
76
-
77
- # Create something to drop unless it already exists
78
- unless @db.collection_names.include?("deleteme_collection")
79
- collection.create
80
- end
81
-
82
- AppOpticsAPM::API.start_trace('mongo_test', nil, {}) do
83
- r = collection.drop
84
- end
85
-
86
- traces = get_all_traces
87
- traces.count.must_equal 4
88
-
89
- r.must_be_instance_of ::Mongo::Operation::Result
90
- if Mongo::VERSION < '2.2'
91
- r.successful?.must_equal true
92
- else
93
- r.ok?.must_equal true
94
- end
95
-
96
- validate_outer_layers(traces, 'mongo_test')
97
- validate_event_keys(traces[1], @entry_kvs)
98
- validate_event_keys(traces[2], @exit_kvs)
99
-
100
- traces[1]['QueryOp'].must_equal "drop"
101
- traces[1]['Collection'].must_equal "deleteme_collection"
102
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
103
- end
104
-
105
- it "should capture collection creation errors" do
106
- collection = @db[:temp_collection]
107
- collection.create
108
-
109
- begin
110
- AppOpticsAPM::API.start_trace('mongo_test', nil, {}) do
111
- collection.create
112
- end
113
- rescue
114
- end
115
-
116
- traces = get_all_traces
117
- traces.count.must_equal 5
118
-
119
- validate_outer_layers(traces, 'mongo_test')
120
- validate_event_keys(traces[1], @entry_kvs)
121
- validate_event_keys(traces[3], @exit_kvs)
122
-
123
- traces[1]['QueryOp'].must_equal "create"
124
- traces[1]['New_Collection_Name'].must_equal "temp_collection"
125
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
126
-
127
- traces[2]['Layer'].must_equal "mongo"
128
- traces[2]['Label'].must_equal "error"
129
- traces[2]['ErrorClass'].must_equal "Mongo::Error::OperationFailure"
130
- traces[2]['ErrorMsg'].must_match /collection.*already exists/
131
- traces[2].has_key?('Backtrace').must_equal true
132
- end
133
-
134
- it "should trace insert_one" do
135
- r = nil
136
- collection = @db[:tv_collection]
137
-
138
- AppOpticsAPM::API.start_trace('mongo_test', nil, {}) do
139
- r = collection.insert_one({ name => 'Rabel Lasen' })
140
- end
141
-
142
- traces = get_all_traces
143
- traces.count.must_equal 4
144
-
145
- r.must_be_instance_of Mongo::Operation::Write::Insert::Result
146
- if Mongo::VERSION < '2.2'
147
- r.successful?.must_equal true
148
- else
149
- r.ok?.must_equal true
150
- end
151
-
152
- validate_outer_layers(traces, 'mongo_test')
153
- validate_event_keys(traces[1], @entry_kvs)
154
- validate_event_keys(traces[2], @exit_kvs)
155
-
156
- traces[1]['QueryOp'].must_equal "insert_one"
157
- traces[1]['Collection'].must_equal "tv_collection"
158
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
159
- end
160
-
161
- it "should trace insert_many" do
162
- r = nil
163
- collection = @db[:tv_collection]
164
-
165
- AppOpticsAPM::API.start_trace('mongo_test', nil, {}) do
166
- r = collection.insert_many([
167
- { :name => 'Rabel Lasen' },
168
- { :name => 'Louval Raiden' }])
169
- end
170
-
171
- traces = get_all_traces
172
- traces.count.must_equal 4
173
-
174
- if Mongo::VERSION < '2.1'
175
- r.must_be_instance_of Mongo::Operation::Write::Insert::Result
176
- else
177
- r.must_be_instance_of Mongo::BulkWrite::Result
178
- r.inserted_count.must_equal 2
179
- end
180
-
181
- validate_outer_layers(traces, 'mongo_test')
182
- validate_event_keys(traces[1], @entry_kvs)
183
- validate_event_keys(traces[2], @exit_kvs)
184
-
185
- traces[1]['QueryOp'].must_equal "insert_many"
186
- traces[1]['Collection'].must_equal "tv_collection"
187
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
188
- end
189
-
190
- it "should trace find" do
191
- coll = @db[:test_collection]
192
- r = nil
193
-
194
- # Insert a doc to assure we get a result
195
- doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
196
- coll.insert_one(doc)
197
-
198
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
199
- r = coll.find(:name => "MyName", :limit => 1)
200
- end
201
-
202
- traces = get_all_traces
203
- traces.count.must_equal 4
204
-
205
- validate_outer_layers(traces, 'mongo_test')
206
- validate_event_keys(traces[1], @entry_kvs)
207
- validate_event_keys(traces[2], @exit_kvs)
208
-
209
- r.must_be_instance_of Mongo::Collection::View
210
-
211
- traces[1]['Collection'].must_equal "test_collection"
212
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
213
- traces[1]['QueryOp'].must_equal "find"
214
- traces[1]['Query'].must_equal "{\"name\":\"MyName\",\"limit\":1}"
215
- traces[1].has_key?('Query').must_equal true
216
- end
217
-
218
- it "should trace find_one_and_delete" do
219
- skip unless Mongo::VERSION >= '2.1'
220
-
221
- coll = @db[:test_collection]
222
- r = nil
223
-
224
- # Insert a doc to assure we get a result
225
- doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
226
- coll.insert_one(doc)
227
-
228
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
229
- r = coll.find_one_and_delete(:name => "MyName")
230
- end
231
-
232
- traces = get_all_traces
233
- traces.count.must_equal 4
234
-
235
- validate_outer_layers(traces, 'mongo_test')
236
- validate_event_keys(traces[1], @entry_kvs)
237
- validate_event_keys(traces[2], @exit_kvs)
238
-
239
- r.must_be_instance_of BSON::Document
240
-
241
- traces[1]['Collection'].must_equal "test_collection"
242
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
243
- traces[1]['QueryOp'].must_equal "find_one_and_delete"
244
- traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
245
- traces[1].has_key?('Query').must_equal true
246
- end
247
-
248
- it "should trace find_one_and_update" do
249
- skip unless Mongo::VERSION >= '2.1'
250
- coll = @db[:test_collection]
251
- r = nil
252
-
253
- # Insert a doc to assure we get a result
254
- doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
255
- coll.insert_one(doc)
256
-
257
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
258
- r = coll.find_one_and_update({ :name => 'MyName' }, { "$set" => { :name => 'test1' }}, :return_document => :after)
259
- end
260
-
261
- traces = get_all_traces
262
- traces.count.must_equal 4
263
-
264
- validate_outer_layers(traces, 'mongo_test')
265
- validate_event_keys(traces[1], @entry_kvs)
266
- validate_event_keys(traces[2], @exit_kvs)
267
-
268
- r.must_be_instance_of BSON::Document
269
-
270
- traces[1]['Collection'].must_equal "test_collection"
271
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
272
- traces[1]['QueryOp'].must_equal "find_one_and_update"
273
- traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
274
- traces[1].has_key?('Query').must_equal true
275
- end
276
-
277
- it "should trace find_one_and_replace" do
278
- skip unless Mongo::VERSION >= '2.1'
279
- coll = @db[:test_collection]
280
- r = nil
281
-
282
- # Insert a doc to assure we get a result
283
- doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
284
- coll.insert_one(doc)
285
-
286
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
287
- r = coll.find_one_and_replace({ :name => 'MyName' }, { "$set" => { :name => 'test1' }}, :return_document => :after)
288
- end
289
-
290
- traces = get_all_traces
291
- traces.count.must_equal 4
292
-
293
- validate_outer_layers(traces, 'mongo_test')
294
- validate_event_keys(traces[1], @entry_kvs)
295
- validate_event_keys(traces[2], @exit_kvs)
296
-
297
- r.must_be_instance_of BSON::Document
298
-
299
- traces[1]['Collection'].must_equal "test_collection"
300
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
301
- traces[1]['QueryOp'].must_equal "find_one_and_replace"
302
- traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
303
- traces[1].has_key?('Query').must_equal true
304
- end
305
-
306
- it "should trace update_one" do
307
- skip unless Mongo::VERSION >= '2.1'
308
-
309
- coll = @db[:test_collection]
310
- r = nil
311
-
312
- # Insert a doc to assure we get a result
313
- doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
314
- coll.insert_one(doc)
315
-
316
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
317
- r = coll.update_one({ :name => 'MyName' }, { "$set" => { :name => 'test1' }}, :return_document => :after)
318
- end
319
-
320
- traces = get_all_traces
321
- traces.count.must_equal 4
322
-
323
- validate_outer_layers(traces, 'mongo_test')
324
- validate_event_keys(traces[1], @entry_kvs)
325
- validate_event_keys(traces[2], @exit_kvs)
326
-
327
- r.class.ancestors.include?(Mongo::Operation::Result).must_equal true
328
-
329
- traces[1]['Collection'].must_equal "test_collection"
330
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
331
- traces[1]['QueryOp'].must_equal "update_one"
332
- traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
333
- traces[1].has_key?('Query').must_equal true
334
- end
335
-
336
- it "should trace update_many" do
337
- skip unless Mongo::VERSION > '2.1'
338
- coll = @db[:test_collection]
339
- r = nil
340
-
341
- # Insert a doc to assure we get a result
342
- doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
343
- coll.insert_one(doc)
344
-
345
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
346
- r = coll.update_many({ :name => 'MyName' }, { "$set" => { :name => 'test1' }}, :return_document => :after)
347
- end
348
-
349
- traces = get_all_traces
350
- traces.count.must_equal 4
351
-
352
- validate_outer_layers(traces, 'mongo_test')
353
- validate_event_keys(traces[1], @entry_kvs)
354
- validate_event_keys(traces[2], @exit_kvs)
355
-
356
- r.class.ancestors.include?(Mongo::Operation::Result).must_equal true
357
-
358
- traces[1]['Collection'].must_equal "test_collection"
359
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
360
- traces[1]['QueryOp'].must_equal "update_many"
361
- traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
362
- traces[1].has_key?('Query').must_equal true
363
- end
364
-
365
- it "should trace delete_one" do
366
- skip unless Mongo::VERSION > '2.1'
367
- coll = @db[:test_collection]
368
- r = nil
369
-
370
- # Insert a doc to assure we get a result
371
- doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
372
- coll.insert_one(doc)
373
-
374
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
375
- r = coll.delete_one({ :name => 'MyName' })
376
- end
377
-
378
- traces = get_all_traces
379
- traces.count.must_equal 4
380
-
381
- validate_outer_layers(traces, 'mongo_test')
382
- validate_event_keys(traces[1], @entry_kvs)
383
- validate_event_keys(traces[2], @exit_kvs)
384
-
385
- r.class.ancestors.include?(Mongo::Operation::Result).must_equal true
386
-
387
- traces[1]['Collection'].must_equal "test_collection"
388
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
389
- traces[1]['QueryOp'].must_equal "delete_one"
390
- traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
391
- traces[1].has_key?('Query').must_equal true
392
- end
393
-
394
- it "should trace delete_many" do
395
- skip unless Mongo::VERSION > '2.1'
396
- coll = @db[:test_collection]
397
- r = nil
398
-
399
- # Insert a doc to assure we get a result
400
- doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
401
- coll.insert_one(doc)
402
-
403
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
404
- r = coll.delete_many({ :name => 'MyName' })
405
- end
406
-
407
- traces = get_all_traces
408
- traces.count.must_equal 4
409
-
410
- validate_outer_layers(traces, 'mongo_test')
411
- validate_event_keys(traces[1], @entry_kvs)
412
- validate_event_keys(traces[2], @exit_kvs)
413
-
414
- r.class.ancestors.include?(Mongo::Operation::Result).must_equal true
415
-
416
- traces[1]['Collection'].must_equal "test_collection"
417
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
418
- traces[1]['QueryOp'].must_equal "delete_many"
419
- traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
420
- traces[1].has_key?('Query').must_equal true
421
- end
422
-
423
- it "should trace replace_one" do
424
- skip unless Mongo::VERSION > '2.1'
425
- coll = @db[:test_collection]
426
- r = nil
427
-
428
- # Insert a doc to assure we get a result
429
- doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
430
- coll.insert_one(doc)
431
-
432
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
433
- r = coll.replace_one({ :name => 'test' }, { :name => 'test1' })
434
- end
435
-
436
- traces = get_all_traces
437
- traces.count.must_equal 4
438
-
439
- validate_outer_layers(traces, 'mongo_test')
440
- validate_event_keys(traces[1], @entry_kvs)
441
- validate_event_keys(traces[2], @exit_kvs)
442
-
443
- r.class.ancestors.include?(Mongo::Operation::Result).must_equal true
444
-
445
- traces[1]['Collection'].must_equal "test_collection"
446
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
447
- traces[1]['QueryOp'].must_equal "replace_one"
448
- traces[1]['Query'].must_equal "{\"name\":\"test\"}"
449
- traces[1].has_key?('Query').must_equal true
450
- end
451
-
452
- it "should trace count" do
453
- skip unless Mongo::VERSION > '2.1'
454
- coll = @db[:test_collection]
455
- r = nil
456
-
457
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
458
- r = coll.count({ :name => 'MyName' })
459
- end
460
-
461
- traces = get_all_traces
462
- traces.count.must_equal 4
463
-
464
- validate_outer_layers(traces, 'mongo_test')
465
- validate_event_keys(traces[1], @entry_kvs)
466
- validate_event_keys(traces[2], @exit_kvs)
467
-
468
- r.is_a?(Numeric).must_equal true
469
-
470
- traces[1]['Collection'].must_equal "test_collection"
471
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
472
- traces[1]['QueryOp'].must_equal "count"
473
- traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
474
- traces[1].has_key?('Query').must_equal true
475
- end
476
-
477
- it "should trace distinct" do
478
- skip unless Mongo::VERSION > '2.1'
479
- coll = @db[:test_collection]
480
- r = nil
481
-
482
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
483
- r = coll.distinct('name', { :name => 'MyName' })
484
- end
485
-
486
- traces = get_all_traces
487
- traces.count.must_equal 4
488
-
489
- validate_outer_layers(traces, 'mongo_test')
490
- validate_event_keys(traces[1], @entry_kvs)
491
- validate_event_keys(traces[2], @exit_kvs)
492
-
493
- r.is_a?(Array).must_equal true
494
-
495
- traces[1]['Collection'].must_equal "test_collection"
496
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
497
- traces[1]['QueryOp'].must_equal "distinct"
498
- traces[1]['Query'].must_equal "{\"name\":\"MyName\"}"
499
- traces[1].has_key?('Query').must_equal true
500
- end
501
-
502
- it "should trace aggregate" do
503
- skip unless Mongo::VERSION >= '2.1'
504
- coll = @db[:test_collection]
505
- r = nil
506
-
507
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
508
- r = coll.aggregate([ { "$group" => { "_id" => "$city", "tpop" => { "$sum" => "$pop" }}} ])
509
- end
510
-
511
- traces = get_all_traces
512
- traces.count.must_equal 4
513
-
514
- validate_outer_layers(traces, 'mongo_test')
515
- validate_event_keys(traces[1], @entry_kvs)
516
- validate_event_keys(traces[2], @exit_kvs)
517
-
518
- r.must_be_instance_of Mongo::Collection::View::Aggregation
519
-
520
- traces[1]['Collection'].must_equal "test_collection"
521
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
522
- traces[1]['QueryOp'].must_equal "aggregate"
523
- traces[1].key?('Query').must_equal false
524
- end
525
-
526
- it "should trace bulk_write" do
527
- coll = @db[:test_collection]
528
- r = nil
529
-
530
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
531
- r = coll.bulk_write([ { :insert_one => { :x => 1} },
532
- { :insert_one => { :x => 3} } ],
533
- :ordered => true)
534
- end
535
-
536
- traces = get_all_traces
537
- traces.count.must_equal 4
538
-
539
- validate_outer_layers(traces, 'mongo_test')
540
- validate_event_keys(traces[1], @entry_kvs)
541
- validate_event_keys(traces[2], @exit_kvs)
542
-
543
- if Mongo::VERSION < '2.1'
544
- r.must_be_instance_of Hash
545
- r[:n_inserted].must_equal 2
546
- else
547
- r.must_be_instance_of Mongo::BulkWrite::Result
548
- end
549
-
550
- traces[1]['Collection'].must_equal "test_collection"
551
- traces[1].has_key?('Backtrace').must_equal AppOpticsAPM::Config[:mongo][:collect_backtraces]
552
- traces[1]['QueryOp'].must_equal "bulk_write"
553
- traces[1].key?('Query').must_equal false
554
- end
555
-
556
- it "should obey :collect_backtraces setting when true" do
557
- AppOpticsAPM::Config[:mongo][:collect_backtraces] = true
558
-
559
- coll = @db[:test_collection]
560
-
561
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
562
- doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
563
- coll.insert_one(doc)
564
- end
565
-
566
- traces = get_all_traces
567
- layer_has_key(traces, 'mongo', 'Backtrace')
568
- end
569
-
570
- it "should obey :collect_backtraces setting when false" do
571
- AppOpticsAPM::Config[:mongo][:collect_backtraces] = false
572
-
573
- coll = @db[:test_collection]
574
-
575
- AppOpticsAPM::API.start_trace('mongo_test', '', {}) do
576
- doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
577
- coll.insert_one(doc)
578
- end
579
-
580
- traces = get_all_traces
581
- layer_doesnt_have_key(traces, 'mongo', 'Backtrace')
582
- end
583
- end
584
- end