Class: Moped::Query

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

Constant Summary

Constants included from TraceView::Inst::Moped

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

Instance Method Summary collapse

Instance Method Details

#count_with_traceviewObject



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

def count_with_traceview
  return count_without_traceview unless TraceView.tracing?

  begin
    report_kvs = extract_trace_details(:count)
    report_kvs[:Query] = selector.empty? ? 'all' : selector.to_json
  rescue StandardError => e
    TraceView.logger.debug "[traceview/debug] Moped KV collection error: #{e.inspect}"
  end

  TraceView::API.trace('mongo', report_kvs) do
    count_without_traceview
  end
end

#distinct_with_traceview(key) ⇒ Object



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

def distinct_with_traceview(key)
  return distinct_without_traceview(key) unless TraceView.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
    TraceView.logger.debug "[traceview/debug] Moped KV collection error: #{e.inspect}"
  end

  TraceView::API.trace('mongo', report_kvs) do
    distinct_without_traceview(key)
  end
end

#explain_with_traceviewObject



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

def explain_with_traceview
  return explain_without_traceview unless TraceView.tracing?

  begin
    report_kvs = extract_trace_details(:explain)
    report_kvs[:Query] = selector.empty? ? 'all' : selector.to_json
  rescue StandardError => e
    TraceView.logger.debug "[traceview/debug] Moped KV collection error: #{e.inspect}"
  end

  TraceView::API.trace('mongo', report_kvs, :explain) do
    explain_without_traceview
  end
end

#extract_trace_details(op) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/traceview/inst/moped.rb', line 170

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

#limit_with_traceview(limit) ⇒ Object



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

def limit_with_traceview(limit)
  if TraceView.tracing? && !TraceView.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
      TraceView.logger.debug "[traceview/debug] Moped KV collection error: #{e.inspect}"
    end

    TraceView::API.trace('mongo', report_kvs) do
      limit_without_traceview(limit)
    end
  else
    limit_without_traceview(limit)
  end
end

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



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

def modify_with_traceview(change, options = {})
  return modify_without_traceview(change, options) unless TraceView.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
    TraceView.logger.debug "[traceview/debug] Moped KV collection error: #{e.inspect}"
  end

  TraceView::API.trace('mongo', report_kvs) do
    modify_without_traceview(change, options)
  end
end

#remove_all_with_traceviewObject



352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/traceview/inst/moped.rb', line 352

def remove_all_with_traceview
  return remove_all_without_traceview unless TraceView.tracing?

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

  TraceView::API.trace('mongo', report_kvs) do
    remove_all_without_traceview
  end
end

#remove_with_traceviewObject



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

def remove_with_traceview
  return remove_without_traceview unless TraceView.tracing?

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

  TraceView::API.trace('mongo', report_kvs) do
    remove_without_traceview
  end
end

#sort_with_traceview(sort) ⇒ Object



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

def sort_with_traceview(sort)
  return sort_without_traceview(sort) unless TraceView.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
    TraceView.logger.debug "[traceview/debug] Moped KV collection error: #{e.inspect}"
  end

  TraceView::API.trace('mongo', report_kvs) do
    sort_without_traceview(sort)
  end
end

#update_all_with_traceview(change) ⇒ Object



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

def update_all_with_traceview(change)
  return update_all_without_traceview(change) unless TraceView.tracing?

  begin
    report_kvs = extract_trace_details(:update_all)
    report_kvs[:Update_Document] = change.to_json
  rescue StandardError => e
    TraceView.logger.debug "[traceview/debug] Moped KV collection error: #{e.inspect}"
  end

  TraceView::API.trace('mongo', report_kvs, :update_all) do
    update_all_without_traceview(change)
  end
end

#update_with_traceview(change, flags = nil) ⇒ Object



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

def update_with_traceview(change, flags = nil)
  if TraceView.tracing? && !TraceView.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
      TraceView.logger.debug "[traceview/debug] Moped KV collection error: #{e.inspect}"
    end

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

#upsert_with_traceview(change) ⇒ Object



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

def upsert_with_traceview(change)
  return upsert_without_traceview(change) unless TraceView.tracing?

  begin
    report_kvs = extract_trace_details(:upsert)
    report_kvs[:Query] = selector.to_json
    report_kvs[:Update_Document] = change.to_json
  rescue StandardError => e
    TraceView.logger.debug "[traceview/debug] Moped KV collection error: #{e.inspect}"
  end

  TraceView::API.trace('mongo', report_kvs, :upsert) do
    upsert_without_traceview(change)
  end
end