Class: Moped::Query

Inherits:
Object
  • Object
show all
Includes:
Oboe::Inst::Moped
Defined in:
lib/oboe/inst/moped.rb

Constant Summary

Constants included from Oboe::Inst::Moped

Oboe::Inst::Moped::COLLECTION_OPS, Oboe::Inst::Moped::DB_OPS, Oboe::Inst::Moped::FLAVOR, Oboe::Inst::Moped::INDEX_OPS, Oboe::Inst::Moped::QUERY_OPS

Instance Method Summary collapse

Instance Method Details

#count_with_oboeObject



176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/oboe/inst/moped.rb', line 176

def count_with_oboe
  return count_without_oboe unless Oboe.tracing?
    
  begin
    report_kvs = extract_trace_details(:count)
    report_kvs[:Query] = selector.empty? ? "all" : selector.to_json
  rescue StandardError => e
    Oboe.logger.debug "[oboe/debug] Moped KV collection error: #{e.inspect}"
  end

  Oboe::API.trace('mongo', report_kvs) do
    count_without_oboe
  end
end

#distinct_with_oboe(key) ⇒ Object



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/oboe/inst/moped.rb', line 225

def distinct_with_oboe(key)
  return distinct_without_oboe(key) unless Oboe.tracing?

  begin
    report_kvs = extract_trace_details(:distinct)
    report_kvs[:Query] = selector.empty? ? "all" : selector.to_json
    report_kvs[:Key] = key.to_s
  rescue StandardError => e
    Oboe.logger.debug "[oboe/debug] Moped KV collection error: #{e.inspect}"
  end

  Oboe::API.trace('mongo', report_kvs) do
    distinct_without_oboe(key)
  end
end

#explain_with_oboeObject



290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/oboe/inst/moped.rb', line 290

def explain_with_oboe
  return explain_without_oboe unless Oboe.tracing?
  
  begin
    report_kvs = extract_trace_details(:explain)
    report_kvs[:Query] = selector.empty? ? "all" : selector.to_json
  rescue StandardError => e
    Oboe.logger.debug "[oboe/debug] Moped KV collection error: #{e.inspect}"
  end

  Oboe::API.trace('mongo', report_kvs, :explain) do
    explain_without_oboe
  end
end

#extract_trace_details(op) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/oboe/inst/moped.rb', line 160

def extract_trace_details(op)
  report_kvs = {}
  begin
    report_kvs[:Flavor] = Oboe::Inst::Moped::FLAVOR
    # FIXME: We're only grabbing the first of potentially multiple servers here
    report_kvs[:RemoteHost], report_kvs[:RemotePort] = collection.database.session.cluster.seeds.first.split(':')
    report_kvs[:Database] = collection.database.name
    report_kvs[:Collection] = collection.name
    report_kvs[:QueryOp] = op.to_s
    report_kvs[:Backtrace] = Oboe::API.backtrace if Oboe::Config[:moped][:collect_backtraces]
  rescue StandardError => e
    Oboe.logger.debug "[oboe/debug] Moped KV collection error: #{e.inspect}"
  end
  report_kvs
end

#limit_with_oboe(limit) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/oboe/inst/moped.rb', line 207

def limit_with_oboe(limit)
  if Oboe.tracing? and not Oboe::Context.tracing_layer_op?(:explain)
    begin
      report_kvs = extract_trace_details(:limit)
      report_kvs[:Query] = selector.empty? ? "all" : selector.to_json
      report_kvs[:Limit] = limit.to_s
    rescue StandardError => e
      Oboe.logger.debug "[oboe/debug] Moped KV collection error: #{e.inspect}"
    end

    Oboe::API.trace('mongo', report_kvs) do
      limit_without_oboe(limit)
    end
  else 
    limit_without_oboe(limit) 
  end
end

#modify_with_oboe(change, options = {}) ⇒ Object



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/oboe/inst/moped.rb', line 305

