oboe 1.3.9.1 → 1.4.0.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.
@@ -20,210 +20,207 @@ module Oboe
20
20
  end
21
21
  end
22
22
 
23
- if defined?(::Mongo::DB)
24
- module ::Mongo
25
- class DB
26
- include Oboe::Inst::Mongo
27
-
28
- # Instrument DB operations
29
- Oboe::Inst::Mongo::DB_OPS.reject { |m| not method_defined?(m) }.each do |m|
30
- define_method("#{m}_with_oboe") do |*args|
31
- report_kvs = {}
23
+ if defined?(::Mongo) and Oboe::Config[:mongo][:enabled]
24
+ puts "[oboe/loading] Instrumenting mongo" if Oboe::Config[:verbose]
32
25
 
33
- begin
34
- report_kvs[:Flavor] = Oboe::Inst::Mongo::FLAVOR
26
+ if defined?(::Mongo::DB)
27
+ module ::Mongo
28
+ class DB
29
+ include Oboe::Inst::Mongo
30
+
31
+ # Instrument DB operations
32
+ Oboe::Inst::Mongo::DB_OPS.reject { |m| not method_defined?(m) }.each do |m|
33
+ define_method("#{m}_with_oboe") do |*args|
34
+ report_kvs = {}
35
35
 
36
- report_kvs[:Database] = @name
37
- report_kvs[:RemoteHost] = @connection.host
38
- report_kvs[:RemotePort] = @connection.port
39
-
40
- report_kvs[:QueryOp] = m
36
+ begin
37
+ report_kvs[:Flavor] = Oboe::Inst::Mongo::FLAVOR
41
38
 
42
- report_kvs[:New_Collection_Name] = args[0] if m == :create_collection
43
- report_kvs[:Collection_Name] = args[0] if m == :drop_collection
39
+ report_kvs[:Database] = @name
40
+ report_kvs[:RemoteHost] = @connection.host
41
+ report_kvs[:RemotePort] = @connection.port
42
+
43
+ report_kvs[:QueryOp] = m
44
44
 
45
- report_kvs[:Backtrace] = Oboe::API.backtrace
46
- rescue
47
- logger.warn "[oboe/error] Problem processing mongo args (#{m})" if defined?(logger)
48
- end
45
+ report_kvs[:New_Collection_Name] = args[0] if m == :create_collection
46
+ report_kvs[:Collection_Name] = args[0] if m == :drop_collection
47
+
48
+ report_kvs[:Backtrace] = Oboe::API.backtrace
49
+ rescue
50
+ end
49
51
 
50
- Oboe::API.trace('mongo', report_kvs) do
51
- send("#{m}_without_oboe", *args)
52
+ Oboe::API.trace('mongo', report_kvs) do
53
+ send("#{m}_without_oboe", *args)
54
+ end
52
55
  end
56
+
57
+ class_eval "alias #{m}_without_oboe #{m}"
58
+ class_eval "alias #{m} #{m}_with_oboe"
53
59
  end
54
-
55
- class_eval "alias #{m}_without_oboe #{m}"
56
- class_eval "alias #{m} #{m}_with_oboe"
57
60
  end
58
61
  end
59
62
  end
60
- end
61
63
 
62
- if defined?(::Mongo::Cursor)
63
- module ::Mongo
64
- class Cursor
65
- include Oboe::Inst::Mongo
66
-
67
- # Instrument DB cursor operations
68
- Oboe::Inst::Mongo::CURSOR_OPS.reject { |m| not method_defined?(m) }.each do |m|
69
- define_method("#{m}_with_oboe") do |*args|
70
- report_kvs = {}
71
-
72
- begin
73
- report_kvs[:Flavor] = Oboe::Inst::Mongo::FLAVOR
74
-
75
- report_kvs[:Database] = @db.name
76
- report_kvs[:RemoteHost] = @connection.host
77
- report_kvs[:RemotePort] = @connection.port
78
-
79
- report_kvs[:QueryOp] = m
80
- if m == :count
81
- unless @selector.empty?
82
- report_kvs[:Query] = @selector.try(:to_json)
83
- else
84
- report_kvs[:Query] = 'all'
64
+ if defined?(::Mongo::Cursor)
65
+ module ::Mongo
66
+ class Cursor
67
+ include Oboe::Inst::Mongo
68
+
69
+ # Instrument DB cursor operations
70
+ Oboe::Inst::Mongo::CURSOR_OPS.reject { |m| not method_defined?(m) }.each do |m|
71
+ define_method("#{m}_with_oboe") do |*args|
72
+ report_kvs = {}
73
+
74
+ begin
75
+ report_kvs[:Flavor] = Oboe::Inst::Mongo::FLAVOR
76
+
77
+ report_kvs[:Database] = @db.name
78
+ report_kvs[:RemoteHost] = @connection.host
79
+ report_kvs[:RemotePort] = @connection.port
80
+
81
+ report_kvs[:QueryOp] = m
82
+ if m == :count
83
+ unless @selector.empty?
84
+ report_kvs[:Query] = @selector.try(:to_json)
85
+ else
86
+ report_kvs[:Query] = 'all'
87
+ end
88
+ report_kvs[:Limit] = @limit if @limit != 0
85
89
  end
86
- report_kvs[:Limit] = @limit if @limit != 0
90
+ rescue
91
+ end
92
+
93
+ Oboe::API.trace('mongo', report_kvs) do
94
+ send("#{m}_without_oboe", *args)
87
95
  end
