Class: Mongo::Collection
- Inherits:
-
Object
- Object
- Mongo::Collection
- Includes:
- TraceView::Inst::Mongo
- Defined in:
- lib/traceview/inst/mongo.rb,
lib/traceview/inst/mongo2.rb,
lib/traceview/inst/mongo2.rb
Defined Under Namespace
Classes: View
Constant Summary
Constants included from TraceView::Inst::Mongo
TraceView::Inst::Mongo::COLL_INDEX_OPS, TraceView::Inst::Mongo::COLL_QUERY_OPS, TraceView::Inst::Mongo::COLL_WRITE_OPS, TraceView::Inst::Mongo::CURSOR_OPS, TraceView::Inst::Mongo::DB_OPS, TraceView::Inst::Mongo::FLAVOR
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.
- #traceview_collect(m, args) ⇒ Object
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.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/traceview/inst/mongo2.rb', line 30 def collect_kvs(op, args) kvs = { :Flavor => :mongodb, :Database => @database.name } kvs[:QueryOp] = op if op == :create kvs[:New_Collection_Name] = @name else kvs[:Collection] = @name end 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 COLL_QUERY_OPS.include?(op) kvs[:Query] = args.first.to_json end end kvs[:RemoteHost] = @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
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/traceview/inst/mongo2.rb', line 65 COLL_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, m) end |
#traceview_collect(m, args) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/traceview/inst/mongo.rb', line 122 def traceview_collect(m, args) kvs = {} kvs[:Flavor] = TraceView::Inst::Mongo::FLAVOR kvs[:Database] = @db.name kvs[:RemoteHost] = @db.connection.host kvs[:RemotePort] = @db.connection.port kvs[:Collection] = @name kvs[:Backtrace] = TraceView::API.backtrace if TraceView::Config[:mongo][:collect_backtraces] kvs[:QueryOp] = m kvs[:Query] = args[0].to_json if args && !args.empty? && args[0].class == Hash rescue StandardError => e TraceView.logger.debug "[traceview/debug] Exception in traceview_collect KV collection: #{e.inspect}" ensure return kvs end |