From 3496e2e7f6c8e7890fe6ded27b2ef7833badb9f7 Mon Sep 17 00:00:00 2001 From: "Charles C. Lee" Date: Thu, 19 Oct 2023 11:29:53 -0700 Subject: [PATCH] Add a warning message when notify payloads are subject to truncation --- lib/bugsnag.rb | 5 +++++ lib/bugsnag/helpers.rb | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/bugsnag.rb b/lib/bugsnag.rb index 5d002a907..1b50ca85c 100644 --- a/lib/bugsnag.rb +++ b/lib/bugsnag.rb @@ -535,6 +535,11 @@ def check_endpoint_setup # @return [String] def report_to_json(report) cleaned = cleaner.clean_object(report.as_json) + + if Bugsnag::Helpers.payload_too_long?(cleaned) + configuration.warn("The notify payload is too large and will be truncated.") + end + trimmed = Bugsnag::Helpers.trim_if_needed(cleaned) ::JSON.dump(trimmed) diff --git a/lib/bugsnag/helpers.rb b/lib/bugsnag/helpers.rb index 7a1c41786..cb43f5cf1 100644 --- a/lib/bugsnag/helpers.rb +++ b/lib/bugsnag/helpers.rb @@ -71,6 +71,13 @@ def self.deep_merge!(l_hash, r_hash) end end + ## + # Validate that the serialized JSON string value is below maximum payload + # length + def self.payload_too_long?(value) + get_payload_length(value) >= MAX_PAYLOAD_LENGTH + end + private TRUNCATION_INFO = '[TRUNCATED]' @@ -156,13 +163,6 @@ def self.trim_strings_in_value(value) end end - ## - # Validate that the serialized JSON string value is below maximum payload - # length - def self.payload_too_long?(value) - get_payload_length(value) >= MAX_PAYLOAD_LENGTH - end - def self.get_payload_length(value) if value.is_a?(String) value.length