File tree 3 files changed +33
-2
lines changed
3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change
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
+
1
7
## 5.23.0
2
8
3
9
### Features
Original file line number Diff line number Diff line change 2
2
3
3
module Sentry
4
4
class Breadcrumb
5
+ MAX_NESTING = 5
5
6
DATA_SERIALIZATION_ERROR_MESSAGE = "[data were removed due to serialization issues]"
6
7
7
8
# @return [String, nil]
@@ -60,7 +61,7 @@ def level=(level) # needed to meet the Sentry spec
60
61
61
62
def serialized_data
62
63
begin
63
- ::JSON . parse ( ::JSON . generate ( @data ) )
64
+ ::JSON . parse ( ::JSON . generate ( @data , max_nesting : MAX_NESTING ) )
64
65
rescue Exception => e
65
66
Sentry . logger . debug ( LOGGER_PROGNAME ) do
66
67
<<~MSG
Original file line number Diff line number Diff line change 3
3
require "spec_helper"
4
4
5
5
RSpec . describe Sentry ::Breadcrumb do
6
+ let ( :stringio ) { StringIO . new }
7
+
6
8
before do
7
- perform_basic_setup
9
+ perform_basic_setup do |config |
10
+ config . logger = ::Logger . new ( stringio )
11
+ end
8
12
end
9
13
10
14
let ( :crumb ) do
71
75
)
72
76
end
73
77
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
+
74
88
it "serializes data correctly" do
75
89
result = crumb . to_hash
76
90
85
99
expect ( result [ :category ] ) . to eq ( "baz" )
86
100
expect ( result [ :message ] ) . to eq ( "I cause issues" )
87
101
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/ )
88
112
end
89
113
end
90
114
end
You can’t perform that action at this time.
0 commit comments