def modify_with_oboe(change, options = {})
  return modify_without_oboe(change, options) unless Oboe.tracing?

  begin
    report_kvs = extract_trace_details(:modify)
    report_kvs[:Update_Document] = selector.empty? ? "all" : selector.to_json
    report_kvs[:Change] = change.to_json
    report_kvs[:Options] = options.to_json
  rescue StandardError => e
    Oboe.logger.debug "[oboe/debug] Moped KV collection error: #{e.inspect}"
  end

  Oboe::API.trace('mongo', report_kvs) do
    modify_without_oboe(change, options)
  end
end

#remove_all_with_oboeObject



337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/oboe/inst/moped.rb', line 337

def remove_all_with_oboe
  return remove_all_without_oboe unless Oboe.tracing?

  begin
    report_kvs = extract_trace_details(:remove_all)
    report_kvs[:Query] = selector.to_json
  rescue StandardError => e
    Oboe.logger.debug "[oboe/debug] Moped KV collection error: #{e.inspect}"
  end

  Oboe::API.trace('mongo', report_kvs) do
    remove_all_without_oboe
  end
end

#remove_with_oboeObject



322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/oboe/inst/moped.rb', line 322

def remove_with_oboe
  return remove_without_oboe unless Oboe.tracing?

  begin
    report_kvs = extract_trace_details(:remove)
    report_kvs[:Query] = selector.to_json
  rescue StandardError => e
    Oboe.logger.debug "[oboe/debug] Moped KV collection error: #{e.inspect}"
  end

  Oboe::API.trace('mongo', report_kvs) do
    remove_without_oboe
  end
end

#sort_with_oboe(sort) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/oboe/inst/moped.rb', line 191

def sort_with_oboe(sort)
  return sort_without_oboe(sort) unless Oboe.tracing?
    
  begin
    report_kvs = extract_trace_details(:sort)
    report_kvs[:Query] = selector.empty? ? "all" : selector.to_json
    report_kvs[:Order] = sort.to_s
  rescue StandardError => e
    Oboe.logger.debug "[oboe/debug] Moped KV collection error: #{e.inspect}"
  end

  Oboe::API.trace('mongo', report_kvs) do
    sort_without_oboe(sort)
  end
end

#update_all_with_oboe(change) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/oboe/inst/moped.rb', line 259

def update_all_with_oboe(change)
  return update_all_without_oboe(change) unless Oboe.tracing?
    
  begin
    report_kvs = extract_trace_details(:update_all)
    report_kvs[:Update_Document] = change.to_json
  rescue StandardError => e
    Oboe.logger.debug "[oboe/debug] Moped KV collection error: #{e.inspect}"
  end

  Oboe::API.trace('mongo', report_kvs, :update_all) do
    update_all_without_oboe(change)
  end
end

#update_with_oboe(change, flags = nil) ⇒ Object



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/oboe/inst/moped.rb', line 241

def update_with_oboe(change, flags = nil)
  if Oboe.tracing? and not Oboe::Context.tracing_layer_op?([:update_all, :upsert])
    begin
      report_kvs = extract_trace_details(:update)
      report_kvs[:Flags] = flags.to_s if flags
      report_kvs[:Update_Document] = change.to_json
    rescue StandardError => e
      Oboe.logger.debug "[oboe/debug] Moped KV collection error: #{e.inspect}"
    end

    Oboe::API.trace('mongo', report_kvs) do
      update_without_oboe(change, flags = nil)
    end
  else
    update_without_oboe(change, flags = nil)
  end
end

#upsert_with_oboe(change) ⇒ Object



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/oboe/inst/moped.rb', line 274

def upsert_with_oboe(change)
  return upsert_without_oboe(change) unless Oboe.tracing?
  
  begin
    report_kvs = extract_trace_details(:upsert)
    report_kvs[:Query] = selector.to_json
    report_kvs[:Update_Document] = change.to_json
  rescue StandardError => e
    Oboe.logger.debug "[oboe/debug] Moped KV collection error: #{e.inspect}"
  end

  Oboe::API.trace('mongo', report_kvs, :upsert) do
    upsert_without_oboe(change)
  end
end