Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/elastic_apm/spies/mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Subscriber
EVENT_KEY = :__elastic_instrumenter_mongo_events_key

def events
Thread.current[EVENT_KEY] ||= {}
Thread.current[EVENT_KEY] ||= []
end

def started(event)
Expand Down Expand Up @@ -72,7 +72,7 @@ def push_event(event)
# and the collection name is at the key `collection`
collection =
if event.command[event.command_name] == 1 ||
event.command[event.command_name].is_a?(BSON::Int64)
event.command[event.command_name].is_a?(BSON::Int64)
event.command[:collection]
else
event.command[event.command_name]
Expand All @@ -91,14 +91,13 @@ def push_event(event)
context: build_context(event)
)

events[event.operation_id] = span
events << span
end

def pop_event(event)
span = events.delete(event.operation_id)
return unless (curr = ElasticAPM.current_span)

curr == span && ElasticAPM.end_span
curr == events[-1] && ElasticAPM.end_span(events.pop)
end

def build_context(event)
Expand Down