oboe 2.2.6 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. data/.gitignore +6 -1
  2. data/Appraisals +20 -0
  3. data/Gemfile +16 -20
  4. data/README.md +280 -10
  5. data/Rakefile +63 -7
  6. data/ext/oboe_metal/extconf.rb +2 -1
  7. data/ext/oboe_metal/tests/test.rb +4 -0
  8. data/gemfiles/rails2.3.gemfile +18 -0
  9. data/gemfiles/rails2.3.gemfile.lock +95 -0
  10. data/gemfiles/rails3.0.gemfile +18 -0
  11. data/gemfiles/rails3.0.gemfile.lock +142 -0
  12. data/gemfiles/rails3.1.gemfile +18 -0
  13. data/gemfiles/rails3.1.gemfile.lock +152 -0
  14. data/gemfiles/rails3.2.gemfile +18 -0
  15. data/gemfiles/rails3.2.gemfile.lock +150 -0
  16. data/init.rb +1 -1
  17. data/lib/joboe_metal.rb +52 -34
  18. data/lib/method_profiling.rb +1 -1
  19. data/lib/oboe.rb +6 -5
  20. data/lib/oboe/api.rb +1 -1
  21. data/lib/oboe/api/layerinit.rb +3 -0
  22. data/lib/oboe/api/logging.rb +1 -1
  23. data/lib/oboe/api/memcache.rb +2 -2
  24. data/lib/oboe/api/profiling.rb +6 -4
  25. data/lib/oboe/api/tracing.rb +1 -1
  26. data/lib/oboe/api/util.rb +1 -1
  27. data/lib/oboe/config.rb +29 -10
  28. data/lib/oboe/frameworks/rails.rb +6 -7
  29. data/lib/oboe/frameworks/rails/inst/action_controller.rb +1 -1
  30. data/lib/oboe/frameworks/rails/inst/action_view.rb +3 -3
  31. data/lib/oboe/frameworks/rails/inst/action_view_2x.rb +3 -3
  32. data/lib/oboe/frameworks/rails/inst/action_view_30.rb +3 -3
  33. data/lib/oboe/frameworks/rails/inst/active_record.rb +1 -1
  34. data/lib/oboe/frameworks/rails/inst/connection_adapters/mysql.rb +1 -1
  35. data/lib/oboe/frameworks/rails/inst/connection_adapters/mysql2.rb +1 -1
  36. data/lib/oboe/frameworks/rails/inst/connection_adapters/oracle.rb +1 -1
  37. data/lib/oboe/frameworks/rails/inst/connection_adapters/postgresql.rb +1 -1
  38. data/lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb +2 -2
  39. data/lib/oboe/inst/cassandra.rb +2 -2
  40. data/lib/oboe/inst/dalli.rb +8 -4
  41. data/lib/oboe/inst/http.rb +38 -34
  42. data/lib/oboe/inst/memcache.rb +12 -3
  43. data/lib/oboe/inst/memcached.rb +10 -5
  44. data/lib/oboe/inst/mongo.rb +19 -15
  45. data/lib/oboe/inst/moped.rb +120 -51
  46. data/lib/oboe/inst/rack.rb +14 -7
  47. data/lib/oboe/inst/resque.rb +2 -2
  48. data/lib/oboe/instrumentation.rb +3 -0
  49. data/lib/oboe/loading.rb +2 -6
  50. data/lib/oboe/logger.rb +3 -1
  51. data/lib/oboe/ruby.rb +3 -0
  52. data/lib/oboe/util.rb +2 -0
  53. data/lib/oboe/version.rb +5 -2
  54. data/lib/oboe_fu.rb +2 -0
  55. data/lib/oboe_metal.rb +23 -10
  56. data/lib/rails/generators/oboe/install_generator.rb +5 -3
  57. data/lib/rails/generators/oboe/templates/oboe_initializer.rb +24 -2
  58. data/oboe.gemspec +20 -14
  59. data/test/instrumentation/cassandra_test.rb +331 -0
  60. data/test/instrumentation/dalli_test.rb +157 -0
  61. data/test/instrumentation/http_test.rb +74 -0
  62. data/test/instrumentation/memcache_test.rb +251 -0
  63. data/test/instrumentation/memcached_test.rb +218 -0
  64. data/test/instrumentation/mongo_test.rb +406 -0
  65. data/test/instrumentation/moped_test.rb +468 -0
  66. data/test/instrumentation/rack_test.rb +55 -0
  67. data/test/instrumentation/resque_test.rb +62 -0
  68. data/test/minitest_helper.rb +113 -0
  69. data/test/support/config_test.rb +41 -0
  70. metadata +56 -35
  71. data/Gemfile.lock +0 -103
  72. data/Guardfile +0 -24
  73. data/install.rb +0 -1
  74. data/spec/instrumentation/cassandra_spec.rb +0 -18
  75. data/spec/instrumentation/dalli_spec.rb +0 -14
  76. data/spec/instrumentation/http_spec.rb +0 -14
  77. data/spec/instrumentation/memcache_spec.rb +0 -19
  78. data/spec/instrumentation/memcached_spec.rb +0 -22
  79. data/spec/instrumentation/mongo_spec.rb +0 -29
  80. data/spec/instrumentation/moped_spec.rb +0 -41
  81. data/spec/instrumentation/resque_spec.rb +0 -18
  82. data/spec/spec_helper.rb +0 -15
  83. data/spec/support/config_spec.rb +0 -27
  84. data/spec/support/oboe_spec.rb +0 -4
@@ -0,0 +1,218 @@
1
+ require 'minitest_helper'
2
+
3
+ if (RUBY_VERSION =~ /^1./) == 0
4
+ describe Oboe::Inst::Memcached do
5
+ require 'memcached'
6
+ require 'memcached/rails'
7
+
8
+ before do
9
+ clear_all_traces
10
+ @mc = ::Memcached::Rails.new(:servers => ['localhost'])
11
+
12
+ # These are standard entry/exit KVs that are passed up with all mongo operations
13
+ @entry_kvs = {
14
+ 'Layer' => 'memcache',
15
+ 'Label' => 'entry' }
16
+
17
+ @info_kvs = {
18
+ 'Layer' => 'memcache',
19
+ 'Label' => 'info' }
20
+
21
+ @exit_kvs = { 'Layer' => 'memcache', 'Label' => 'exit' }
22
+ @collect_backtraces = Oboe::Config[:memcached][:collect_backtraces]
23
+ end
24
+
25
+ after do
26
+ Oboe::Config[:memcached][:collect_backtraces] = @collect_backtraces
27
+ end
28
+
29
+ it 'Stock Memcached should be loaded, defined and ready' do
30
+ defined?(::Memcached).wont_match nil
31
+ defined?(::Memcached::Rails).wont_match nil
32
+ end
33
+
34
+ it 'Memcached should have oboe methods defined' do
35
+ Oboe::API::Memcache::MEMCACHE_OPS.each do |m|
36
+ if ::Memcached.method_defined?(m)
37
+ ::Memcached.method_defined?("#{m}_with_oboe").must_equal true
38
+ end
39
+ ::Memcached::Rails.method_defined?(:get_multi_with_oboe).must_equal true
40
+ end
41
+ end
42
+
43
+ it "should trace set" do
44
+ Oboe::API.start_trace('memcached_test', '', {}) do
45
+ @mc.set('testKey', 'blah')
46
+ end
47
+
48
+ traces = get_all_traces
49
+ traces.count.must_equal 4
50
+
51
+ validate_outer_layers(traces, 'memcached_test')
52
+ validate_event_keys(traces[1], @entry_kvs)
53
+ validate_event_keys(traces[2], @exit_kvs)
54
+
55
+ traces[1]['KVOp'].must_equal "set"
56
+ traces[1]['KVKey'].must_equal "testKey"
57
+ end
58
+
59
+ it "should trace get" do
60
+ Oboe::API.start_trace('memcached_test', '', {}) do
61
+ @mc.get('msg')
62
+ end
63
+
64
+ traces = get_all_traces
65
+ traces.count.must_equal 4
66
+
67
+ validate_outer_layers(traces, 'memcached_test')
68
+ validate_event_keys(traces[1], @entry_kvs)
69
+ validate_event_keys(traces[2], @exit_kvs)
70
+
71
+ traces[1]['KVOp'].must_equal "get"
72
+ traces[1]['KVKey'].must_equal "msg"
73
+ end
74
+
75
+ it "should trace get_multi" do
76
+ Oboe::API.start_trace('memcached_test', '', {}) do
77
+ @mc.get_multi(['one', 'two', 'three', 'four', 'five', 'six'])
78
+ end
79
+
80
+ traces = get_all_traces
81
+ traces.count.must_equal 5
82
+
83
+ validate_outer_layers(traces, 'memcached_test')
84
+ validate_event_keys(traces[1], @entry_kvs)
85
+ validate_event_keys(traces[2], @info_kvs)
86
+ validate_event_keys(traces[3], @exit_kvs)
87
+
88
+ traces[1]['KVOp'].must_equal "get_multi"
89
+
90
+ traces[2]['KVKeyCount'].must_equal "6"
91
+ traces[2].has_key?('KVHitCount').must_equal true
92
+ end
93
+
94
+ it "should trace add for existing key" do
95
+ Oboe::API.start_trace('memcached_test', '', {}) do
96
+ @mc.add('testKey', 'x', 1200)
97
+ end
98
+
99
+ traces = get_all_traces
100
+ traces.count.must_equal 5
101
+
102
+ validate_outer_layers(traces, 'memcached_test')
103
+ validate_event_keys(traces[1], @entry_kvs)
104
+ validate_event_keys(traces[3], @exit_kvs)
105
+
106
+ traces[1]['KVOp'].must_equal "add"
107
+ traces[1]['KVKey'].must_equal "testKey"
108
+
109
+ traces[2]['ErrorClass'].must_equal "Memcached::NotStored"
110
+ traces[2]['Message'].must_equal "Memcached::NotStored"
111
+ end
112
+
113
+ it "should trace append" do
114
+ @mc.set('rawKey', "Peanut Butter ", 600, :raw => true)
115
+ Oboe::API.start_trace('memcached_test', '', {}) do
116
+ @mc.append('rawKey', "Jelly")
117
+ end
118
+
119
+ traces = get_all_traces
120
+ traces.count.must_equal 4
121
+
122
+ validate_outer_layers(traces, 'memcached_test')
123
+ validate_event_keys(traces[1], @entry_kvs)
124
+ validate_event_keys(traces[2], @exit_kvs)
125
+
126
+ traces[1]['KVOp'].must_equal "append"
127
+ traces[1]['KVKey'].must_equal "rawKey"
128
+ end
129
+
130
+ it "should trace decr" do
131
+ Oboe::API.start_trace('memcached_test', '', {}) do
132
+ @mc.decr('some_key_counter', 1)
133
+ end
134
+
135
+ traces = get_all_traces
136
+ traces.count.must_equal 4
137
+
138
+ validate_outer_layers(traces, 'memcached_test')
139
+ validate_event_keys(traces[1], @entry_kvs)
140
+ validate_event_keys(traces[2], @exit_kvs)
141
+
142
+ traces[1]['KVOp'].must_equal "decr"
143
+ traces[1]['KVKey'].must_equal "some_key_counter"
144
+ end
145
+
146
+ it "should trace increment" do
147
+ Oboe::API.start_trace('memcached_test', '', {}) do
148
+ @mc.incr("some_key_counter", 1)
149
+ end
150
+
151
+ traces = get_all_traces
152
+ traces.count.must_equal 4
153
+
154
+ validate_outer_layers(traces, 'memcached_test')
155
+ validate_event_keys(traces[1], @entry_kvs)
156
+ validate_event_keys(traces[2], @exit_kvs)
157
+
158
+ traces[1]['KVOp'].must_equal "incr"
159
+ traces[1]['KVKey'].must_equal "some_key_counter"
160
+ end
161
+
162
+ it "should trace replace" do
163
+ @mc.set('some_key', 'blah')
164
+ Oboe::API.start_trace('memcached_test', '', {}) do
165
+ @mc.replace("some_key", "woop")
166
+ end
167
+
168
+ traces = get_all_traces
169
+ traces.count.must_equal 4
170
+
171
+ validate_outer_layers(traces, 'memcached_test')
172
+ validate_event_keys(traces[1], @entry_kvs)
173
+ validate_event_keys(traces[2], @exit_kvs)
174
+
175
+ traces[1]['KVOp'].must_equal "replace"
176
+ traces[1]['KVKey'].must_equal "some_key"
177
+ end
178
+
179
+ it "should trace delete" do
180
+ @mc.set('some_key', 'blah')
181
+ Oboe::API.start_trace('memcached_test', '', {}) do
182
+ @mc.delete("some_key")
183
+ end
184
+
185
+ traces = get_all_traces
186
+ traces.count.must_equal 4
187
+
188
+ validate_outer_layers(traces, 'memcached_test')
189
+ validate_event_keys(traces[1], @entry_kvs)
190
+ validate_event_keys(traces[2], @exit_kvs)
191
+
192
+ traces[1]['KVOp'].must_equal "delete"
193
+ traces[1]['KVKey'].must_equal "some_key"
194
+ end
195
+
196
+ it "should obey :collect_backtraces setting when true" do
197
+ Oboe::Config[:memcached][:collect_backtraces] = true
198
+
199
+ Oboe::API.start_trace('memcached_test', '', {}) do
200
+ @mc.set('some_key', 1)
201
+ end
202
+
203
+ traces = get_all_traces
204
+ layer_has_key(traces, 'memcache', 'Backtrace')
205
+ end
206
+
207
+ it "should obey :collect_backtraces setting when false" do
208
+ Oboe::Config[:memcached][:collect_backtraces] = false
209
+
210
+ Oboe::API.start_trace('memcached_test', '', {}) do
211
+ @mc.set('some_key', 1)
212
+ end
213
+
214
+ traces = get_all_traces
215
+ layer_doesnt_have_key(traces, 'memcache', 'Backtrace')
216
+ end
217
+ end
218
+ end
@@ -0,0 +1,406 @@
1
+ require 'minitest_helper'
2
+
3
+ describe Oboe::Inst::Mongo do
4
+ before do
5
+ clear_all_traces
6
+ @connection = Mongo::Connection.new("localhost", 27017, :slave_ok => true)
7
+ @db = @connection.db("test-#{ENV['RACK_ENV']}")
8
+
9
+ # These are standard entry/exit KVs that are passed up with all mongo operations
10
+ @entry_kvs = {
11
+ 'Layer' => 'mongo',
12
+ 'Label' => 'entry',
13
+ 'Flavor' => 'mongodb',
14
+ 'Database' => 'test-test',
15
+ 'RemoteHost' => 'localhost',
16
+ 'RemotePort' => '27017' }
17
+
18
+ @exit_kvs = { 'Layer' => 'mongo', 'Label' => 'exit' }
19
+ @collect_backtraces = Oboe::Config[:mongo][:collect_backtraces]
20
+ end
21
+
22
+ after do
23
+ Oboe::Config[:mongo][:collect_backtraces] = @collect_backtraces
24
+ end
25
+
26
+ it 'Stock Mongo should be loaded, defined and ready' do
27
+ defined?(::Mongo).wont_match nil
28
+ defined?(::Mongo::DB).wont_match nil
29
+ defined?(::Mongo::Cursor).wont_match nil
30
+ defined?(::Mongo::Collection).wont_match nil
31
+ end
32
+
33
+ it 'Mongo should have oboe methods defined' do
34
+ Oboe::Inst::Mongo::DB_OPS.each do |m|
35
+ ::Mongo::DB.method_defined?("#{m}_with_oboe").must_equal true
36
+ end
37
+ Oboe::Inst::Mongo::CURSOR_OPS.each do |m|
38
+ ::Mongo::Cursor.method_defined?("#{m}_with_oboe").must_equal true
39
+ end
40
+ Oboe::Inst::Mongo::COLL_WRITE_OPS.each do |m|
41
+ ::Mongo::Collection.method_defined?("#{m}_with_oboe").must_equal true
42
+ end
43
+ Oboe::Inst::Mongo::COLL_QUERY_OPS.each do |m|
44
+ ::Mongo::Collection.method_defined?("#{m}_with_oboe").must_equal true
45
+ end
46
+ Oboe::Inst::Mongo::COLL_INDEX_OPS.each do |m|
47
+ ::Mongo::Collection.method_defined?("#{m}_with_oboe").must_equal true
48
+ end
49
+ ::Mongo::Collection.method_defined?(:oboe_collect).must_equal true
50
+ end
51
+
52
+ it "should trace create_collection" do
53
+ Oboe::API.start_trace('mongo_test', '', {}) do
54
+ @db.create_collection("create_and_drop_collection_test")
55
+ end
56
+
57
+ traces = get_all_traces
58
+ traces.count.must_equal 4
59
+
60
+ validate_outer_layers(traces, 'mongo_test')
61
+ validate_event_keys(traces[1], @entry_kvs)
62
+ validate_event_keys(traces[2], @exit_kvs)
63
+
64
+ traces[1]['QueryOp'].must_equal "create_collection"
65
+ traces[1]['New_Collection_Name'].must_equal "create_and_drop_collection_test"
66
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
67
+ end
68
+
69
+ it "should trace drop_collection" do
70
+ Oboe::API.start_trace('mongo_test', '', {}) do
71
+ @db.drop_collection("create_and_drop_collection_test")
72
+ end
73
+
74
+ traces = get_all_traces
75
+ traces.count.must_equal 4
76
+
77
+ validate_outer_layers(traces, 'mongo_test')
78
+ validate_event_keys(traces[1], @entry_kvs)
79
+ validate_event_keys(traces[2], @exit_kvs)
80
+
81
+ traces[1]['QueryOp'].must_equal "drop_collection"
82
+ traces[1]['Collection'].must_equal "create_and_drop_collection_test"
83
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
84
+ end
85
+
86
+ it "should trace count" do
87
+ coll = @db.collection("testCollection")
88
+
89
+ Oboe::API.start_trace('mongo_test', '', {}) do
90
+ coll.count(:query => {:name => "MyName"})
91
+ end
92
+
93
+ traces = get_all_traces
94
+ traces.count.must_equal 6
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[3]['QueryOp'].must_equal "count"
101
+ end
102
+
103
+ it "should trace find_and_modify" do
104
+ coll = @db.collection("testCollection")
105
+
106
+ Oboe::API.start_trace('mongo_test', '', {}) do
107
+ coll.find_and_modify({ :query => { :name => "MyName" }, :update => { :count => 203 }})
108
+ end
109
+
110
+ traces = get_all_traces
111
+ traces.count.must_equal 4
112
+
113
+ validate_outer_layers(traces, 'mongo_test')
114
+ validate_event_keys(traces[1], @entry_kvs)
115
+ validate_event_keys(traces[2], @exit_kvs)
116
+
117
+ traces[1]['Collection'].must_equal "testCollection"
118
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
119
+ traces[1]['QueryOp'].must_equal "find_and_modify"
120
+ traces[1]['Update_Document'].must_equal "{:count=>203}"
121
+ end
122
+
123
+ it "should trace insert" do
124
+ coll = @db.collection("testCollection")
125
+
126
+ Oboe::API.start_trace('mongo_test', '', {}) do
127
+ doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
128
+ id = coll.insert(doc)
129
+ end
130
+
131
+ traces = get_all_traces
132
+ traces.count.must_equal 4
133
+
134
+ validate_outer_layers(traces, 'mongo_test')
135
+ validate_event_keys(traces[1], @entry_kvs)
136
+ validate_event_keys(traces[2], @exit_kvs)
137
+
138
+ traces[1]['Collection'].must_equal "testCollection"
139
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
140
+ traces[1]['QueryOp'].must_equal "insert"
141
+ traces[1]['Query'].must_equal "{\"name\":\"MyName\",\"type\":\"MyType\",\"count\":1,\"info\":{\"x\":203,\"y\":\"102\"}}"
142
+ end
143
+
144
+ it "should trace map_reduce" do
145
+ coll = @db.collection("testCollection")
146
+
147
+ Oboe::API.start_trace('mongo_test', '', {}) do
148
+ map = "function() { emit(this.name, 1); }"
149
+ reduce = "function(k, vals) { var sum = 0; for(var i in vals) sum += vals[i]; return sum; }"
150
+ coll.map_reduce(map, reduce, { :out => "mr_results", :limit => 100, :read => :primary })
151
+ end
152
+
153
+ traces = get_all_traces
154
+ traces.count.must_equal 4
155
+
156
+ validate_outer_layers(traces, 'mongo_test')
157
+ validate_event_keys(traces[1], @entry_kvs)
158
+ validate_event_keys(traces[2], @exit_kvs)
159
+
160
+ traces[1]['Collection'].must_equal "testCollection"
161
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
162
+ traces[1]['QueryOp'].must_equal "map_reduce"
163
+ traces[1]['Map_Function'].must_equal "function() { emit(this.name, 1); }"
164
+ traces[1]['Reduce_Function'].must_equal "function(k, vals) { var sum = 0; for(var i in vals) sum += vals[i]; return sum; }"
165
+ traces[1]['Limit'].must_equal "100"
166
+ end
167
+
168
+ it "should trace remove" do
169
+ coll = @db.collection("testCollection")
170
+
171
+ Oboe::API.start_trace('mongo_test', '', {}) do
172
+ coll.remove(:name => "SaveOp")
173
+ end
174
+
175
+ traces = get_all_traces
176
+ traces.count.must_equal 4
177
+
178
+ validate_outer_layers(traces, 'mongo_test')
179
+ validate_event_keys(traces[1], @entry_kvs)
180
+ validate_event_keys(traces[2], @exit_kvs)
181
+
182
+ traces[1]['Collection'].must_equal "testCollection"
183
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
184
+ traces[1]['QueryOp'].must_equal "remove"
185
+ traces[1]['Query'].must_equal "{\"name\":\"SaveOp\"}"
186
+ end
187
+
188
+ it "should trace rename" do
189
+ coll = @db.collection("testCollection")
190
+ new_name = (0...10).map{ ('a'..'z').to_a[rand(26)] }.join
191
+
192
+ Oboe::API.start_trace('mongo_test', '', {}) do
193
+ coll.rename(new_name)
194
+ end
195
+
196
+ traces = get_all_traces
197
+ traces.count.must_equal 4
198
+
199
+ validate_outer_layers(traces, 'mongo_test')
200
+ validate_event_keys(traces[1], @entry_kvs)
201
+ validate_event_keys(traces[2], @exit_kvs)
202
+
203
+ traces[1]['Collection'].must_equal "testCollection"
204
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
205
+ traces[1]['QueryOp'].must_equal "rename"
206
+ traces[1]['New_Collection_Name'].must_equal new_name
207
+
208
+ # Clean up after test and set collection name back to original
209
+ coll.rename("testCollection")
210
+ end
211
+
212
+ it "should trace update" do
213
+ coll = @db.collection("testCollection")
214
+
215
+ Oboe::API.start_trace('mongo_test', '', {}) do
216
+ # Two types of update calls
217
+ coll.update({"_id" => 1}, { "$set" => {"name" => "MongoDB Ruby"}}, :multi => true)
218
+
219
+ doc = {"name" => "MyOtherName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
220
+ coll.update({"_id" => 1}, doc)
221
+ end
222
+
223
+ traces = get_all_traces
224
+ traces.count.must_equal 6
225
+
226
+ validate_outer_layers(traces, 'mongo_test')
227
+ validate_event_keys(traces[1], @entry_kvs)
228
+ validate_event_keys(traces[2], @exit_kvs)
229
+
230
+ traces[1]['Collection'].must_equal "testCollection"
231
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
232
+ traces[1]['QueryOp'].must_equal "update"
233
+ traces[1]['Query'].must_equal "{\"_id\":1}"
234
+
235
+ validate_event_keys(traces[3], @entry_kvs)
236
+ validate_event_keys(traces[4], @exit_kvs)
237
+
238
+ traces[3].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
239
+ traces[3]['QueryOp'].must_equal "update"
240
+ traces[3]['Query'].must_equal "{\"_id\":1}"
241
+ end
242
+
243
+ it "should trace distinct" do
244
+ coll = @db.collection("testCollection")
245
+
246
+ Oboe::API.start_trace('mongo_test', '', {}) do
247
+ coll.distinct("count")
248
+ end
249
+
250
+ traces = get_all_traces
251
+ traces.count.must_equal 4
252
+
253
+ validate_outer_layers(traces, 'mongo_test')
254
+ validate_event_keys(traces[1], @entry_kvs)
255
+ validate_event_keys(traces[2], @exit_kvs)
256
+
257
+ traces[1]['Collection'].must_equal "testCollection"
258
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
259
+ traces[1]['QueryOp'].must_equal "distinct"
260
+ end
261
+
262
+ it "should trace find" do
263
+ coll = @db.collection("testCollection")
264
+
265
+ Oboe::API.start_trace('mongo_test', '', {}) do
266
+ coll.find(:name => "MyName", :limit => 1)
267
+ end
268
+
269
+ traces = get_all_traces
270
+ traces.count.must_equal 4
271
+
272
+ validate_outer_layers(traces, 'mongo_test')
273
+ validate_event_keys(traces[1], @entry_kvs)
274
+ validate_event_keys(traces[2], @exit_kvs)
275
+
276
+ traces[1]['Collection'].must_equal "testCollection"
277
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
278
+ traces[1]['QueryOp'].must_equal "find"
279
+ traces[1]['Query'].must_equal "{\"name\":\"MyName\",\"limit\":1}"
280
+ traces[1]['Limit'].must_equal "1"
281
+ end
282
+
283
+ it "should trace group" do
284
+ coll = @db.collection("testCollection")
285
+
286
+ Oboe::API.start_trace('mongo_test', '', {}) do
287
+ coll.group( :key => :type,
288
+ :cond => { :count => 1 },
289
+ :initial => { :count => 0 },
290
+ :reduce => 'function(obj,prev) { prev.count += obj.c; }')
291
+ end
292
+
293
+ traces = get_all_traces
294
+ traces.count.must_equal 4
295
+
296
+ validate_outer_layers(traces, 'mongo_test')
297
+ validate_event_keys(traces[1], @entry_kvs)
298
+ validate_event_keys(traces[2], @exit_kvs)
299
+
300
+ traces[1]['Collection'].must_equal "testCollection"
301
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
302
+ traces[1]['QueryOp'].must_equal "group"
303
+ traces[1]['Query'].must_equal "{\"key\":\"type\",\"cond\":{\"count\":1},\"initial\":{\"count\":0},\"reduce\":\"function(obj,prev) { prev.count += obj.c; }\"}"
304
+ end
305
+
306
+ it "should trace create, ensure and drop index" do
307
+ coll = @db.collection("testCollection")
308
+
309
+ Oboe::API.start_trace('mongo_test', '', {}) do
310
+ coll.create_index("i")
311
+ coll.ensure_index("i")
312
+ coll.drop_index("i_1")
313
+ end
314
+
315
+ traces = get_all_traces
316
+ traces.count.must_equal 8
317
+
318
+ validate_outer_layers(traces, 'mongo_test')
319
+ validate_event_keys(traces[1], @entry_kvs)
320
+ validate_event_keys(traces[2], @exit_kvs)
321
+
322
+ traces[1]['Collection'].must_equal "testCollection"
323
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
324
+ traces[1]['QueryOp'].must_equal "create_index"
325
+
326
+ validate_event_keys(traces[3], @entry_kvs)
327
+ validate_event_keys(traces[4], @exit_kvs)
328
+
329
+ traces[3]['Collection'].must_equal "testCollection"
330
+ traces[3].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
331
+ traces[3]['QueryOp'].must_equal "ensure_index"
332
+
333
+ validate_event_keys(traces[5], @entry_kvs)
334
+ validate_event_keys(traces[6], @exit_kvs)
335
+
336
+ traces[5]['Collection'].must_equal "testCollection"
337
+ traces[5].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
338
+ traces[5]['QueryOp'].must_equal "drop_index"
339
+ end
340
+
341
+ it "should trace drop_indexes" do
342
+ coll = @db.collection("testCollection")
343
+
344
+ Oboe::API.start_trace('mongo_test', '', {}) do
345
+ coll.drop_indexes
346
+ end
347
+
348
+ traces = get_all_traces
349
+ traces.count.must_equal 4
350
+
351
+ validate_outer_layers(traces, 'mongo_test')
352
+ validate_event_keys(traces[1], @entry_kvs)
353
+ validate_event_keys(traces[2], @exit_kvs)
354
+
355
+ traces[1]['Collection'].must_equal "testCollection"
356
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
357
+ traces[1]['QueryOp'].must_equal "drop_indexes"
358
+ end
359
+
360
+ it "should trace index_information" do
361
+ coll = @db.collection("testCollection")
362
+
363
+ Oboe::API.start_trace('mongo_test', '', {}) do
364
+ coll.index_information
365
+ end
366
+
367
+ traces = get_all_traces
368
+ traces.count.must_equal 4
369
+
370
+ validate_outer_layers(traces, 'mongo_test')
371
+ validate_event_keys(traces[1], @entry_kvs)
372
+ validate_event_keys(traces[2], @exit_kvs)
373
+
374
+ traces[1]['Collection'].must_equal "testCollection"
375
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:mongo][:collect_backtraces]
376
+ traces[1]['QueryOp'].must_equal "index_information"
377
+ end
378
+
379
+ it "should obey :collect_backtraces setting when true" do
380
+ Oboe::Config[:mongo][:collect_backtraces] = true
381
+
382
+ coll = @db.collection("testCollection")
383
+
384
+ Oboe::API.start_trace('mongo_test', '', {}) do
385
+ doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
386
+ id = coll.insert(doc)
387
+ end
388
+
389
+ traces = get_all_traces
390
+ layer_has_key(traces, 'mongo', 'Backtrace')
391
+ end
392
+
393
+ it "should obey :collect_backtraces setting when false" do
394
+ Oboe::Config[:mongo][:collect_backtraces] = false
395
+
396
+ coll = @db.collection("testCollection")
397
+
398
+ Oboe::API.start_trace('mongo_test', '', {}) do
399
+ doc = {"name" => "MyName", "type" => "MyType", "count" => 1, "info" => {"x" => 203, "y" => '102'}}
400
+ id = coll.insert(doc)
401
+ end
402
+
403
+ traces = get_all_traces
404
+ layer_doesnt_have_key(traces, 'mongo', 'Backtrace')
405
+ end
406
+ end