diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b30e3dee..f097be0d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## Unreleased + +### Bug Fixes + +- Also check stringified breadcrumbs key when reducing payload size [#1758](https://github.com/getsentry/sentry-ruby/pull/1758) + - Fixes [#1757](https://github.com/getsentry/sentry-ruby/issues/1757) + ## 5.2.0 ### Features diff --git a/sentry-ruby/lib/sentry/transport.rb b/sentry-ruby/lib/sentry/transport.rb index 8529e6db9..a63ff7c24 100644 --- a/sentry-ruby/lib/sentry/transport.rb +++ b/sentry-ruby/lib/sentry/transport.rb @@ -73,7 +73,12 @@ def serialize_envelope(envelope) result = item.to_s if result.bytesize > Event::MAX_SERIALIZED_PAYLOAD_SIZE - item.payload.delete(:breadcrumbs) + if item.payload.key?(:breadcrumbs) + item.payload.delete(:breadcrumbs) + elsif item.payload.key?("breadcrumbs") + item.payload.delete("breadcrumbs") + end + result = item.to_s end diff --git a/sentry-ruby/spec/sentry/transport_spec.rb b/sentry-ruby/spec/sentry/transport_spec.rb index 443f7b983..7b038fd7f 100644 --- a/sentry-ruby/spec/sentry/transport_spec.rb +++ b/sentry-ruby/spec/sentry/transport_spec.rb @@ -201,7 +201,7 @@ expect(serialized_result.bytesize).to be > Sentry::Event::MAX_SERIALIZED_PAYLOAD_SIZE end - it "sends the event and logs the action" do + it "deletes the event's breadcrumbs and sends it" do expect(subject).to receive(:send_data) subject.send_envelope(envelope) @@ -209,6 +209,18 @@ expect(io.string).to match(/Sending envelope with items \[event\]/) end + context "when the event hash has string keys" do + let(:envelope) { subject.envelope_from_event(event.to_json_compatible) } + + it "deletes the event's breadcrumbs and sends it" do + expect(subject).to receive(:send_data) + + subject.send_envelope(envelope) + + expect(io.string).to match(/Sending envelope with items \[event\]/) + end + end + context "if it's still oversized" do before do 100.times do |i|