diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b3289f99..c592aea57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/sentry-ruby/lib/sentry/envelope/item.rb b/sentry-ruby/lib/sentry/envelope/item.rb index 864ad0239..010652435 100644 --- a/sentry-ruby/lib/sentry/envelope/item.rb +++ b/sentry-ruby/lib/sentry/envelope/item.rb @@ -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( @@ -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 @@ -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 diff --git a/sentry-ruby/spec/sentry/transport_spec.rb b/sentry-ruby/spec/sentry/transport_spec.rb index f71bf8719..85ac76a16 100644 --- a/sentry-ruby/spec/sentry/transport_spec.rb +++ b/sentry-ruby/spec/sentry/transport_spec.rb @@ -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