88
-
89
- rescue
90
- logger.warn "[oboe/error] Problem processing mongo args (#{m})" if defined?(logger)
91
96
  end
92
97
 
93
- Oboe::API.trace('mongo', report_kvs) do
94
- send("#{m}_without_oboe", *args)
95
- end
98
+ class_eval "alias #{m}_without_oboe #{m}"
99
+ class_eval "alias #{m} #{m}_with_oboe"
96
100
  end
97
-
98
- class_eval "alias #{m}_without_oboe #{m}"
99
- class_eval "alias #{m} #{m}_with_oboe"
100
101
  end
101
102
  end
102
103
  end
103
- end
104
104
 
105
- if defined?(::Mongo::Collection)
106
- module ::Mongo
107
- class Collection
108
- include Oboe::Inst::Mongo
105
+ if defined?(::Mongo::Collection)
106
+ module ::Mongo
107
+ class Collection
108
+ include Oboe::Inst::Mongo
109
109
 
110
- def oboe_collect(m, args)
111
- report_kvs = {}
112
- report_kvs[:Flavor] = Oboe::Inst::Mongo::FLAVOR
113
-
114
- report_kvs[:Database] = @db.name
115
- report_kvs[:RemoteHost] = @db.connection.host
116
- report_kvs[:RemotePort] = @db.connection.port
117
- report_kvs[:Collection] = @name
110
+ def oboe_collect(m, args)
111
+ report_kvs = {}
112
+ report_kvs[:Flavor] = Oboe::Inst::Mongo::FLAVOR
113
+
114
+ report_kvs[:Database] = @db.name
115
+ report_kvs[:RemoteHost] = @db.connection.host
116
+ report_kvs[:RemotePort] = @db.connection.port
117
+ report_kvs[:Collection] = @name
118
+
119
+ report_kvs[:Backtrace] = Oboe::API.backtrace
120
+
121
+ report_kvs[:QueryOp] = m
122
+ report_kvs[:Query] = args[0].try(:to_json) if args and not args.empty? and args[0].class == Hash
123
+ report_kvs
124
+ end
125
+
126
+ # Instrument Collection write operations
127
+ Oboe::Inst::Mongo::COLL_WRITE_OPS.reject { |m| not method_defined?(m) }.each do |m|
128
+ define_method("#{m}_with_oboe") do |*args|
129
+ report_kvs = oboe_collect(m, args)
130
+ args_length = args.length
118
131
 
119
- report_kvs[:Backtrace] = Oboe::API.backtrace
120
-
121
- report_kvs[:QueryOp] = m
122
- report_kvs[:Query] = args[0].try(:to_json) if args and not args.empty? and args[0].class == Hash
123
- report_kvs
124
- end
125
-
126
- # Instrument Collection write operations
127
- Oboe::Inst::Mongo::COLL_WRITE_OPS.reject { |m| not method_defined?(m) }.each do |m|
128
- define_method("#{m}_with_oboe") do |*args|
129
- report_kvs = oboe_collect(m, args)
130
- args_length = args.length
131
-
132
- begin
133
- if m == :find_and_modify and args[0] and args[0].has_key?(:update)
134
- report_kvs[:Update_Document] = args[0][:update]
135
- end
132
+ begin
133
+ if m == :find_and_modify and args[0] and args[0].has_key?(:update)
134
+ report_kvs[:Update_Document] = args[0][:update]
135
+ end
136
136
 
137
- if m == :map_reduce
138
- report_kvs[:Map_Function] = args[0]
139
- report_kvs[:Reduce_Function] = args[1]
140
- report_kvs[:Limit] = args[2][:limit] if args[2] and args[2].has_key?(:limit)
141
- end
137
+ if m == :map_reduce
138
+ report_kvs[:Map_Function] = args[0]
139
+ report_kvs[:Reduce_Function] = args[1]
140
+ report_kvs[:Limit] = args[2][:limit] if args[2] and args[2].has_key?(:limit)
141
+ end
142
142
 
143
- report_kvs[:New_Collection_Name] = args[0] if m == :rename
143
+ report_kvs[:New_Collection_Name] = args[0] if m == :rename
144
144
 
145
- if m == :update
146
- if args_length >= 3
147
- report_kvs[:Update_Document] = args[1].try(:to_json)
148
- report_kvs[:Multi] = args[2][:multi] if args[2] and args[2].has_key?(:multi)
145
+ if m == :update
146
+ if args_length >= 3
147
+ report_kvs[:Update_Document] = args[1].try(:to_json)
148
+ report_kvs[:Multi] = args[2][:multi] if args[2] and args[2].has_key?(:multi)
149
+ end
149
150
  end
151
+ rescue
152
+ end
153
+
154
+ Oboe::API.trace('mongo', report_kvs) do
155
+ send("#{m}_without_oboe", *args)
150
156
  end
151
- rescue
152
- logger.warn "[oboe/error] Problem processing mongo args (#{m})" if defined?(logger)
153
- end
154
-
155
- Oboe::API.trace('mongo', report_kvs) do
156
- send("#{m}_without_oboe", *args)
157
157
  end
158
- end
159
-
160
- class_eval "alias #{m}_without_oboe #{m}"
161
- class_eval "alias #{m} #{m}_with_oboe"
162
- end
163
-
164
- # Instrument Collection query operations
165
- Oboe::Inst::Mongo::COLL_QUERY_OPS.reject { |m| not method_defined?(m) }.each do |m|
166
- define_method("#{m}_with_oboe") do |*args|
167
- begin
168
- report_kvs = oboe_collect(m, args)
169
- args_length = args.length
170
158
 
