class ElasticAPM::Spies::MongoSpy::Subscriber

@api private

Constants

TYPE

Public Class Methods

new() click to toggle source
# File lib/elastic_apm/spies/mongo.rb, line 19
def initialize
  @events = {}
end

Public Instance Methods

failed(event) click to toggle source
# File lib/elastic_apm/spies/mongo.rb, line 27
def failed(event)
  pop_event(event)
end
started(event) click to toggle source
# File lib/elastic_apm/spies/mongo.rb, line 23
def started(event)
  push_event(event)
end
succeeded(event) click to toggle source
# File lib/elastic_apm/spies/mongo.rb, line 31
def succeeded(event)
  pop_event(event)
end

Private Instance Methods

build_context(event) click to toggle source
# File lib/elastic_apm/spies/mongo.rb, line 57
def build_context(event)
  Span::Context.new(
    db: {
      instance: event.database_name,
      statement: nil,
      type: 'mongodb',
      user: nil
    }
  )
end
pop_event(event) click to toggle source
# File lib/elastic_apm/spies/mongo.rb, line 50
def pop_event(event)
  return unless (curr = ElasticAPM.current_span)
  span = @events.delete(event.operation_id)

  curr == span && ElasticAPM.end_span
end
push_event(event) click to toggle source
# File lib/elastic_apm/spies/mongo.rb, line 37
def push_event(event)
  return unless ElasticAPM.current_transaction

  span =
    ElasticAPM.start_span(
      event.command_name.to_s,
      TYPE,
      context: build_context(event)
    )

  @events[event.operation_id] = span
end