class TingYun::Instrumentation::MongoCommandLogSubscriber

Constants

COLLECTION
GET_MORE
MONGODB

Public Instance Methods

completed(event) click to toggle source
# File lib/ting_yun/instrumentation/mongo_command_log_subscriber.rb, line 27
def completed(event)
  begin
    state = TingYun::Agent::TransactionState.tl_get
    state.timings.mon_duration = state.timings.mon_duration +  event.duration * 1000
    started_event = operations.delete(event.operation_id)
    # TingYun::Agent.instance.stats_engine.tl_record_scoped_and_unscoped_metrics(
    #     base, other_metrics, event.duration*1000
    # )
    notice_nosql_statement(state, started_event, nil, event.duration, "Mongo::Monitoring::Global")
  rescue Exception => e
    log_notification_error('completed', e)
  end
end
Also aliased as: succeeded, failed
failed(event)
Alias for: completed
started(event) click to toggle source
# File lib/ting_yun/instrumentation/mongo_command_log_subscriber.rb, line 18
def started(event)
  begin
    operations[event.operation_id] = event
  rescue Exception => e
    log_notification_error('started', e)
  end
end
succeeded(event)
Alias for: completed

Private Instance Methods

collection(event) click to toggle source
# File lib/ting_yun/instrumentation/mongo_command_log_subscriber.rb, line 49
def collection(event)
  if event.command_name == GET_MORE
    event.command[COLLECTION]
  else
    event.command.values.first
  end
end
generate_statement(event) click to toggle source
# File lib/ting_yun/instrumentation/mongo_command_log_subscriber.rb, line 72
def generate_statement(event)
  TingYun::Instrumentation::Support::EventFormatter.format(
      event.command_name,
      event.database_name,
      event.command,
      event.address.host,
      event.address.port,
      event.inspect
  )
end
log_notification_error(event_type, error) click to toggle source
# File lib/ting_yun/instrumentation/mongo_command_log_subscriber.rb, line 57
def log_notification_error(event_type, error)
  TingYun::Agent.logger.error("Error during MongoDB #{event_type} event:")
  TingYun::Agent.logger.log_exception(:error, error)
  TingYun::Agent.notice_error(error,:type=>:exception)
end
metrics(event) click to toggle source
# File lib/ting_yun/instrumentation/mongo_command_log_subscriber.rb, line 68
def metrics(event)
  TingYun::Agent::Datastore::MetricHelper.metrics_for(MONGODB, TingYun::Agent::Datastore::Mongo.transform_operation(event.command_name), event.address.host, event.address.port, event.database_name, collection(event))
end
notice_nosql_statement(state, event, metric, duration, klass_name) click to toggle source
# File lib/ting_yun/instrumentation/mongo_command_log_subscriber.rb, line 83
def notice_nosql_statement(state, event, metric, duration, klass_name)
  end_time = Time.now.to_f

  stack  = state.traced_method_stack

  # enter transaction trace node
  frame = stack.push_frame(state, :mongo_db, end_time - duration)

  transaction_sampler.notice_nosql_statement(generate_statement(event),duration*1000,:nosql)

  # exit transaction trace node
  stack.pop_frame(state, frame, metric, end_time, true, klass_name)
end
operations() click to toggle source
# File lib/ting_yun/instrumentation/mongo_command_log_subscriber.rb, line 64
def operations
  @operations ||= {}
end
transaction_sampler() click to toggle source
# File lib/ting_yun/instrumentation/mongo_command_log_subscriber.rb, line 97
def transaction_sampler
  ::TingYun::Agent::Collector::TransactionSampler
end