diff --git a/lib/bugsnag.rb b/lib/bugsnag.rb index 5d002a90..1b50ca85 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 7a1c4178..cb43f5cf 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