Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 62bd21c

Browse files
committedMar 17, 2025·
Add max_nesting of 5 to breadcrumbs data serialization
This is [enforced in [relay](https://github.com/getsentry/relay/blob/bcbfa7e7db6e4a8f3f0383270fbb2b5cfe668770/relay-event-schema/src/protocol/breadcrumb.rs#L111) either way so this is not a behavioral change. Closes #2393 and #2397
1 parent cf3887b commit 62bd21c

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed
 

‎CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Unreleased
2+
3+
- Add `max_nesting` of 5 to breadcrumbs data serialization ([#2549](https://github.com/getsentry/sentry-ruby/pull/2549))
4+
5+
### Features
6+
17
## 5.23.0
28

39
### Features

‎sentry-ruby/lib/sentry/breadcrumb.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
module Sentry
44
class Breadcrumb
5+
MAX_NESTING = 5
56
DATA_SERIALIZATION_ERROR_MESSAGE = "[data were removed due to serialization issues]"
67

78
# @return [String, nil]
@@ -60,7 +61,7 @@ def level=(level) # needed to meet the Sentry spec
6061

6162
def serialized_data
6263
begin
63-
::JSON.parse(::JSON.generate(@data))
64+
::JSON.parse(::JSON.generate(@data, max_nesting: MAX_NESTING))
6465
rescue Exception => e
6566
Sentry.logger.debug(LOGGER_PROGNAME) do
6667
<<~MSG

‎sentry-ruby/spec/sentry/breadcrumb_spec.rb

+25-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
require "spec_helper"
44

55
RSpec.describe Sentry::Breadcrumb do
6+
let(:stringio) { StringIO.new }
7+
68
before do
7-
perform_basic_setup
9+
perform_basic_setup do |config|
10+
config.logger = ::Logger.new(stringio)
11+
end
812
end
913

1014
let(:crumb) do
@@ -71,6 +75,16 @@
7175
)
7276
end
7377

78+
let(:very_deep_crumb) do
79+
data = [[ { a: [{ b: [{ c: 4 }] }] }]]
80+
81+
Sentry::Breadcrumb.new(
82+
category: "cow",
83+
message: "I cause too much recursion",
84+
data: data
85+
)
86+
end
87+
7488
it "serializes data correctly" do
7589
result = crumb.to_hash
7690

@@ -85,6 +99,16 @@
8599
expect(result[:category]).to eq("baz")
86100
expect(result[:message]).to eq("I cause issues")
87101
expect(result[:data]).to eq("[data were removed due to serialization issues]")
102+
expect(stringio.string).to match(/can't serialize breadcrumb data because of error: nesting of 5 is too deep/)
103+
end
104+
105+
it "rescues data serialization issue for extremely nested data and ditch the data" do
106+
result = very_deep_crumb.to_hash
107+
108+
expect(result[:category]).to eq("cow")
109+
expect(result[:message]).to eq("I cause too much recursion")
110+
expect(result[:data]).to eq("[data were removed due to serialization issues]")
111+
expect(stringio.string).to match(/can't serialize breadcrumb data because of error: nesting of 5 is too deep/)
88112
end
89113
end
90114
end

0 commit comments

Comments
 (0)
Please sign in to comment.