Class: Mongo::Collection::View
- Inherits:
-
Object
- Object
- Mongo::Collection::View
- Defined in:
- lib/traceview/inst/mongo2.rb
Instance Method Summary collapse
-
#collect_kvs(op, args) ⇒ Object
collect_kvs.
-
#m ⇒ Object
Here we dynamically define wrapper methods for the operations we want to instrument in mongo.
Instance Method Details
#collect_kvs(op, args) ⇒ Object
collect_kvs
Used to collect up information to report and build a hash with the Keys/Values to report.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/traceview/inst/mongo2.rb', line 108 def collect_kvs(op, args) kvs = { :Flavor => :mongodb, :Database => @collection.database.name } kvs[:QueryOp] = op kvs[:Collection] = @collection.name if op == :map_reduce kvs[:Map_Function] = args[0] kvs[:Reduce_Function] = args[1] kvs[:Limit] = args[2][:limit] if args[2].is_a?(Hash) && args[2].key?(:limit) end if TraceView::Config[:mongo][:log_args] if VIEW_QUERY_OPS.include?(op) if defined?(filter) kvs[:Query] = filter.to_json elsif defined?(selector) kvs[:Query] = selector.to_json end end end kvs[:RemoteHost] = @collection.database.client.cluster.addresses.first.to_s kvs[:Backtrace] = TraceView::API.backtrace if TraceView::Config[:mongo][:collect_backtraces] rescue => e TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.}" if TraceView::Config[:verbose] ensure return kvs end |
#m ⇒ Object
Here we dynamically define wrapper methods for the operations we want to instrument in mongo
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/traceview/inst/mongo2.rb', line 142 VIEW_OPS.reject { |m| !method_defined?(m) }.each do |m| define_method("#{m}_with_traceview") do |*args| begin if !TraceView.tracing? || TraceView.tracing_layer?(:mongo) mongo_skipped = true return send("#{m}_without_traceview", *args) end kvs = collect_kvs(m, args) TraceView::API.log_entry(:mongo, kvs) send("#{m}_without_traceview", *args) rescue => e TraceView::API.log_exception(:mongo, e) raise e ensure TraceView::API.log_exit(:mongo) unless mongo_skipped end end ::TraceView::Util.method_alias(Mongo::Collection::View, m) end |