|
100 | 100 | end |
101 | 101 |
|
102 | 102 | context "oversized event" do |
103 | | - let(:event) { client.event_from_message("foo") } |
104 | | - let(:envelope) { subject.envelope_from_event(event) } |
| 103 | + context "due to breadcrumb" do |
| 104 | + let(:event) { client.event_from_message("foo") } |
| 105 | + let(:envelope) { subject.envelope_from_event(event) } |
105 | 106 |
|
106 | | - before do |
107 | | - event.breadcrumbs = Sentry::BreadcrumbBuffer.new(100) |
108 | | - 100.times do |i| |
109 | | - event.breadcrumbs.record Sentry::Breadcrumb.new(category: i.to_s, message: "x" * Sentry::Event::MAX_MESSAGE_SIZE_IN_BYTES) |
| 107 | + before do |
| 108 | + event.breadcrumbs = Sentry::BreadcrumbBuffer.new(100) |
| 109 | + 100.times do |i| |
| 110 | + event.breadcrumbs.record Sentry::Breadcrumb.new(category: i.to_s, message: "x" * Sentry::Event::MAX_MESSAGE_SIZE_IN_BYTES) |
| 111 | + end |
| 112 | + serialized_result = JSON.generate(event.to_hash) |
| 113 | + expect(serialized_result.bytesize).to be > Sentry::Event::MAX_SERIALIZED_PAYLOAD_SIZE |
110 | 114 | end |
111 | | - serialized_result = JSON.generate(event.to_hash) |
112 | | - expect(serialized_result.bytesize).to be > Sentry::Event::MAX_SERIALIZED_PAYLOAD_SIZE |
113 | | - end |
114 | 115 |
|
115 | | - it "removes breadcrumbs and carry on" do |
116 | | - data, _ = subject.serialize_envelope(envelope) |
117 | | - expect(data.bytesize).to be < Sentry::Event::MAX_SERIALIZED_PAYLOAD_SIZE |
| 116 | + it "removes breadcrumbs and carry on" do |
| 117 | + data, _ = subject.serialize_envelope(envelope) |
| 118 | + expect(data.bytesize).to be < Sentry::Event::MAX_SERIALIZED_PAYLOAD_SIZE |
| 119 | + |
| 120 | + expect(envelope.items.count).to eq(1) |
| 121 | + |
| 122 | + event_item = envelope.items.first |
| 123 | + expect(event_item.payload[:breadcrumbs]).to be_nil |
| 124 | + end |
118 | 125 |
|
119 | | - expect(envelope.items.count).to eq(1) |
| 126 | + context "if it's still oversized" do |
| 127 | + before do |
| 128 | + 100.times do |i| |
| 129 | + event.contexts["context_#{i}"] = "s" * Sentry::Event::MAX_MESSAGE_SIZE_IN_BYTES |
| 130 | + end |
| 131 | + end |
120 | 132 |
|
121 | | - event_item = envelope.items.first |
122 | | - expect(event_item.payload[:breadcrumbs]).to be_nil |
| 133 | + it "rejects the item and logs attributes size breakdown" do |
| 134 | + data, _ = subject.serialize_envelope(envelope) |
| 135 | + expect(data).to be_nil |
| 136 | + expect(io.string).not_to match(/Sending envelope with items \[event\]/) |
| 137 | + expect(io.string).to match(/tags: 2, contexts: 820791, extra: 2/) |
| 138 | + end |
| 139 | + end |
123 | 140 | end |
124 | 141 |
|
125 | | - context "if it's still oversized" do |
| 142 | + context "due to stacktrace frames" do |
| 143 | + let(:event) { client.event_from_exception(SystemStackError.new("stack level too deep")) } |
| 144 | + let(:envelope) { subject.envelope_from_event(event) } |
| 145 | + |
| 146 | + let(:in_app_pattern) do |
| 147 | + project_root = "/fake/project_root" |
| 148 | + Regexp.new("^(#{project_root}/)?#{Sentry::Backtrace::APP_DIRS_PATTERN}") |
| 149 | + end |
| 150 | + let(:frame_list_limit) { Sentry::Transport::STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD } |
| 151 | + let(:frame_list_size) { frame_list_limit * 4 } |
| 152 | + |
126 | 153 | before do |
127 | | - 100.times do |i| |
128 | | - event.contexts["context_#{i}"] = "s" * Sentry::Event::MAX_MESSAGE_SIZE_IN_BYTES |
129 | | - end |
| 154 | + single_exception = event.exception.instance_variable_get(:@values)[0] |
| 155 | + new_stacktrace = Sentry::StacktraceInterface.new( |
| 156 | + frames: frame_list_size.times.map do |zero_based_index| |
| 157 | + Sentry::StacktraceInterface::Frame.new( |
| 158 | + "/fake/path", |
| 159 | + Sentry::Backtrace::Line.parse("app.rb:#{zero_based_index + 1}:in `/'", in_app_pattern) |
| 160 | + ) |
| 161 | + end, |
| 162 | + ) |
| 163 | + single_exception.instance_variable_set(:@stacktrace, new_stacktrace) |
| 164 | + |
| 165 | + serialized_result = JSON.generate(event.to_hash) |
| 166 | + expect(serialized_result.bytesize).to be > Sentry::Event::MAX_SERIALIZED_PAYLOAD_SIZE |
130 | 167 | end |
131 | 168 |
|
132 | | - it "rejects the item and logs attributes size breakdown" do |
| 169 | + it "keeps some stacktrace frames and carry on" do |
133 | 170 | data, _ = subject.serialize_envelope(envelope) |
134 | | - expect(data).to be_nil |
135 | | - expect(io.string).not_to match(/Sending envelope with items \[event\]/) |
136 | | - expect(io.string).to match(/tags: 2, contexts: 820791, extra: 2/) |
| 171 | + expect(data.bytesize).to be < Sentry::Event::MAX_SERIALIZED_PAYLOAD_SIZE |
| 172 | + |
| 173 | + expect(envelope.items.count).to eq(1) |
| 174 | + |
| 175 | + event_item = envelope.items.first |
| 176 | + frames = event_item.payload[:exception][:values][0][:stacktrace][:frames] |
| 177 | + expect(frames.length).to eq(frame_list_limit) |
| 178 | + |
| 179 | + # Last N lines kept |
| 180 | + # N = Frame limit / 2 |
| 181 | + expect(frames[-1][:lineno]).to eq(frame_list_size) |
| 182 | + expect(frames[-1][:filename]).to eq('app.rb') |
| 183 | + expect(frames[-1][:function]).to eq('/') |
| 184 | + # |
| 185 | + expect(frames[-(frame_list_limit / 2)][:lineno]).to eq(frame_list_size - ((frame_list_limit / 2) - 1)) |
| 186 | + expect(frames[-(frame_list_limit / 2)][:filename]).to eq('app.rb') |
| 187 | + expect(frames[-(frame_list_limit / 2)][:function]).to eq('/') |
| 188 | + |
| 189 | + # First N lines kept |
| 190 | + # N = Frame limit / 2 |
| 191 | + expect(frames[0][:lineno]).to eq(1) |
| 192 | + expect(frames[0][:filename]).to eq('app.rb') |
| 193 | + expect(frames[0][:function]).to eq('/') |
| 194 | + expect(frames[(frame_list_limit / 2) - 1][:lineno]).to eq(frame_list_limit / 2) |
| 195 | + expect(frames[(frame_list_limit / 2) - 1][:filename]).to eq('app.rb') |
| 196 | + expect(frames[(frame_list_limit / 2) - 1][:function]).to eq('/') |
| 197 | + end |
| 198 | + |
| 199 | + context "if it's still oversized" do |
| 200 | + before do |
| 201 | + 100.times do |i| |
| 202 | + event.contexts["context_#{i}"] = "s" * Sentry::Event::MAX_MESSAGE_SIZE_IN_BYTES |
| 203 | + end |
| 204 | + end |
| 205 | + |
| 206 | + it "rejects the item and logs attributes size breakdown" do |
| 207 | + data, _ = subject.serialize_envelope(envelope) |
| 208 | + expect(data).to be_nil |
| 209 | + expect(io.string).not_to match(/Sending envelope with items \[event\]/) |
| 210 | + expect(io.string).to match(/tags: 2, contexts: 820791, extra: 2/) |
| 211 | + end |
137 | 212 | end |
138 | 213 | end |
139 | 214 | end |
|
0 commit comments