Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit breadcrumb's message length #1465

Merged
merged 2 commits into from
Jun 4, 2021
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Fixes the issue mentioned in this [comment](https://github.com/getsentry/sentry-ruby/pull/1199#issuecomment-773069840)
- Correct the timing of loading ActiveJobExtensions [#1464](https://github.com/getsentry/sentry-ruby/pull/1464)
- Fixes [#1249](https://github.com/getsentry/sentry-ruby/issues/1249)
- Limit breadcrumb's message length [#1465](https://github.com/getsentry/sentry-ruby/pull/1465)

## 4.5.0

Expand Down
9 changes: 7 additions & 2 deletions sentry-ruby/lib/sentry/breadcrumb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ module Sentry
class Breadcrumb
DATA_SERIALIZATION_ERROR_MESSAGE = "[data were removed due to serialization issues]"

attr_accessor :category, :data, :message, :level, :timestamp, :type
attr_accessor :category, :data, :level, :timestamp, :type
attr_reader :message

def initialize(category: nil, data: nil, message: nil, timestamp: nil, level: nil, type: nil)
@category = category
@data = data || {}
@level = level
@message = message
@timestamp = timestamp || Sentry.utc_now.to_i
@type = type
self.message = message
end

def to_hash
Expand All @@ -24,6 +25,10 @@ def to_hash
}
end

def message=(msg)
@message = (msg || "").byteslice(0..Event::MAX_MESSAGE_SIZE_IN_BYTES)
end

private

def serialized_data
Expand Down
19 changes: 19 additions & 0 deletions sentry-ruby/spec/sentry/breadcrumb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@
)
end

describe "#initialize" do
it "limits the maximum size of message" do
long_message = "a" * Sentry::Event::MAX_MESSAGE_SIZE_IN_BYTES * 2

crumb = described_class.new(message: long_message)
expect(crumb.message.length).to eq(Sentry::Event::MAX_MESSAGE_SIZE_IN_BYTES + 1)
end
end

describe "#message=" do
it "limits the maximum size of message" do
long_message = "a" * Sentry::Event::MAX_MESSAGE_SIZE_IN_BYTES * 2

crumb = described_class.new
crumb.message = long_message
expect(crumb.message.length).to eq(Sentry::Event::MAX_MESSAGE_SIZE_IN_BYTES + 1)
end
end

describe "#to_hash" do
it "serializes data correctly" do
result = crumb.to_hash
Expand Down