Skip to content

Commit

Permalink
Add custom size limit for profile items
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Sep 30, 2024
1 parent 8964c60 commit 51c18b9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sentry-ruby/lib/sentry/envelope/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ class Envelope::Item
STACKTRACE_FRAME_LIMIT_ON_OVERSIZED_PAYLOAD = 500
MAX_SERIALIZED_PAYLOAD_SIZE = 1024 * 1000

SIZE_LIMITS = Hash.new(MAX_SERIALIZED_PAYLOAD_SIZE).update(
"profile" => 1024 * 1000 * 10
)

attr_reader :size_limit, :headers, :payload, :type, :data_category

# rate limits and client reports use the data_category rather than envelope item type
Expand All @@ -24,9 +28,9 @@ def self.data_category(type)
def initialize(headers, payload)
@headers = headers
@payload = payload
@size_limit = MAX_SERIALIZED_PAYLOAD_SIZE
@type = headers[:type] || "event"
@data_category = self.class.data_category(type)
@size_limit = SIZE_LIMITS[type]

Check warning on line 33 in sentry-ruby/lib/sentry/envelope/item.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/envelope/item.rb#L29-L33

Added lines #L29 - L33 were not covered by tests
end

def to_s
Expand Down
31 changes: 31 additions & 0 deletions sentry-ruby/spec/sentry/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,37 @@
expect(profile_payload).to eq(profile.to_json)
end
end

context "allows bigger item size" do
let(:profile) do
{
environment: "test",
release: "release",
profile: {
frames: Array.new(10000) { |i| { function: "function_#{i}", filename: "file_#{i}", lineno: i } },
stacks: Array.new(10000) { |i| [i] },
samples: Array.new(10000) { |i| { stack_id: i, elapsed_since_start_ns: i * 1000, thread_id: i % 10 } }
}
}
end

let(:event_with_profile) do
event.profile = profile
event
end

let(:envelope) { subject.envelope_from_event(event_with_profile) }

it "adds profile item to envelope" do
result, _ = subject.serialize_envelope(envelope)

profile_header, profile_payload_json = result.split("\n").last(2)

profile_payload = JSON.parse(profile_payload_json)

expect(profile_payload["profile"]).to_not be(nil)
end
end
end

context "client report" do
Expand Down

0 comments on commit 51c18b9

Please sign in to comment.