171
- if m == :distinct and args_length >= 2
172
- report_kvs[:Key] = args[0]
173
- report_kvs[:Query] = args[1].try(:to_json) if args[1] and args[1].class == Hash
174
- end
159
+ class_eval "alias #{m}_without_oboe #{m}"
160
+ class_eval "alias #{m} #{m}_with_oboe"
161
+ end
162
+
163
+ # Instrument Collection query operations
164
+ Oboe::Inst::Mongo::COLL_QUERY_OPS.reject { |m| not method_defined?(m) }.each do |m|
165
+ define_method("#{m}_with_oboe") do |*args|
166
+ begin
167
+ report_kvs = oboe_collect(m, args)
168
+ args_length = args.length
169
+
170
+ if m == :distinct and args_length >= 2
171
+ report_kvs[:Key] = args[0]
172
+ report_kvs[:Query] = args[1].try(:to_json) if args[1] and args[1].class == Hash
173
+ end
175
174
 
176
- if m == :find and args_length > 0
177
- report_kvs[:Limit] = args[0][:limit] if !args[0].nil? and args[0].has_key?(:limit)
178
- end
175
+ if m == :find and args_length > 0
176
+ report_kvs[:Limit] = args[0][:limit] if !args[0].nil? and args[0].has_key?(:limit)
177
+ end
179
178
 
180
- if m == :group
181
- unless args.empty?
182
- if args[0].is_a?(Hash)
183
- report_kvs[:Group_Key] = args[0][:key].try(:to_json) if args[0].has_key?(:key)
184
- report_kvs[:Group_Condition] = args[0][:cond].try(:to_json) if args[0].has_key?(:cond)
185
- report_kvs[:Group_Initial] = args[0][:initial].try(:to_json) if args[0].has_key?(:initial)
186
- report_kvs[:Group_Reduce] = args[0][:reduce] if args[0].has_key?(:reduce)
179
+ if m == :group
180
+ unless args.empty?
181
+ if args[0].is_a?(Hash)
182
+ report_kvs[:Group_Key] = args[0][:key].try(:to_json) if args[0].has_key?(:key)
183
+ report_kvs[:Group_Condition] = args[0][:cond].try(:to_json) if args[0].has_key?(:cond)
184
+ report_kvs[:Group_Initial] = args[0][:initial].try(:to_json) if args[0].has_key?(:initial)
185
+ report_kvs[:Group_Reduce] = args[0][:reduce] if args[0].has_key?(:reduce)
186
+ end
187
187
  end
188
188
  end
189
+ rescue
189
190
  end
190
- rescue
191
- logger.warn "[oboe/error] Problem processing mongo args (#{m})" if defined?(logger)
192
- end
193
191
 
194
- Oboe::API.trace('mongo', report_kvs) do
195
- send("#{m}_without_oboe", *args)
192
+ Oboe::API.trace('mongo', report_kvs) do
193
+ send("#{m}_without_oboe", *args)
194
+ end
196
195
  end
196
+
197
+ class_eval "alias #{m}_without_oboe #{m}"
198
+ class_eval "alias #{m} #{m}_with_oboe"
197
199
  end
200
+
201
+ # Instrument Collection index operations
202
+ Oboe::Inst::Mongo::COLL_INDEX_OPS.reject { |m| not method_defined?(m) }.each do |m|
203
+ define_method("#{m}_with_oboe") do |*args|
204
+ report_kvs = oboe_collect(m, args)
205
+ _args = args || []
206
+
207
+ begin
208
+ if [:create_index, :ensure_index, :drop_index].include? m and not _args.empty?
209
+ report_kvs[:Index] = _args[0].try(:to_json)
210
+ end
211
+ rescue
212
+ end
198
213
 
199
- class_eval "alias #{m}_without_oboe #{m}"
200
- class_eval "alias #{m} #{m}_with_oboe"
201
- end
202
-
203
- # Instrument Collection index operations
204
- Oboe::Inst::Mongo::COLL_INDEX_OPS.reject { |m| not method_defined?(m) }.each do |m|
205
- define_method("#{m}_with_oboe") do |*args|
206
- report_kvs = oboe_collect(m, args)
207
- _args = args || []
208
-
209
- begin
210
- if [:create_index, :ensure_index, :drop_index].include? m and not _args.empty?
211
- report_kvs[:Index] = _args[0].try(:to_json)
214
+ Oboe::API.trace('mongo', report_kvs) do
215
+ send("#{m}_without_oboe", *args)
212
216
  end
213
- rescue
214
- logger.warn "[oboe/error] Problem processing mongo args (#{m})" if defined?(logger)
215
217
  end
216
218
 
217
- Oboe::API.trace('mongo', report_kvs) do
218
- send("#{m}_without_oboe", *args)
219
- end
219
+ class_eval "alias #{m}_without_oboe #{m}"
220
+ class_eval "alias #{m} #{m}_with_oboe"
220
221
  end
221
-
222
- class_eval "alias #{m}_without_oboe #{m}"
223
- class_eval "alias #{m} #{m}_with_oboe"
224
222
  end
225
223
  end
226
224
  end
227
- puts "[oboe/loading] Instrumenting mongo" if Oboe::Config[:verbose]
228
225
  end
229
226
 
@@ -22,394 +22,396 @@ module Oboe
22
22
  end
23
23
  end
24
24
 
