Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Migrate from to_hash to to_h ([#2351](https://github.com/getsentry/sentry-ruby/pull/2351))
- Add `before_send_check_in` for applying to `CheckInEvent` ([#2703](https://github.com/getsentry/sentry-ruby/pull/2703))
- Returning a hash from `before_send` and `before_send_transaction` is no longer supported and will drop the event.
- Remove stacktrace trimming ([#2714](https://github.com/getsentry/sentry-ruby/pull/2714))

### Internal

Expand Down
22 changes: 0 additions & 22 deletions sentry-ruby/lib/sentry/envelope/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
module Sentry
# @api private
class Envelope::Item
STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD = 500
MAX_SERIALIZED_PAYLOAD_SIZE = 1024 * 1000

SIZE_LIMITS = Hash.new(MAX_SERIALIZED_PAYLOAD_SIZE).update(
Expand Down Expand Up @@ -45,11 +44,6 @@ def serialize
result = to_s
end

if result.bytesize > size_limit
reduce_stacktrace!
result = to_s
end

[result, result.bytesize > size_limit]
end

Expand All @@ -68,21 +62,5 @@ def remove_breadcrumbs!
payload.delete("breadcrumbs")
end
end

def reduce_stacktrace!
if exceptions = payload.dig(:exception, :values) || payload.dig("exception", "values")
exceptions.each do |exception|
# in most cases there is only one exception (2 or 3 when have multiple causes), so we won't loop through this double condition much
traces = exception.dig(:stacktrace, :frames) || exception.dig("stacktrace", "frames")

if traces && traces.size > STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD
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
end
end
end
73 changes: 0 additions & 73 deletions sentry-ruby/spec/sentry/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,79 +353,6 @@
end
end
end

context "due to stacktrace frames" do
let(:event) { client.event_from_exception(SystemStackError.new("stack level too deep")) }
let(:envelope) { subject.envelope_from_event(event) }

let(:in_app_pattern) do
project_root = "/fake/project_root"
Regexp.new("^(#{project_root}/)?#{Sentry::Configuration::APP_DIRS_PATTERN}")
end
let(:frame_list_limit) { 500 }
let(:frame_list_size) { frame_list_limit * 20 }

before do
single_exception = event.exception.values[0]
new_stacktrace = Sentry::StacktraceInterface.new(
frames: frame_list_size.times.map do |zero_based_index|
Sentry::StacktraceInterface::Frame.new(
"/fake/path",
Sentry::Backtrace::Line.parse("app.rb:#{zero_based_index + 1}:in `/'", in_app_pattern)
)
end,
)
single_exception.instance_variable_set(:@stacktrace, new_stacktrace)

serialized_result = JSON.generate(event.to_h)
expect(serialized_result.bytesize).to be > Sentry::Envelope::Item::MAX_SERIALIZED_PAYLOAD_SIZE
end

it "keeps some stacktrace frames and carry on" do
data, _ = subject.serialize_envelope(envelope)
expect(data.bytesize).to be < Sentry::Envelope::Item::MAX_SERIALIZED_PAYLOAD_SIZE

expect(envelope.items.count).to eq(1)

event_item = envelope.items.first
frames = event_item.payload[:exception][:values][0][:stacktrace][:frames]
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
before do
1000.times do |i|
event.contexts["context_#{i}"] = "s" * Sentry::Event::MAX_MESSAGE_SIZE_IN_BYTES
end
end

it "rejects the item and logs attributes size breakdown" do
data, _ = subject.serialize_envelope(envelope)
expect(data).to be_nil
expect(io.string).not_to match(/Sending envelope with items \[event\]/)
expect(io.string).to match(/tags: 2, contexts: 8208891, extra: 2/)
end
end
end
end
end

Expand Down
Loading