lib/elastic_apm/spies/mongo.rb in elastic-apm-3.2.0 vs lib/elastic_apm/spies/mongo.rb in elastic-apm-3.3.0

- old
+ new

@@ -34,19 +34,25 @@ pop_event(event) end private - # rubocop:disable Metrics/MethodLength def push_event(event) return unless ElasticAPM.current_transaction # Some MongoDB commands are not on collections but rather are db # admin commands. For these commands, the value at the `command_name` # key is the integer 1. - unless event.command[event.command_name] == 1 - collection = event.command[event.command_name] - end + # For getMore commands, the value at `command_name` is the cursor id + # 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[:collection] + else + event.command[event.command_name] + end + name = [event.database_name, collection, event.command_name].compact.join('.') span = @@ -58,10 +64,9 @@ context: build_context(event) ) @events[event.operation_id] = span end - # rubocop:enable Metrics/MethodLength def pop_event(event) return unless (curr = ElasticAPM.current_span) span = @events.delete(event.operation_id)