25
- puts "[oboe/loading] Instrumenting moped" if Oboe::Config[:verbose] and defined?(::Moped)
26
-
27
- if defined?(::Moped::Database)
28
- module ::Moped
29
- class Database
30
- include Oboe::Inst::Moped
31
-
32
- def extract_trace_details(op)
33
- report_kvs = {}
34
- begin
35
- report_kvs[:Flavor] = Oboe::Inst::Moped::FLAVOR
36
- # FIXME: We're only grabbing the first of potentially multiple servers here
37
- report_kvs[:RemoteHost], report_kvs[:RemotePort] = session.cluster.seeds.first.split(':')
38
- report_kvs[:Database] = name
39
- report_kvs[:QueryOp] = op.to_s
40
- rescue
25
+ if defined?(::Moped) and Oboe::Config[:moped][:enabled]
26
+ puts "[oboe/loading] Instrumenting moped" if Oboe::Config[:verbose]
27
+
28
+ if defined?(::Moped::Database)
29
+ module ::Moped
30
+ class Database
31
+ include Oboe::Inst::Moped
32
+
33
+ def extract_trace_details(op)
34
+ report_kvs = {}
35
+ begin
36
+ report_kvs[:Flavor] = Oboe::Inst::Moped::FLAVOR
37
+ # FIXME: We're only grabbing the first of potentially multiple servers here
38
+ report_kvs[:RemoteHost], report_kvs[:RemotePort] = session.cluster.seeds.first.split(':')
39
+ report_kvs[:Database] = name
40
+ report_kvs[:QueryOp] = op.to_s
41
+ rescue
42
+ end
43
+ report_kvs
41
44
  end
42
- report_kvs
43
- end
44
-
45
- def command_with_oboe(command)
46
- if Oboe::Config.tracing? and not Oboe::Context.layer_op and command.has_key?(:mapreduce)
47
- report_kvs = extract_trace_details(:map_reduce)
48
- report_kvs[:Map_Function] = command[:map]
49
- report_kvs[:Reduce_Function] = command[:reduce]
50
-
51
- Oboe::API.trace('mongo', report_kvs) do
45
+
46
+ def command_with_oboe(command)
47
+ if Oboe.tracing? and not Oboe::Context.layer_op and command.has_key?(:mapreduce)
48
+ report_kvs = extract_trace_details(:map_reduce)
49
+ report_kvs[:Map_Function] = command[:map]
50
+ report_kvs[:Reduce_Function] = command[:reduce]
51
+
52
+ Oboe::API.trace('mongo', report_kvs) do
53
+ command_without_oboe(command)
54
+ end
55
+ else
52
56
  command_without_oboe(command)
53
57
  end
54
- else
55
- command_without_oboe(command)
56
58
  end
57
- end
58
59
 
59
- def drop_with_oboe
60
- if Oboe::Config.tracing?
61
- report_kvs = extract_trace_details(:drop_database)
60
+ def drop_with_oboe
61
+ if Oboe.tracing?
62
+ report_kvs = extract_trace_details(:drop_database)
62
63
 
63
- Oboe::API.trace('mongo', report_kvs) do
64
+ Oboe::API.trace('mongo', report_kvs) do
65
+ drop_without_oboe
66
+ end
67
+ else
64
68
  drop_without_oboe
65
69
  end
66
- else
67
- drop_without_oboe
68
70
  end
69
- end
70
-
71
- Oboe::Inst::Moped::DB_OPS.each do |m|
72
- if method_defined?(m)
73
- class_eval "alias #{m}_without_oboe #{m}"
74
- class_eval "alias #{m} #{m}_with_oboe"
75
- else puts "[oboe/loading] Couldn't properly instrument moped (#{m}). Partial traces may occur."
71
+
72
+ Oboe::Inst::Moped::DB_OPS.each do |m|
73
+ if method_defined?(m)
74
+ class_eval "alias #{m}_without_oboe #{m}"
75
+ class_eval "alias #{m} #{m}_with_oboe"
76
+ else puts "[oboe/loading] Couldn't properly instrument moped (#{m}). Partial traces may occur."
77
+ end
76
78
  end
77
79
  end
78
80
  end
79
81
  end
80
- end
81
82
 
82
- if defined?(::Moped::Indexes)
83
- module ::Moped
84
- class Indexes
85
- include Oboe::Inst::Moped
86
-
87
- def extract_trace_details(op)
88
- report_kvs = {}
89
- begin
90
- report_kvs[:Flavor] = Oboe::Inst::Moped::FLAVOR
91
- # FIXME: We're only grabbing the first of potentially multiple servers here
92
- report_kvs[:RemoteHost], report_kvs[:RemotePort] = database.session.cluster.seeds.first.split(':')
93
- report_kvs[:Database] = database.name
94
- report_kvs[:QueryOp] = op.to_s
95
- rescue
83
+ if defined?(::Moped::Indexes)
84
+ module ::Moped
85
+ class Indexes
86
+ include Oboe::Inst::Moped
87
+
88
+ def extract_trace_details(op)
89
+ report_kvs = {}
90
+ begin
91
+ report_kvs[:Flavor] = Oboe::Inst::Moped::FLAVOR
92
+ # FIXME: We're only grabbing the first of potentially multiple servers here
93
+ report_kvs[:RemoteHost], report_kvs[:RemotePort] = database.session.cluster.seeds.first.split(':')
94
+ report_kvs[:Database] = database.name
95
+ report_kvs[:QueryOp] = op.to_s
96
+ rescue
97
+ end
98
+ report_kvs
96
99
  end
