|
326 | 326 | end |
327 | 327 | end |
328 | 328 | end |
| 329 | + |
| 330 | + context "due to stacktrace frames" do |
| 331 | + let(:event) { client.event_from_exception(SystemStackError.new("stack level too deep")) } |
| 332 | + let(:envelope) { subject.envelope_from_event(event) } |
| 333 | + |
| 334 | + let(:in_app_pattern) do |
| 335 | + project_root = "/fake/project_root" |
| 336 | + Regexp.new("^(#{project_root}/)?#{Sentry::Configuration::APP_DIRS_PATTERN}") |
| 337 | + end |
| 338 | + let(:frame_list_limit) { 1000 } |
| 339 | + let(:frame_list_size) { frame_list_limit * 20 } |
| 340 | + |
| 341 | + before do |
| 342 | + single_exception = event.exception.values[0] |
| 343 | + new_stacktrace = Sentry::StacktraceInterface.new( |
| 344 | + frames: frame_list_size.times.map do |zero_based_index| |
| 345 | + Sentry::StacktraceInterface::Frame.new( |
| 346 | + "/fake/path", |
| 347 | + Sentry::Backtrace::Line.parse("app.rb:#{zero_based_index + 1}:in `/'", in_app_pattern) |
| 348 | + ) |
| 349 | + end, |
| 350 | + ) |
| 351 | + single_exception.instance_variable_set(:@stacktrace, new_stacktrace) |
| 352 | + |
| 353 | + serialized_result = JSON.generate(event.to_h) |
| 354 | + expect(serialized_result.bytesize).to be > Sentry::Envelope::Item::MAX_SERIALIZED_PAYLOAD_SIZE |
| 355 | + end |
| 356 | + |
| 357 | + it "keeps some stacktrace frames and carry on" do |
| 358 | + data, _ = subject.serialize_envelope(envelope) |
| 359 | + expect(data.bytesize).to be < Sentry::Envelope::Item::MAX_SERIALIZED_PAYLOAD_SIZE |
| 360 | + |
| 361 | + expect(envelope.items.count).to eq(1) |
| 362 | + |
| 363 | + event_item = envelope.items.first |
| 364 | + frames = event_item.payload[:exception][:values][0][:stacktrace][:frames] |
| 365 | + expect(frames.length).to eq(frame_list_limit) |
| 366 | + |
| 367 | + # Last N lines kept |
| 368 | + # N = Frame limit / 2 |
| 369 | + expect(frames[-1][:lineno]).to eq(frame_list_size) |
| 370 | + expect(frames[-1][:filename]).to eq('app.rb') |
| 371 | + expect(frames[-1][:function]).to eq('/') |
| 372 | + # |
| 373 | + expect(frames[-(frame_list_limit / 2)][:lineno]).to eq(frame_list_size - ((frame_list_limit / 2) - 1)) |
| 374 | + expect(frames[-(frame_list_limit / 2)][:filename]).to eq('app.rb') |
| 375 | + expect(frames[-(frame_list_limit / 2)][:function]).to eq('/') |
| 376 | + |
| 377 | + # First N lines kept |
| 378 | + # N = Frame limit / 2 |
| 379 | + expect(frames[0][:lineno]).to eq(1) |
| 380 | + expect(frames[0][:filename]).to eq('app.rb') |
| 381 | + expect(frames[0][:function]).to eq('/') |
| 382 | + expect(frames[(frame_list_limit / 2) - 1][:lineno]).to eq(frame_list_limit / 2) |
| 383 | + expect(frames[(frame_list_limit / 2) - 1][:filename]).to eq('app.rb') |
| 384 | + expect(frames[(frame_list_limit / 2) - 1][:function]).to eq('/') |
| 385 | + end |
| 386 | + |
| 387 | + context "if it's still oversized" do |
| 388 | + before do |
| 389 | + 1000.times do |i| |
| 390 | + event.contexts["context_#{i}"] = "s" * Sentry::Event::MAX_MESSAGE_SIZE_IN_BYTES |
| 391 | + end |
| 392 | + end |
| 393 | + |
| 394 | + it "rejects the item and logs attributes size breakdown" do |
| 395 | + data, _ = subject.serialize_envelope(envelope) |
| 396 | + expect(data).to be_nil |
| 397 | + expect(io.string).not_to match(/Sending envelope with items \[event\]/) |
| 398 | + expect(io.string).to match(/tags: 2, contexts: 8208891, extra: 2/) |
| 399 | + end |
| 400 | + end |
| 401 | + end |
329 | 402 | end |
330 | 403 | end |
331 | 404 |
|
|
0 commit comments