Class: Moped::Collection

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

#aggregate_with_traceview(*pipeline) ⇒ Object



453
454
455
456
457
458
459
460
461
462
# File 'lib/traceview/inst/moped.rb', line 453

def aggregate_with_traceview(*pipeline)
  return aggregate_without_traceview(pipeline) unless TraceView.tracing?

  report_kvs = extract_trace_details(:aggregate)
  report_kvs[:Query] = pipeline

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

#drop_with_traceviewObject



404
405
406
407
408
409
410
411
412
413
414
# File 'lib/traceview/inst/moped.rb', line 404

def drop_with_traceview
  return drop_without_traceview unless TraceView.tracing?

  # We report :drop_collection here to be consistent
  # with other mongo implementations
  report_kvs = extract_trace_details(:drop_collection)

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

#extract_trace_details(op) ⇒ Object



383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/traceview/inst/moped.rb', line 383

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] = database.session.cluster.seeds.first.split(':')
    else
      report_kvs[:RemoteHost] = database.session.cluster.seeds.first.address.host
      report_kvs[:RemotePort] = database.session.cluster.seeds.first.address.port
    end
    report_kvs[:Database] = database.name
    report_kvs[: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

#find_with_traceview(selector = {}) ⇒ Object



416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/traceview/inst/moped.rb', line 416

def find_with_traceview(selector = {})
  return find_without_traceview(selector) unless TraceView.tracing?

  begin
    report_kvs = extract_trace_details(:find)
    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
    find_without_traceview(selector)
  end
end

#indexes_with_traceviewObject



431
432
433
434
435
436
437
438
439
# File 'lib/traceview/inst/moped.rb', line 431

def indexes_with_traceview
  return indexes_without_traceview unless TraceView.tracing?

  report_kvs = extract_trace_details(:indexes)

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

#insert_with_traceview(documents, flags = nil) ⇒ Object



441
442
443
444
445
446
447
448
449
450
451
# File 'lib/traceview/inst/moped.rb', line 441

def insert_with_traceview(documents, flags = nil)
  if TraceView.tracing? && !TraceView.tracing_layer_op?(:create_index)
    report_kvs = extract_trace_details(:insert)

    TraceView::API.trace('mongo', report_kvs) do
      insert_without_traceview(documents, flags)
    end
  else
    insert_without_traceview(documents, flags)
  end
end