Module: TraceView::Inst::MopedIndexes

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

Overview

MopedIndexes

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



103
104
105
106
107
# File 'lib/traceview/inst/moped.rb', line 103

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

Instance Method Details

#create_with_traceview(key, options = {}) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/traceview/inst/moped.rb', line 129

def create_with_traceview(key, options = {})
  return create_without_traceview(key, options) unless TraceView.tracing?

  begin
    # We report :create_index here to be consistent
    # with other mongo implementations
    report_kvs = extract_trace_details(:create_index)
    report_kvs[:Key] = key.to_json
    report_kvs[:Options] = options.to_json
  rescue StandardError => e
    TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
  end

  TraceView::API.trace(:mongo, report_kvs, :create_index) do
    create_without_traceview(key, options = {})
  end
end

#drop_with_traceview(key = nil) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/traceview/inst/moped.rb', line 147

def drop_with_traceview(key = nil)
  return drop_without_traceview(key) unless TraceView.tracing?

  begin
    # We report :drop_indexes here to be consistent
    # with other mongo implementations
    report_kvs = extract_trace_details(:drop_indexes)
    report_kvs[:Key] = key.nil? ? :all : key.to_json
  rescue StandardError => e
    TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
  end

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

#extract_trace_details(op) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/traceview/inst/moped.rb', line 109

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
  first = database.session.cluster.seeds.first
  if ::Moped::VERSION < '2.0.0'
    report_kvs[:RemoteHost] = first
  else
    report_kvs[:RemoteHost] = "#{first.address.host}:#{first.address.port}"
  end
  report_kvs[:Database] = 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