class OneApm::Agent::Instrumentation::MongoCommandSubscriber
Constants
- OA_FAILED
- OA_MONGODB
- OA_STARTED
- OA_SUCCEEDED
Public Instance Methods
failed(event)
click to toggle source
# File lib/one_apm/inst/nosql/mongo2.rb, line 26 def failed(event) operator OA_FAILED, event end
started(event)
click to toggle source
# File lib/one_apm/inst/nosql/mongo2.rb, line 13 def started(event) begin return unless OneApm::Manager.tl_is_execution_traced? operations[event.operation_id] = event rescue Exception => e log_operations_error(OA_STARTED, e) end end
succeeded(event)
click to toggle source
# File lib/one_apm/inst/nosql/mongo2.rb, line 22 def succeeded(event) operator OA_SUCCEEDED, event end
Private Instance Methods
generate_metrics(event)
click to toggle source
# File lib/one_apm/inst/nosql/mongo2.rb, line 36 def generate_metrics(event) @product ||= begin host = event.address.host rescue nil port = event.address.port rescue nil OneApm::Agent::Datastore.oneapm_product(OA_MONGODB, host, port) end OneApm::Agent::Datastore::MetricHelper.metrics_for(@product, event.command_name, event.command.values.first) end
log_operations_error(event_type, error)
click to toggle source
# File lib/one_apm/inst/nosql/mongo2.rb, line 88 def log_operations_error(event_type, error) OneApm::Manager.logger.error("Error during MongoDB #{event_type} event:") OneApm::Manager.logger.log_exception(:error, error) end
one_apm_notice_sql(state, event, status, duration)
click to toggle source
# File lib/one_apm/inst/nosql/mongo2.rb, line 65 def one_apm_notice_sql(state, event, status, duration) stack = state.traced_method_stack base, *other_metrics = generate_metrics(event) started_time = Time.now.to_f frame = stack.push_frame(state, :mongo_tracer, started_time - duration) builder = state.transaction_sample_builder format_sql = OneApm::Agent::Datastore::Mongo::CommandFormatter.format_sql(event, status) OneApm::Manager.agent.transaction_sampler.send(:notice_extra_data, builder, format_sql, duration, :sql) stack.pop_frame(state, frame, base, started_time) end
one_apm_notice_statement(event, status, duration)
click to toggle source
# File lib/one_apm/inst/nosql/mongo2.rb, line 79 def one_apm_notice_statement(event, status, duration) statement = OneApm::Agent::Datastore::Mongo::CommandFormatter.format(event, status) if statement OneApm::Manager.agent.transaction_sampler.notice_nosql_statement(statement, duration) end rescue => e OneApm::Manager.logger.debug("Exception during Mongo statement gathering", e) end
one_apm_record_metrics(event, duration)
click to toggle source
# File lib/one_apm/inst/nosql/mongo2.rb, line 58 def one_apm_record_metrics(event, duration) base, *other_metrics = generate_metrics(event) OneApm::Manager.agent.stats_engine.tl_record_scoped_and_unscoped_metrics( base, other_metrics, duration ) end
operations()
click to toggle source
# File lib/one_apm/inst/nosql/mongo2.rb, line 32 def operations @operations ||= {} end
operator(operator_type, event)
click to toggle source
# File lib/one_apm/inst/nosql/mongo2.rb, line 45 def operator(operator_type, event) begin state = OneApm::TransactionState.tl_get return unless state.is_execution_traced? stared_event = operations.delete(event.operation_id) one_apm_record_metrics(stared_event, event.duration) one_apm_notice_statement(stared_event, operator_type, event.duration) one_apm_notice_sql(state, stared_event, operator_type, event.duration) rescue => e log_operations_error(operator_type, e) end end