|
353 | 353 | end |
354 | 354 | end |
355 | 355 | 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 |
429 | 356 | end |
430 | 357 | end |
431 | 358 |
|
|
0 commit comments