From b665fcc39866b0b7daf5c54a5ed95e9e2b898f2a Mon Sep 17 00:00:00 2001 From: Johnny Shields <27655+johnnyshields@users.noreply.github.com> Date: Thu, 19 Oct 2023 14:05:23 +0900 Subject: [PATCH 1/4] Rename resque:setup.rake to resque_setup.rake --- .../rails-51/lib/tasks/{resque:setup.rake => resque_setup.rake} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename example/rails-51/lib/tasks/{resque:setup.rake => resque_setup.rake} (100%) diff --git a/example/rails-51/lib/tasks/resque:setup.rake b/example/rails-51/lib/tasks/resque_setup.rake similarity index 100% rename from example/rails-51/lib/tasks/resque:setup.rake rename to example/rails-51/lib/tasks/resque_setup.rake From b62a1c62b1e1d26fc33b9b4c380585851626be13 Mon Sep 17 00:00:00 2001 From: Johnny Shields <27655+johnnyshields@users.noreply.github.com> Date: Thu, 19 Oct 2023 14:05:59 +0900 Subject: [PATCH 2/4] Rename resque:setup.rake to resque_setup.rake --- .../rails-60/lib/tasks/{resque:setup.rake => resque_setup.rake} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename example/rails-60/lib/tasks/{resque:setup.rake => resque_setup.rake} (100%) diff --git a/example/rails-60/lib/tasks/resque:setup.rake b/example/rails-60/lib/tasks/resque_setup.rake similarity index 100% rename from example/rails-60/lib/tasks/resque:setup.rake rename to example/rails-60/lib/tasks/resque_setup.rake From 390309c04bf63572486ee0fccda592d39487a83a Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Thu, 19 Oct 2023 14:19:14 +0900 Subject: [PATCH 3/4] Mongo add sort --- lib/bugsnag/integrations/mongo.rb | 1 + spec/integrations/mongo_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/bugsnag/integrations/mongo.rb b/lib/bugsnag/integrations/mongo.rb index e1b2d22d0..42f01416b 100644 --- a/lib/bugsnag/integrations/mongo.rb +++ b/lib/bugsnag/integrations/mongo.rb @@ -60,6 +60,7 @@ def leave_mongo_breadcrumb(event_name, event) filter = sanitize_filter_hash(command["filter"]) meta_data[:filter] = JSON.dump(filter) end + meta_data[:sort] = JSON.dump(command["sort"]) unless command["sort"].nil? end meta_data[:message] = event.message if defined?(event.message) diff --git a/spec/integrations/mongo_spec.rb b/spec/integrations/mongo_spec.rb index fc2594ebe..e1bfe9c2e 100644 --- a/spec/integrations/mongo_spec.rb +++ b/spec/integrations/mongo_spec.rb @@ -174,6 +174,27 @@ def require(path) ) subscriber.send(:leave_mongo_breadcrumb, event_name, event) end + + it "adds a JSON string of sort data" do + command["sort"] = {"a" => 1, "b" => -1} + expect(subscriber).to receive(:pop_command).with("123456").and_return(command) + expect(Bugsnag).to receive(:leave_breadcrumb).with( + "Mongo query #{event_name}", + { + :event_name => "mongo.#{event_name}", + :command_name => "command", + :database_name => "database", + :operation_id => "1234567890", + :request_id => "123456", + :duration => "123.456", + :collection => "collection_name_command", + :sort => '{"a":1,"b":-1}' + }, + "process", + :auto + ) + subscriber.send(:leave_mongo_breadcrumb, event_name, event) + end end end From 69ada998611c29bf411149b4da5a772c8cead0b9 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Thu, 19 Oct 2023 15:04:38 +0900 Subject: [PATCH 4/4] Nongo "filter": Summarize length for long arrays (size > 3) --- lib/bugsnag/integrations/mongo.rb | 7 ++++++- spec/integrations/mongo_spec.rb | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/bugsnag/integrations/mongo.rb b/lib/bugsnag/integrations/mongo.rb index 42f01416b..57ac60d80 100644 --- a/lib/bugsnag/integrations/mongo.rb +++ b/lib/bugsnag/integrations/mongo.rb @@ -11,6 +11,7 @@ class MongoBreadcrumbSubscriber MONGO_EVENT_PREFIX = "mongo." MONGO_COMMAND_KEY = :bugsnag_mongo_commands MAX_FILTER_DEPTH = 5 + MAX_ARRAY_LENGTH = 3 ## # Listens to the 'started' event, storing the command for later usage @@ -92,7 +93,11 @@ def sanitize_filter_value(value, depth) if depth >= MAX_FILTER_DEPTH '[MAX_FILTER_DEPTH_REACHED]' elsif value.is_a?(Array) - value.map { |array_value| sanitize_filter_value(array_value, depth) } + if value.size > MAX_ARRAY_LENGTH && value.none? { |v| v.is_a?(Hash) || v.is_a?(Array) } + ["LENGTH=#{value.size}"] + else + value.map { |array_value| sanitize_filter_value(array_value, depth) } + end elsif value.is_a?(Hash) sanitize_filter_hash(value, depth) else diff --git a/spec/integrations/mongo_spec.rb b/spec/integrations/mongo_spec.rb index e1bfe9c2e..e845e626d 100644 --- a/spec/integrations/mongo_spec.rb +++ b/spec/integrations/mongo_spec.rb @@ -216,6 +216,12 @@ def require(path) expect(subscriber.send(:sanitize_filter_value, [1, [2, [3]]], 0)).to eq(['?', ['?', ['?']]]) end + it "returns LENGTH= for long arrays" do + actual = subscriber.send(:sanitize_filter_value, [1, [2, 2, 2], 3, 4, [5, 5, 5, 5], 6], 0) + expected = ['?', %w[? ? ?], '?', '?', ['LENGTH=4'], '?'] + expect(actual).to eq(expected) + end + it "calls #sanitize_filter_hash for hash values" do expect(subscriber).to receive(:sanitize_filter_hash).with({:a => 1}, 1) subscriber.send(:sanitize_filter_value, {:a => 1}, 0)