97
- report_kvs
98
- end
99
-
100
- def create_with_oboe(key, options = {})
101
- if Oboe::Config.tracing?
102
- # We report :create_index here to be consistent
103
- # with other mongo implementations
104
- report_kvs = extract_trace_details(:create_index)
105
- report_kvs[:Key] = key.try(:to_json)
106
- report_kvs[:Options] = options.try(:to_json)
107
-
108
- Oboe::API.trace('mongo', report_kvs, :create_index) do
100
+
101
+ def create_with_oboe(key, options = {})
102
+ if Oboe.tracing?
103
+ # We report :create_index here to be consistent
104
+ # with other mongo implementations
105
+ report_kvs = extract_trace_details(:create_index)
106
+ report_kvs[:Key] = key.try(:to_json)
107
+ report_kvs[:Options] = options.try(:to_json)
108
+
109
+ Oboe::API.trace('mongo', report_kvs, :create_index) do
110
+ create_without_oboe(key, options = {})
111
+ end
112
+ else
109
113
  create_without_oboe(key, options = {})
110
114
  end
111
- else
112
- create_without_oboe(key, options = {})
113
115
  end
114
- end
115
-
116
- def drop_with_oboe(key = nil)
117
- if Oboe::Config.tracing?
118
- # We report :drop_indexes here to be consistent
119
- # with other mongo implementations
120
- report_kvs = extract_trace_details(:drop_indexes)
121
- report_kvs[:Key] = key.nil? ? "all" : key.try(:to_json)
122
-
123
- Oboe::API.trace('mongo', report_kvs) do
116
+
117
+ def drop_with_oboe(key = nil)
118
+ if Oboe.tracing?
119
+ # We report :drop_indexes here to be consistent
120
+ # with other mongo implementations
121
+ report_kvs = extract_trace_details(:drop_indexes)
122
+ report_kvs[:Key] = key.nil? ? "all" : key.try(:to_json)
123
+
124
+ Oboe::API.trace('mongo', report_kvs) do
125
+ drop_without_oboe(key = nil)
126
+ end
127
+ else
124
128
  drop_without_oboe(key = nil)
125
129
  end
126
- else
127
- drop_without_oboe(key = nil)
128
130
  end
129
- end
130
131
 
131
- Oboe::Inst::Moped::INDEX_OPS.each do |m|
132
- if method_defined?(m)
133
- class_eval "alias #{m}_without_oboe #{m}"
134
- class_eval "alias #{m} #{m}_with_oboe"
135
- else puts "[oboe/loading] Couldn't properly instrument moped (#{m}). Partial traces may occur."
132
+ Oboe::Inst::Moped::INDEX_OPS.each do |m|
133
+ if method_defined?(m)
134
+ class_eval "alias #{m}_without_oboe #{m}"
135
+ class_eval "alias #{m} #{m}_with_oboe"
136
+ else puts "[oboe/loading] Couldn't properly instrument moped (#{m}). Partial traces may occur."
137
+ end
136
138
  end
137
139
  end
138
140
  end
139
141
  end
140
- end
141
142
 
142
- if defined?(::Moped::Query)
143
- module ::Moped
144
- class Query
145
- include Oboe::Inst::Moped
146
-
147
-
148
- def extract_trace_details(op)
149
- report_kvs = {}
150
- begin
151
- report_kvs[:Flavor] = Oboe::Inst::Moped::FLAVOR
152
- # FIXME: We're only grabbing the first of potentially multiple servers here
153
- report_kvs[:RemoteHost], report_kvs[:RemotePort] = collection.database.session.cluster.seeds.first.split(':')
154
- report_kvs[:Database] = collection.database.name
155
- report_kvs[:Collection_Name] = collection.name
156
- report_kvs[:QueryOp] = op.to_s
157
- rescue
143
+ if defined?(::Moped::Query)
144
+ module ::Moped
145
+ class Query
146
+ include Oboe::Inst::Moped
147
+
148
+
149
+ def extract_trace_details(op)
150
+ report_kvs = {}
151
+ begin
152
+ report_kvs[:Flavor] = Oboe::Inst::Moped::FLAVOR
153
+ # FIXME: We're only grabbing the first of potentially multiple servers here
154
+ report_kvs[:RemoteHost], report_kvs[:RemotePort] = collection.database.session.cluster.seeds.first.split(':')
155
+ report_kvs[:Database] = collection.database.name
156
+ report_kvs[:Collection_Name] = collection.name
157
+ report_kvs[:QueryOp] = op.to_s
158
+ rescue
159
+ end
160
+ report_kvs
158
161
  end
159
- report_kvs
160
- end
161
-
162
- def count_with_oboe
163
- if Oboe::Config.tracing?
164
- report_kvs = extract_trace_details(:count)
165
- report_kvs[:Query] = selector.try(:empty?) ? "all" : selector.try(:to_json)
166
-
167
- Oboe::API.trace('mongo', report_kvs) do
162
+
163
+ def count_with_oboe
164
+ if Oboe.tracing?
165
+ report_kvs = extract_trace_details(:count)
166
+ report_kvs[:Query] = selector.try(:empty?) ? "all" : selector.try(:to_json)
167
+
168
+ Oboe::API.trace('mongo', report_kvs) do
169
+ count_without_oboe
170
+ end
171
+ else
168
172
  count_without_oboe
169
173
  end
170
- else
171
- count_without_oboe
172
174
  end
173
- end
174
175
 
