Module: OneApm::Agent::Instrumentation::Moped
- Defined in:
- lib/one_apm/inst/nosql/mongo_moped.rb
Instance Method Summary collapse
- #determine_operation_and_collection(operation) ⇒ Object
- #logging_with_oneapm_trace(operations, &blk) ⇒ Object
Instance Method Details
#determine_operation_and_collection(operation) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/one_apm/inst/nosql/mongo_moped.rb', line 60 def determine_operation_and_collection(operation) log_statement = operation.log_inspect.encode("UTF-8") collection = "Unknown" if operation.respond_to?(:collection) collection = operation.collection end operation_name = log_statement.split[0] if operation_name == 'COMMAND' && log_statement.include?(":mapreduce") operation_name = 'MAPREDUCE' collection = log_statement[/:mapreduce=>"([^"]+)/,1] elsif operation_name == 'COMMAND' && log_statement.include?(":count") operation_name = 'COUNT' collection = log_statement[/:count=>"([^"]+)/,1] elsif operation_name == 'COMMAND' && log_statement.include?(":aggregate") operation_name = 'AGGREGATE' collection = log_statement[/:aggregate=>"([^"]+)/,1] elsif operation_name == 'COMMAND' && log_statement.include?(":findAndModify") operation_name = 'FIND_AND_MODIFY' collection = log_statement[/:findAndModify=>"([^"]+)/,1] end return operation_name, collection end |
#logging_with_oneapm_trace(operations, &blk) ⇒ Object
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 |
# File 'lib/one_apm/inst/nosql/mongo_moped.rb', line 30 def logging_with_oneapm_trace(operations, &blk) operation_name, collection = determine_operation_and_collection(operations.first) log_statement = operations.first.log_inspect.encode("UTF-8") operation = case operation_name when 'INSERT', 'UPDATE', 'CREATE', 'FIND_AND_MODIFY' then 'save' when 'QUERY', 'COUNT', 'GET_MORE', 'AGGREGATE' then 'find' when 'DELETE' then 'destroy' else nil end command = Proc.new { logging_without_oneapm_trace(operations, &blk) } res = nil if operation callback = Proc.new do |result, metric, elapsed| OneApm::Agent::Datastore.notice_statement(log_statement, elapsed) end OneApm::Agent::Datastore.wrap('MongoDB', operation, collection, callback) do res = command.call end else res = command.call end res end |