-
Notifications
You must be signed in to change notification settings - Fork 173
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
WIP: Up limits on payload lengths, more focussed trimming #431
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fairly complex solution to the problem and expensive for what it does. Serializing the payload is relatively costly and shouldn't be done for every stacktrace line, for example. Added more inline.
lib/bugsnag/stacktrace.rb
Outdated
@@ -1,3 +1,5 @@ | |||
require 'pp' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this from debugging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll remove that.
spec/helper_spec.rb
Outdated
@@ -171,6 +172,111 @@ def to_s | |||
expect(trimmed_value[:events].first[:metaData]).to be_nil | |||
end | |||
end | |||
|
|||
context "and new trimming priorities are in place" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be a new context because no conditions are being changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's mostly a readability context for me at the moment before the tests are concreted.
lib/bugsnag/helpers.rb
Outdated
return payload unless payload.is_a?(Hash) and payload[:events].respond_to?(:map) | ||
payload[:events].map do |event| | ||
event[:exceptions].map do |exception| | ||
initial_size = get_payload_length(exception[:stacktrace]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just do exception[:stacktrace].each
and pop the code from each entry. No need for all of these checks and breaks or using downto
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/bugsnag/helpers.rb
Outdated
initial_size = get_payload_length(exception[:stacktrace]) | ||
(exception[:stacktrace].length - 1).downto(0).each do |i| | ||
break unless (initial_size - get_payload_length(exception[:stacktrace])) < threshold | ||
exception[:stacktrace][i].delete(:code) if exception[:stacktrace][i].include?(:code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to check for inclusion before deletion.
lib/bugsnag/helpers.rb
Outdated
def self.trim_stacktrace_functions(payload, threshold) | ||
return payload unless payload.is_a?(Hash) and payload[:events].respond_to?(:map) | ||
payload[:events].map do |event| | ||
event[:exceptions].map do |exception| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same changes as above ☝️
Can you ping me on this when it's ready for a second review. |
…ion data - Remove unnecessary trimming and reduce number of Stringifications
…ion data - Remove unnecessary tests, ensure tests are setup correctly
I've updated this to more closely match the original spec for trimming payloads.
|
…ion data - Refactor exception unpacking into helper function - Use each instead of map as result isn't utilised
lib/bugsnag/helpers.rb
Outdated
@@ -60,21 +70,74 @@ def self.deep_merge!(l_hash, r_hash) | |||
|
|||
TRUNCATION_INFO = '[TRUNCATED]' | |||
|
|||
## | |||
# Trim stacktrace code out if they're too large, oldest functions first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than checking the length for every line, just delete the code from every frame.
- # Trim stacktrace code out if they're too large, oldest functions first
+ # Remove all code from stacktraces
lib/bugsnag/helpers.rb
Outdated
# Shorten array until it fits within the payload size limit when serialized | ||
def self.truncate_array(array) | ||
def self.truncate_array(array, limit = MAX_ARRAY_LENGTH) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If limit
is just a constant value everywhere and never modified, just use it directly instead of passing it from one method to the next.
34e9c35
to
8662014
Compare
Changes how payload trimming is implemented to favour keeping longer stacktraces in place rather than limiting them to 40 items.
Namely:
:code
from stacktrace items, oldest first, until within limitsWIP: