lib/elastic_apm/spies/mongo.rb in elastic-apm-4.4.0 vs lib/elastic_apm/spies/mongo.rb in elastic-apm-4.5.0

- old
+ new

@@ -33,12 +33,20 @@ class Subscriber TYPE = 'db' SUBTYPE = 'mongodb' ACTION = 'query' + EVENT_KEY = :__elastic_instrumenter_mongo_events_key + + class Collection + def events + Thread.current[EVENT_KEY] ||= {} + end + end + def initialize - @events = {} + @collection = Collection.new end def started(event) push_event(event) end @@ -87,14 +95,14 @@ subtype: SUBTYPE, action: ACTION, context: build_context(event) ) - @events[event.operation_id] = span + @collection.events[event.operation_id] = span end def pop_event(event) - span = @events.delete(event.operation_id) + span = @collection.events.delete(event.operation_id) return unless (curr = ElasticAPM.current_span) curr == span && ElasticAPM.end_span end