Skip to content

Commit ed7a2db

Browse files
authored
Remove stacktrace trimming from the SDK (#2714)
1 parent 6e39d31 commit ed7a2db

3 files changed

Lines changed: 1 addition & 95 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Migrate from to_hash to to_h ([#2351](https://github.com/getsentry/sentry-ruby/pull/2351))
77
- Add `before_send_check_in` for applying to `CheckInEvent` ([#2703](https://github.com/getsentry/sentry-ruby/pull/2703))
88
- Returning a hash from `before_send` and `before_send_transaction` is no longer supported and will drop the event.
9+
- Remove stacktrace trimming ([#2714](https://github.com/getsentry/sentry-ruby/pull/2714))
910

1011
### Internal
1112

sentry-ruby/lib/sentry/envelope/item.rb

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
module Sentry
44
# @api private
55
class Envelope::Item
6-
STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD = 500
76
MAX_SERIALIZED_PAYLOAD_SIZE = 1024 * 1000
87

98
SIZE_LIMITS = Hash.new(MAX_SERIALIZED_PAYLOAD_SIZE).update(
@@ -45,11 +44,6 @@ def serialize
4544
result = to_s
4645
end
4746

48-
if result.bytesize > size_limit
49-
reduce_stacktrace!
50-
result = to_s
51-
end
52-
5347
[result, result.bytesize > size_limit]
5448
end
5549

@@ -68,21 +62,5 @@ def remove_breadcrumbs!
6862
payload.delete("breadcrumbs")
6963
end
7064
end
71-
72-
def reduce_stacktrace!
73-
if exceptions = payload.dig(:exception, :values) || payload.dig("exception", "values")
74-
exceptions.each do |exception|
75-
# 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
76-
traces = exception.dig(:stacktrace, :frames) || exception.dig("stacktrace", "frames")
77-
78-
if traces && traces.size > STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD
79-
size_on_both_ends = STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD / 2
80-
traces.replace(
81-
traces[0..(size_on_both_ends - 1)] + traces[-size_on_both_ends..-1],
82-
)
83-
end
84-
end
85-
end
86-
end
8765
end
8866
end

sentry-ruby/spec/sentry/transport_spec.rb

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -353,79 +353,6 @@
353353
end
354354
end
355355
end
356-
357-
context "due to stacktrace frames" do
358-
let(:event) { client.event_from_exception(SystemStackError.new("stack level too deep")) }
359-
let(:envelope) { subject.envelope_from_event(event) }
360-
361-
let(:in_app_pattern) do
362-
project_root = "/fake/project_root"
363-
Regexp.new("^(#{project_root}/)?#{Sentry::Configuration::APP_DIRS_PATTERN}")
364-
end
365-
let(:frame_list_limit) { 500 }
366-
let(:frame_list_size) { frame_list_limit * 20 }
367-
368-
before do
369-
single_exception = event.exception.values[0]
370-
new_stacktrace = Sentry::StacktraceInterface.new(
371-
frames: frame_list_size.times.map do |zero_based_index|
372-
Sentry::StacktraceInterface::Frame.new(
373-
"/fake/path",
374-
Sentry::Backtrace::Line.parse("app.rb:#{zero_based_index + 1}:in `/'", in_app_pattern)
375-
)
376-
end,
377-
)
378-
single_exception.instance_variable_set(:@stacktrace, new_stacktrace)
379-
380-
serialized_result = JSON.generate(event.to_h)
381-
expect(serialized_result.bytesize).to be > Sentry::Envelope::Item::MAX_SERIALIZED_PAYLOAD_SIZE
382-
end
383-
384-
it "keeps some stacktrace frames and carry on" do
385-
data, _ = subject.serialize_envelope(envelope)
386-
expect(data.bytesize).to be < Sentry::Envelope::Item::MAX_SERIALIZED_PAYLOAD_SIZE
387-
388-
expect(envelope.items.count).to eq(1)
389-
390-
event_item = envelope.items.first
391-
frames = event_item.payload[:exception][:values][0][:stacktrace][:frames]
392-
expect(frames.length).to eq(frame_list_limit)
393-
394-
# Last N lines kept
395-
# N = Frame limit / 2
396-
expect(frames[-1][:lineno]).to eq(frame_list_size)
397-
expect(frames[-1][:filename]).to eq('app.rb')
398-
expect(frames[-1][:function]).to eq('/')
399-
#
400-
expect(frames[-(frame_list_limit / 2)][:lineno]).to eq(frame_list_size - ((frame_list_limit / 2) - 1))
401-
expect(frames[-(frame_list_limit / 2)][:filename]).to eq('app.rb')
402-
expect(frames[-(frame_list_limit / 2)][:function]).to eq('/')
403-
404-
# First N lines kept
405-
# N = Frame limit / 2
406-
expect(frames[0][:lineno]).to eq(1)
407-
expect(frames[0][:filename]).to eq('app.rb')
408-
expect(frames[0][:function]).to eq('/')
409-
expect(frames[(frame_list_limit / 2) - 1][:lineno]).to eq(frame_list_limit / 2)
410-
expect(frames[(frame_list_limit / 2) - 1][:filename]).to eq('app.rb')
411-
expect(frames[(frame_list_limit / 2) - 1][:function]).to eq('/')
412-
end
413-
414-
context "if it's still oversized" do
415-
before do
416-
1000.times do |i|
417-
event.contexts["context_#{i}"] = "s" * Sentry::Event::MAX_MESSAGE_SIZE_IN_BYTES
418-
end
419-
end
420-
421-
it "rejects the item and logs attributes size breakdown" do
422-
data, _ = subject.serialize_envelope(envelope)
423-
expect(data).to be_nil
424-
expect(io.string).not_to match(/Sending envelope with items \[event\]/)
425-
expect(io.string).to match(/tags: 2, contexts: 8208891, extra: 2/)
426-
end
427-
end
428-
end
429356
end
430357
end
431358

0 commit comments

Comments
 (0)