175
- def sort_with_oboe(sort)
176
- if Oboe::Config.tracing?
177
- report_kvs = extract_trace_details(:sort)
178
- report_kvs[:Query] = selector.try(:empty?) ? "all" : selector.try(:to_json)
179
- report_kvs[:Order] = sort.to_s
176
+ def sort_with_oboe(sort)
177
+ if Oboe.tracing?
178
+ report_kvs = extract_trace_details(:sort)
179
+ report_kvs[:Query] = selector.try(:empty?) ? "all" : selector.try(:to_json)
180
+ report_kvs[:Order] = sort.to_s
180
181
 
181
- Oboe::API.trace('mongo', report_kvs) do
182
+ Oboe::API.trace('mongo', report_kvs) do
183
+ sort_without_oboe(sort)
184
+ end
185
+ else
182
186
  sort_without_oboe(sort)
183
187
  end
184
- else
185
- sort_without_oboe(sort)
186
188
  end
187
- end
188
-
189
- def limit_with_oboe(limit)
190
- if Oboe::Config.tracing? and not Oboe::Context.tracing_layer_op?(:explain)
191
- report_kvs = extract_trace_details(:limit)
192
- report_kvs[:Query] = selector.try(:empty?) ? "all" : selector.try(:to_json)
193
- report_kvs[:Limit] = limit.to_s
194
-
195
- Oboe::API.trace('mongo', report_kvs) do
189
+
190
+ def limit_with_oboe(limit)
191
+ if Oboe.tracing? and not Oboe::Context.tracing_layer_op?(:explain)
192
+ report_kvs = extract_trace_details(:limit)
193
+ report_kvs[:Query] = selector.try(:empty?) ? "all" : selector.try(:to_json)
194
+ report_kvs[:Limit] = limit.to_s
195
+
196
+ Oboe::API.trace('mongo', report_kvs) do
197
+ limit_without_oboe(limit)
198
+ end
199
+ else
196
200
  limit_without_oboe(limit)
197
201
  end
198
- else
199
- limit_without_oboe(limit)
200
202
  end
201
- end
202
203
 
203
- def distinct_with_oboe(key)
204
- if Oboe::Config.tracing?
205
- report_kvs = extract_trace_details(:distinct)
206
- report_kvs[:Query] = selector.try(:empty?) ? "all" : selector.try(:to_json)
207
- report_kvs[:Key] = key.to_s
204
+ def distinct_with_oboe(key)
205
+ if Oboe.tracing?
206
+ report_kvs = extract_trace_details(:distinct)
207
+ report_kvs[:Query] = selector.try(:empty?) ? "all" : selector.try(:to_json)
208
+ report_kvs[:Key] = key.to_s
208
209
 
209
- Oboe::API.trace('mongo', report_kvs) do
210
+ Oboe::API.trace('mongo', report_kvs) do
211
+ distinct_without_oboe(key)
212
+ end
213
+ else
210
214
  distinct_without_oboe(key)
211
215
  end
212
- else
213
- distinct_without_oboe(key)
214
216
  end
215
- end
216
-
217
- def update_with_oboe(change, flags = nil)
218
- if Oboe::Config.tracing? and not Oboe::Context.tracing_layer_op?([:update_all, :upsert])
219
- report_kvs = extract_trace_details(:update)
220
- report_kvs[:Flags] = flags.to_s if flags
221
- report_kvs[:Update_Document] = change.try(:to_json)
222
-
223
- Oboe::API.trace('mongo', report_kvs) do
217
+
218
+ def update_with_oboe(change, flags = nil)
219
+ if Oboe.tracing? and not Oboe::Context.tracing_layer_op?([:update_all, :upsert])
220
+ report_kvs = extract_trace_details(:update)
221
+ report_kvs[:Flags] = flags.to_s if flags
222
+ report_kvs[:Update_Document] = change.try(:to_json)
223
+
224
+ Oboe::API.trace('mongo', report_kvs) do
225
+ update_without_oboe(change, flags = nil)
226
+ end
227
+ else
224
228
  update_without_oboe(change, flags = nil)
225
229
  end
226
- else
227
- update_without_oboe(change, flags = nil)
228
230
  end
229
- end
230
-
231
- def update_all_with_oboe(change)
232
- if Oboe::Config.tracing?
233
- report_kvs = extract_trace_details(:update_all)
234
- report_kvs[:Update_Document] = change.try(:to_json)
235
-
236
- Oboe::API.trace('mongo', report_kvs, :update_all) do
231
+
232
+ def update_all_with_oboe(change)
233
+ if Oboe.tracing?
234
+ report_kvs = extract_trace_details(:update_all)
235
+ report_kvs[:Update_Document] = change.try(:to_json)
236
+
237
+ Oboe::API.trace('mongo', report_kvs, :update_all) do
238
+ update_all_without_oboe(change)
239
+ end
240
+ else
237
241
  update_all_without_oboe(change)
238
242
  end
239
- else
240
- update_all_without_oboe(change)
241
243
  end
242
- end
243
244
 
244
- def upsert_with_oboe(change)
245
- if Oboe::Config.tracing?
246
- report_kvs = extract_trace_details(:upsert)
247
- report_kvs[:Query] = selector.try(:to_json)
248
- report_kvs[:Update_Document] = change.try(:to_json)
245
+ def upsert_with_oboe(change)
246
+ if Oboe.tracing?
247
+ report_kvs = extract_trace_details(:upsert)
248
+ report_kvs[:Query] = selector.try(:to_json)
249
+ report_kvs[:Update_Document] = change.try(:to_json)
249
250
 
