Module: TraceView::Inst::MopedDatabase

Includes:
Moped
Defined in:
lib/traceview/inst/moped.rb

Overview

MopedDatabase

Constant Summary

Constants included from 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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Moped

#remote_host

Class Method Details

.included(klass) ⇒ Object



48
49
50
51
52
# File 'lib/traceview/inst/moped.rb', line 48

def self.included(klass)
  TraceView::Inst::Moped::DB_OPS.each do |m|
    ::TraceView::Util.method_alias(klass, m)
  end
end

Instance Method Details

#command_with_traceview(command) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/traceview/inst/moped.rb', line 68

def command_with_traceview(command)
  if TraceView.tracing? && !TraceView.layer_op && command.key?(:mapreduce)
    begin
      report_kvs = extract_trace_details(:map_reduce)
      report_kvs[:Map_Function] = command[:map]
      report_kvs[:Reduce_Function] = command[:reduce]
    rescue => e
      TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
    end

    TraceView::API.trace(:mongo, report_kvs) do
      command_without_traceview(command)
    end
  else
    command_without_traceview(command)
  end
end

#drop_with_traceviewObject



86
87
88
89
90
91
92
93
94
# File 'lib/traceview/inst/moped.rb', line 86

def drop_with_traceview
  return drop_without_traceview unless TraceView.tracing?

  report_kvs = extract_trace_details(:drop_database)

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

#extract_trace_details(op) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/traceview/inst/moped.rb', line 54

def extract_trace_details(op)
  report_kvs = {}
  report_kvs[:Flavor] = TraceView::Inst::Moped::FLAVOR
  # FIXME: We're only grabbing the first of potentially multiple servers here
  report_kvs[:RemoteHost] = remote_host(session.cluster.seeds.first)
  report_kvs[:Database] = 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] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
ensure
  return report_kvs
end