Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion sentry-ruby/lib/sentry/transport.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "json"
require "concurrent/map"
require "sentry/envelope"

module Sentry
Expand Down Expand Up @@ -76,7 +77,8 @@ def serialize_envelope(envelope)
result, oversized = item.serialize

if oversized
log_debug("Envelope item [#{item.type}] is still oversized after size reduction: {#{item.size_breakdown}}")
log_oversized_item(item)
record_lost_event(:send_error, item.data_category, num: item.item_count, num_bytes: item.lost_event_byte_size)

next
end
Expand Down Expand Up @@ -190,6 +192,20 @@ def flush

private

# Warns once per item type, then logs at debug level, so an app that keeps
# producing oversized items doesn't flood its logs. Every drop is still
# recorded as a lost event.
def log_oversized_item(item)
message = "Envelope item [#{item.type}] is still oversized after size reduction: {#{item.size_breakdown}}"
@oversized_item_types_warned ||= Concurrent::Map.new

if @oversized_item_types_warned.put_if_absent(item.type, true).nil?
log_warn("#{message}. Further oversized [#{item.type}] items are dropped with a debug log only.")
else
log_debug(message)
end
end

def fetch_pending_client_report(force: false)
return nil unless @send_client_reports
return nil if !force && @last_client_report_sent > Time.now - CLIENT_REPORT_INTERVAL
Expand Down
16 changes: 16 additions & 0 deletions sentry-ruby/spec/sentry/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,22 @@
expect(io.string).not_to match(/Sending envelope with items \[event\]/)
end

it "records the dropped event as lost and logs a warning" do
subject.send_envelope(envelope)

expect(subject.discarded_events[[:send_error, "error"]]).to eq(1)
expect(io.string).to match(/WARN -- sentry: Envelope item \[event\] is still oversized after size reduction/)
end

it "warns only once per item type but records every drop" do
subject.send_envelope(envelope)
subject.send_envelope(subject.envelope_from_event(event))

expect(subject.discarded_events[[:send_error, "error"]]).to eq(2)
expect(io.string.scan(/WARN -- sentry: Envelope item \[event\] is still oversized/).size).to eq(1)
expect(io.string.scan(/DEBUG -- sentry: Envelope item \[event\] is still oversized/).size).to eq(1)
end

context "with other types of items" do
before do
5.times { subject.record_lost_event(:ratelimit_backoff, 'error') }
Expand Down
Loading