Skip to content

Commit

Permalink
Update frame truncating to keep first & last N/2 frames instead of ju…
Browse files Browse the repository at this point in the history
…st last N frames
  • Loading branch information
PikachuEXE committed May 10, 2022
1 parent 1b39151 commit 4e48130
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
10 changes: 8 additions & 2 deletions sentry-ruby/lib/sentry/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,20 @@ def serialize_envelope(envelope)
single_exceptions.each do |single_exception|
traces = single_exception.dig(:stacktrace, :frames)
if traces && traces.size > STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD
traces.replace(traces[-STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD..-1])
size_on_both_ends = STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD / 2
traces.replace(
traces[0..(size_on_both_ends - 1)] + traces[-size_on_both_ends..-1],
)
end
end
elsif single_exceptions = item.payload.dig("exception", "values")
single_exceptions.each do |single_exception|
traces = single_exception.dig("stacktrace", "frames")
if traces && traces.size > STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD
traces.replace(traces[-STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD..-1])
size_on_both_ends = STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD / 2
traces.replace(
traces[0..(size_on_both_ends - 1)] + traces[-size_on_both_ends..-1],
)
end
end
end
Expand Down
21 changes: 19 additions & 2 deletions sentry-ruby/spec/sentry/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@
project_root = "/fake/project_root"
Regexp.new("^(#{project_root}/)?#{Sentry::Backtrace::APP_DIRS_PATTERN}")
end
let(:frame_list_size) { Sentry::Transport::STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD * 4 }
let(:frame_list_limit) { Sentry::Transport::STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD }
let(:frame_list_size) { frame_list_limit * 4 }

before do
single_exception = event.exception.instance_variable_get(:@values)[0]
Expand All @@ -173,10 +174,26 @@

event_item = envelope.items.first
frames = event_item.payload[:exception][:values][0][:stacktrace][:frames]
expect(frames.length).to eq(Sentry::Transport::STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD)
expect(frames.length).to eq(frame_list_limit)

# Last N lines kept
# N = Frame limit / 2
expect(frames[-1][:lineno]).to eq(frame_list_size)
expect(frames[-1][:filename]).to eq('app.rb')
expect(frames[-1][:function]).to eq('/')
#
expect(frames[-(frame_list_limit / 2)][:lineno]).to eq(frame_list_size - ((frame_list_limit / 2) - 1))
expect(frames[-(frame_list_limit / 2)][:filename]).to eq('app.rb')
expect(frames[-(frame_list_limit / 2)][:function]).to eq('/')

# First N lines kept
# N = Frame limit / 2
expect(frames[0][:lineno]).to eq(1)
expect(frames[0][:filename]).to eq('app.rb')
expect(frames[0][:function]).to eq('/')
expect(frames[(frame_list_limit / 2) - 1][:lineno]).to eq(frame_list_limit / 2)
expect(frames[(frame_list_limit / 2) - 1][:filename]).to eq('app.rb')
expect(frames[(frame_list_limit / 2) - 1][:function]).to eq('/')
end

context "if it's still oversized" do
Expand Down

0 comments on commit 4e48130

Please sign in to comment.