250
- Oboe::API.trace('mongo', report_kvs, :upsert) do
251
+ Oboe::API.trace('mongo', report_kvs, :upsert) do
252
+ upsert_without_oboe(change)
253
+ end
254
+ else
251
255
  upsert_without_oboe(change)
252
256
  end
253
- else
254
- upsert_without_oboe(change)
255
257
  end
256
- end
257
258
 
258
- def explain_with_oboe
259
- if Oboe::Config.tracing?
260
- report_kvs = extract_trace_details(:explain)
261
- report_kvs[:Query] = selector.try(:empty?) ? "all" : selector.try(:to_json)
259
+ def explain_with_oboe
260
+ if Oboe.tracing?
261
+ report_kvs = extract_trace_details(:explain)
262
+ report_kvs[:Query] = selector.try(:empty?) ? "all" : selector.try(:to_json)
262
263
 
263
- Oboe::API.trace('mongo', report_kvs, :explain) do
264
+ Oboe::API.trace('mongo', report_kvs, :explain) do
265
+ explain_without_oboe
266
+ end
267
+ else
264
268
  explain_without_oboe
265
269
  end
266
- else
267
- explain_without_oboe
268
270
  end
269
- end
270
-
271
- def modify_with_oboe(change, options = {})
272
- if Oboe::Config.tracing?
273
- report_kvs = extract_trace_details(:modify)
274
- report_kvs[:Update_Document] = selector.try(:empty?) ? "all" : selector.try(:to_json)
275
- report_kvs[:Change] = change.try(:to_json)
276
- report_kvs[:Options] = options.try(:to_json)
277
271
 
278
- Oboe::API.trace('mongo', report_kvs) do
272
+ def modify_with_oboe(change, options = {})
273
+ if Oboe.tracing?
274
+ report_kvs = extract_trace_details(:modify)
275
+ report_kvs[:Update_Document] = selector.try(:empty?) ? "all" : selector.try(:to_json)
276
+ report_kvs[:Change] = change.try(:to_json)
277
+ report_kvs[:Options] = options.try(:to_json)
278
+
279
+ Oboe::API.trace('mongo', report_kvs) do
280
+ modify_without_oboe(change, options)
281
+ end
282
+ else
279
283
  modify_without_oboe(change, options)
280
284
  end
281
- else
282
- modify_without_oboe(change, options)
283
285
  end
284
- end
285
-
286
- def remove_with_oboe
287
- if Oboe::Config.tracing?
288
- report_kvs = extract_trace_details(:remove)
289
- report_kvs[:Query] = selector.try(:to_json)
290
-
291
- Oboe::API.trace('mongo', report_kvs) do
286
+
287
+ def remove_with_oboe
288
+ if Oboe.tracing?
289
+ report_kvs = extract_trace_details(:remove)
290
+ report_kvs[:Query] = selector.try(:to_json)
291
+
292
+ Oboe::API.trace('mongo', report_kvs) do
293
+ remove_without_oboe
294
+ end
295
+ else
292
296
  remove_without_oboe
293
297
  end
294
- else
295
- remove_without_oboe
296
298
  end
297
- end
298
299
 
299
- def remove_all_with_oboe
300
- if Oboe::Config.tracing?
301
- report_kvs = extract_trace_details(:remove_all)
302
- report_kvs[:Query] = selector.try(:to_json)
300
+ def remove_all_with_oboe
301
+ if Oboe.tracing?
302
+ report_kvs = extract_trace_details(:remove_all)
303
+ report_kvs[:Query] = selector.try(:to_json)
303
304
 
304
- Oboe::API.trace('mongo', report_kvs) do
305
+ Oboe::API.trace('mongo', report_kvs) do
306
+ remove_all_without_oboe
307
+ end
308
+ else
305
309
  remove_all_without_oboe
306
310
  end
307
- else
308
- remove_all_without_oboe
309
311
  end
310
- end
311
312
 
312
- Oboe::Inst::Moped::QUERY_OPS.each do |m|
313
- if method_defined?(m)
314
- class_eval "alias #{m}_without_oboe #{m}"
315
- class_eval "alias #{m} #{m}_with_oboe"
316
- else puts "[oboe/loading] Couldn't properly instrument moped (#{m}). Partial traces may occur."
313
+ Oboe::Inst::Moped::QUERY_OPS.each do |m|
314
+ if method_defined?(m)
315
+ class_eval "alias #{m}_without_oboe #{m}"
316
+ class_eval "alias #{m} #{m}_with_oboe"
317
+ else puts "[oboe/loading] Couldn't properly instrument moped (#{m}). Partial traces may occur."
318
+ end
317
319
  end
318
320
  end
319
321
  end
320
- end
321
- end # ::Moped::Query
322
-
323
-
324
- if defined?(::Moped::Collection)
325
- module ::Moped
326
- class Collection
327
- include Oboe::Inst::Moped
328
-
329
- def extract_trace_details(op)
330
- report_kvs = {}
331
- begin
332
- report_kvs[:Flavor] = Oboe::Inst::Moped::FLAVOR
333
- # FIXME: We're only grabbing the first of potentially multiple servers here
334
- report_kvs[:RemoteHost], report_kvs[:RemotePort] = @database.session.cluster.seeds.first.split(':')
335
- report_kvs[:Database] = @database.name
336
- report_kvs[:Collection_Name] = @name
337
- report_kvs[:QueryOp] = op.to_s
338
- rescue
322
+ end # ::Moped::Query
323
+
324
+
325
+ if defined?(::Moped::Collection)
326
+ module ::Moped
327
+ class Collection
328
+ include Oboe::Inst::Moped
329
+
330
+ def extract_trace_details(op)
331
+ report_kvs = {}
332
+ begin
333
+ report_kvs[:Flavor] = Oboe::Inst::Moped::FLAVOR
334
+ # FIXME: We're only grabbing the first of potentially multiple servers here
335
+ report_kvs[:RemoteHost], report_kvs[:RemotePort] = @database.session.cluster.seeds.first.split(':')
336
+ report_kvs[:Database] = @database.name
337
+ report_kvs[:Collection_Name] = @name
338
+ report_kvs[:QueryOp] = op.to_s
339
+ rescue
340
+ end
341
+ report_kvs
339
342
  end
