3838# Bytes are technically not strings in Python 3, but we can serialize them
3939serializable_str_types = (str , bytes , bytearray , memoryview )
4040
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
4641CYCLE_MARKER = "<cyclic>"
4742
4843
@@ -99,7 +94,6 @@ def serialize(event: Union[Dict[str, Any], Event], **kwargs: Any) -> Dict[str, A
9994 The algorithm itself is a recursive graph walk down the data structures it encounters.
10095
10196 It has the following responsibilities:
102- * Trimming databags and keeping them within MAX_DATABAG_BREADTH and MAX_DATABAG_DEPTH.
10397 * Calling safe_repr() on objects appropriately to keep them informative and readable in the final payload.
10498 * Annotating the payload with the _meta field whenever trimming happens.
10599
@@ -113,7 +107,6 @@ def serialize(event: Union[Dict[str, Any], Event], **kwargs: Any) -> Dict[str, A
113107 path : List [Segment ] = []
114108 meta_stack : List [Dict [str , Any ]] = []
115109
116- keep_request_bodies : bool = kwargs .pop ("max_request_body_size" , None ) == "always"
117110 max_value_length : Optional [int ] = kwargs .pop ("max_value_length" , None )
118111 is_vars = kwargs .pop ("is_vars" , False )
119112 custom_repr : Callable [..., Optional [str ]] = kwargs .pop ("custom_repr" , None )
@@ -179,11 +172,8 @@ def _is_request_body() -> Optional[bool]:
179172 def _serialize_node (
180173 obj : Any ,
181174 is_databag : Optional [bool ] = None ,
182- is_request_body : Optional [bool ] = None ,
183175 should_repr_strings : Optional [bool ] = None ,
184176 segment : Optional [Segment ] = None ,
185- remaining_breadth : Optional [Union [int , float ]] = None ,
186- remaining_depth : Optional [Union [int , float ]] = None ,
187177 ) -> Any :
188178 if segment is not None :
189179 path .append (segment )
@@ -196,10 +186,7 @@ def _serialize_node(
196186 return _serialize_node_impl (
197187 obj ,
198188 is_databag = is_databag ,
199- is_request_body = is_request_body ,
200189 should_repr_strings = should_repr_strings ,
201- remaining_depth = remaining_depth ,
202- remaining_breadth = remaining_breadth ,
203190 )
204191 except BaseException :
205192 capture_internal_exception (sys .exc_info ())
@@ -222,10 +209,7 @@ def _flatten_annotated(obj: Any) -> Any:
222209 def _serialize_node_impl (
223210 obj : Any ,
224211 is_databag : Optional [bool ],
225- is_request_body : Optional [bool ],
226212 should_repr_strings : Optional [bool ],
227- remaining_depth : Optional [Union [float , int ]],
228- remaining_breadth : Optional [Union [float , int ]],
229213 ) -> Any :
230214 if isinstance (obj , AnnotatedValue ):
231215 should_repr_strings = False
@@ -235,31 +219,10 @@ def _serialize_node_impl(
235219 if is_databag is None :
236220 is_databag = _is_databag ()
237221
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-
251222 obj = _flatten_annotated (obj )
252223
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-
261224 if is_databag and global_repr_processors :
262- hints = {"memo" : memo , "remaining_depth" : remaining_depth }
225+ hints = {"memo" : memo }
263226 for processor in global_repr_processors :
264227 result = processor (obj , hints )
265228 if result is not NotImplemented :
@@ -294,21 +257,12 @@ def _serialize_node_impl(
294257 i = 0
295258
296259 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-
301260 str_k = str (k )
302261 v = _serialize_node (
303262 v ,
304263 segment = str_k ,
305264 should_repr_strings = should_repr_strings ,
306265 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 ,
312266 )
313267 rv_dict [str_k ] = v
314268 i += 1
@@ -321,21 +275,12 @@ def _serialize_node_impl(
321275 rv_list = []
322276
323277 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-
328278 rv_list .append (
329279 _serialize_node (
330280 v ,
331281 segment = i ,
332282 should_repr_strings = should_repr_strings ,
333283 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 ,
339284 )
340285 )
341286
0 commit comments