Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a warning message when notify payloads are subject to truncation #800

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/bugsnag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions lib/bugsnag/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
Expand Down Expand Up @@ -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
Expand Down