340
- report_kvs
341
- end
342
343
 
343
- def drop_with_oboe
344
- if Oboe::Config.tracing?
345
- # We report :drop_collection here to be consistent
346
- # with other mongo implementations
347
- report_kvs = extract_trace_details(:drop_collection)
344
+ def drop_with_oboe
345
+ if Oboe.tracing?
346
+ # We report :drop_collection here to be consistent
347
+ # with other mongo implementations
348
+ report_kvs = extract_trace_details(:drop_collection)
348
349
 
349
- Oboe::API.trace('mongo', report_kvs) do
350
+ Oboe::API.trace('mongo', report_kvs) do
351
+ drop_without_oboe
352
+ end
353
+ else
350
354
  drop_without_oboe
351
355
  end
352
- else
353
- drop_without_oboe
354
356
  end
355
- end
356
357
 
357
- def find_with_oboe(selector = {})
358
- if Oboe::Config.tracing?
359
- report_kvs = extract_trace_details(:find)
360
- report_kvs[:Query] = selector.try(:empty?) ? "all" : selector.try(:to_json)
358
+ def find_with_oboe(selector = {})
359
+ if Oboe.tracing?
360
+ report_kvs = extract_trace_details(:find)
361
+ report_kvs[:Query] = selector.try(:empty?) ? "all" : selector.try(:to_json)
361
362
 
362
- Oboe::API.trace('mongo', report_kvs) do
363
+ Oboe::API.trace('mongo', report_kvs) do
364
+ find_without_oboe(selector)
365
+ end
366
+ else
363
367
  find_without_oboe(selector)
364
368
  end
365
- else
366
- find_without_oboe(selector)
367
369
  end
368
- end
369
-
370
- def indexes_with_oboe
371
- if Oboe::Config.tracing?
372
- report_kvs = extract_trace_details(:indexes)
373
-
374
- Oboe::API.trace('mongo', report_kvs) do
370
+
371
+ def indexes_with_oboe
372
+ if Oboe.tracing?
373
+ report_kvs = extract_trace_details(:indexes)
374
+
375
+ Oboe::API.trace('mongo', report_kvs) do
376
+ indexes_without_oboe
377
+ end
378
+ else
375
379
  indexes_without_oboe
376
380
  end
377
- else
378
- indexes_without_oboe
379
381
  end
380
- end
381
-
382
- def insert_with_oboe(documents, flags = nil)
383
- if Oboe::Config.tracing? and not Oboe::Context.tracing_layer_op?(:create_index)
384
- report_kvs = extract_trace_details(:insert)
385
-
386
- Oboe::API.trace('mongo', report_kvs) do
382
+
383
+ def insert_with_oboe(documents, flags = nil)
384
+ if Oboe.tracing? and not Oboe::Context.tracing_layer_op?(:create_index)
385
+ report_kvs = extract_trace_details(:insert)
386
+
387
+ Oboe::API.trace('mongo', report_kvs) do
388
+ insert_without_oboe(documents, flags)
389
+ end
390
+ else
387
391
  insert_without_oboe(documents, flags)
388
392
  end
389
- else
390
- insert_without_oboe(documents, flags)
391
393
  end
392
- end
393
-
394
- def aggregate_with_oboe(pipeline)
395
- if Oboe::Config.tracing?
396
- report_kvs = extract_trace_details(:aggregate)
397
-
398
- Oboe::API.trace('mongo', report_kvs) do
394
+
395
+ def aggregate_with_oboe(pipeline)
396
+ if Oboe.tracing?
397
+ report_kvs = extract_trace_details(:aggregate)
398
+
399
+ Oboe::API.trace('mongo', report_kvs) do
400
+ aggregate_without_oboe(pipeline)
401
+ end
402
+ else
399
403
  aggregate_without_oboe(pipeline)
400
404
  end
401
- else
402
- aggregate_without_oboe(pipeline)
403
405
  end
404
- end
405
-
406
- Oboe::Inst::Moped::COLLECTION_OPS.each do |m|
407
- if method_defined?(m)
408
- class_eval "alias #{m}_without_oboe #{m}"
409
- class_eval "alias #{m} #{m}_with_oboe"
410
- else puts "[oboe/loading] Couldn't properly instrument moped (#{m}). Partial traces may occur."
406
+
407
+ Oboe::Inst::Moped::COLLECTION_OPS.each do |m|
408
+ if method_defined?(m)
409
+ class_eval "alias #{m}_without_oboe #{m}"
410
+ class_eval "alias #{m} #{m}_with_oboe"
411
+ else puts "[oboe/loading] Couldn't properly instrument moped (#{m}). Partial traces may occur."
412
+ end
411
413
  end
412
414
  end
413
415
  end
414
- end
415
- end # ::Moped::Collection
416
+ end # ::Moped::Collection
417
+ end