38
38
# Bytes are technically not strings in Python 3, but we can serialize them
39
39
serializable_str_types = (str , bytes , bytearray , memoryview )
40
40
41
-
42
- # Maximum depth and breadth of databags. Excess data will be trimmed. If
43
- # max_request_body_size is "always", request bodies won't be trimmed.
44
- MAX_DATABAG_DEPTH = 5
45
- MAX_DATABAG_BREADTH = 10
46
41
CYCLE_MARKER = "<cyclic>"
47
42
48
43
@@ -99,7 +94,6 @@ def serialize(event: Union[Dict[str, Any], Event], **kwargs: Any) -> Dict[str, A
99
94
The algorithm itself is a recursive graph walk down the data structures it encounters.
100
95
101
96
It has the following responsibilities:
102
- * Trimming databags and keeping them within MAX_DATABAG_BREADTH and MAX_DATABAG_DEPTH.
103
97
* Calling safe_repr() on objects appropriately to keep them informative and readable in the final payload.
104
98
* Annotating the payload with the _meta field whenever trimming happens.
105
99
@@ -113,7 +107,6 @@ def serialize(event: Union[Dict[str, Any], Event], **kwargs: Any) -> Dict[str, A
113
107
path : List [Segment ] = []
114
108
meta_stack : List [Dict [str , Any ]] = []
115
109
116
- keep_request_bodies : bool = kwargs .pop ("max_request_body_size" , None ) == "always"
117
110
max_value_length : Optional [int ] = kwargs .pop ("max_value_length" , None )
118
111
is_vars = kwargs .pop ("is_vars" , False )
119
112
custom_repr : Callable [..., Optional [str ]] = kwargs .pop ("custom_repr" , None )
@@ -179,11 +172,8 @@ def _is_request_body() -> Optional[bool]:
179
172
def _serialize_node (
180
173
obj : Any ,
181
174
is_databag : Optional [bool ] = None ,
182
- is_request_body : Optional [bool ] = None ,
183
175
should_repr_strings : Optional [bool ] = None ,
184
176
segment : Optional [Segment ] = None ,
185
- remaining_breadth : Optional [Union [int , float ]] = None ,
186
- remaining_depth : Optional [Union [int , float ]] = None ,
187
177
) -> Any :
188
178
if segment is not None :
189
179
path .append (segment )
@@ -196,10 +186,7 @@ def _serialize_node(
196
186
return _serialize_node_impl (
197
187
obj ,
198
188
is_databag = is_databag ,
199
- is_request_body = is_request_body ,
200
189
should_repr_strings = should_repr_strings ,
201
- remaining_depth = remaining_depth ,
202
- remaining_breadth = remaining_breadth ,
203
190
)
204
191
except BaseException :
205
192
capture_internal_exception (sys .exc_info ())
@@ -222,10 +209,7 @@ def _flatten_annotated(obj: Any) -> Any:
222
209
def _serialize_node_impl (
223
210
obj : Any ,
224
211
is_databag : Optional [bool ],
225
- is_request_body : Optional [bool ],
226
212
should_repr_strings : Optional [bool ],
227
- remaining_depth : Optional [Union [float , int ]],
228
- remaining_breadth : Optional [Union [float , int ]],
229
213
) -> Any :
230
214
if isinstance (obj , AnnotatedValue ):
231
215
should_repr_strings = False
@@ -235,31 +219,10 @@ def _serialize_node_impl(
235
219
if is_databag is None :
236
220
is_databag = _is_databag ()
237
221
238
- if is_request_body is None :
239
- is_request_body = _is_request_body ()
240
-
241
- if is_databag :
242
- if is_request_body and keep_request_bodies :
243
- remaining_depth = float ("inf" )
244
- remaining_breadth = float ("inf" )
245
- else :
246
- if remaining_depth is None :
247
- remaining_depth = MAX_DATABAG_DEPTH
248
- if remaining_breadth is None :
249
- remaining_breadth = MAX_DATABAG_BREADTH
250
-
251
222
obj = _flatten_annotated (obj )
252
223
253
- if remaining_depth is not None and remaining_depth <= 0 :
254
- _annotate (rem = [["!limit" , "x" ]])
255
- if is_databag :
256
- return _flatten_annotated (
257
- strip_string (_safe_repr_wrapper (obj ), max_length = max_value_length )
258
- )
259
- return None
260
-
261
224
if is_databag and global_repr_processors :
262
- hints = {"memo" : memo , "remaining_depth" : remaining_depth }
225
+ hints = {"memo" : memo }
263
226
for processor in global_repr_processors :
264
227
result = processor (obj , hints )
265
228
if result is not NotImplemented :
@@ -294,21 +257,12 @@ def _serialize_node_impl(
294
257
i = 0
295
258
296
259
for k , v in obj .items ():
297
- if remaining_breadth is not None and i >= remaining_breadth :
298
- _annotate (len = len (obj ))
299
- break
300
-
301
260
str_k = str (k )
302
261
v = _serialize_node (
303
262
v ,
304
263
segment = str_k ,
305
264
should_repr_strings = should_repr_strings ,
306
265
is_databag = is_databag ,
307
- is_request_body = is_request_body ,
308
- remaining_depth = (
309
- remaining_depth - 1 if remaining_depth is not None else None
310
- ),
311
- remaining_breadth = remaining_breadth ,
312
266
)
313
267
rv_dict [str_k ] = v
314
268
i += 1
@@ -321,21 +275,12 @@ def _serialize_node_impl(
321
275
rv_list = []
322
276
323
277
for i , v in enumerate (obj ):
324
- if remaining_breadth is not None and i >= remaining_breadth :
325
- _annotate (len = len (obj ))
326
- break
327
-
328
278
rv_list .append (
329
279
_serialize_node (
330
280
v ,
331
281
segment = i ,
332
282
should_repr_strings = should_repr_strings ,
333
283
is_databag = is_databag ,
334
- is_request_body = is_request_body ,
335
- remaining_depth = (
336
- remaining_depth - 1 if remaining_depth is not None else None
337
- ),
338
- remaining_breadth = remaining_breadth ,
339
284
)
340
285
)
341
286
0 commit comments