-
Notifications
You must be signed in to change notification settings - Fork 548
Do not truncate body if request_bodies
is "always"
#2092
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,8 @@ | |
# this value due to attached metadata, so keep the number conservative. | ||
MAX_EVENT_BYTES = 10**6 | ||
|
||
# Maximum depth and breadth of databags. Excess data will be trimmed. If | ||
# request_bodies is "always", request bodies won't be trimmed. | ||
MAX_DATABAG_DEPTH = 5 | ||
MAX_DATABAG_BREADTH = 10 | ||
CYCLE_MARKER = "<cyclic>" | ||
|
@@ -118,6 +120,8 @@ def serialize(event, **kwargs): | |
path = [] # type: List[Segment] | ||
meta_stack = [] # type: List[Dict[str, Any]] | ||
|
||
keep_request_bodies = kwargs.pop("request_bodies", None) == "always" # type: bool | ||
|
||
def _annotate(**meta): | ||
# type: (**Any) -> None | ||
while len(meta_stack) <= len(path): | ||
|
@@ -182,10 +186,11 @@ def _is_databag(): | |
if rv in (True, None): | ||
return rv | ||
|
||
p0 = path[0] | ||
if p0 == "request" and path[1] == "data": | ||
return True | ||
is_request_body = _is_request_body() | ||
if is_request_body in (True, None): | ||
return is_request_body | ||
|
||
p0 = path[0] | ||
if p0 == "breadcrumbs" and path[1] == "values": | ||
path[2] | ||
return True | ||
|
@@ -198,13 +203,24 @@ def _is_databag(): | |
|
||
return False | ||
|
||
def _is_request_body(): | ||
# type: () -> Optional[bool] | ||
try: | ||
if path[0] == "request" and path[1] == "data": | ||
return True | ||
except IndexError: | ||
return None | ||
|
||
return False | ||
|
||
def _serialize_node( | ||
obj, # type: Any | ||
is_databag=None, # type: Optional[bool] | ||
is_request_body=None, # type: Optional[bool] | ||
should_repr_strings=None, # type: Optional[bool] | ||
segment=None, # type: Optional[Segment] | ||
remaining_breadth=None, # type: Optional[int] | ||
remaining_depth=None, # type: Optional[int] | ||
remaining_breadth=None, # type: Optional[Union[int, float]] | ||
remaining_depth=None, # type: Optional[Union[int, float]] | ||
): | ||
# type: (...) -> Any | ||
if segment is not None: | ||
|
@@ -218,6 +234,7 @@ def _serialize_node( | |
return _serialize_node_impl( | ||
obj, | ||
is_databag=is_databag, | ||
is_request_body=is_request_body, | ||
should_repr_strings=should_repr_strings, | ||
remaining_depth=remaining_depth, | ||
remaining_breadth=remaining_breadth, | ||
|
@@ -242,9 +259,14 @@ def _flatten_annotated(obj): | |
return obj | ||
|
||
def _serialize_node_impl( | ||
obj, is_databag, should_repr_strings, remaining_depth, remaining_breadth | ||
obj, | ||
is_databag, | ||
is_request_body, | ||
should_repr_strings, | ||
remaining_depth, | ||
remaining_breadth, | ||
): | ||
# type: (Any, Optional[bool], Optional[bool], Optional[int], Optional[int]) -> Any | ||
# type: (Any, Optional[bool], Optional[bool], Optional[bool], Optional[Union[float, int]], Optional[Union[float, int]]) -> Any | ||
if isinstance(obj, AnnotatedValue): | ||
should_repr_strings = False | ||
if should_repr_strings is None: | ||
|
@@ -253,10 +275,18 @@ def _serialize_node_impl( | |
if is_databag is None: | ||
is_databag = _is_databag() | ||
|
||
if is_databag and remaining_depth is None: | ||
remaining_depth = MAX_DATABAG_DEPTH | ||
if is_databag and remaining_breadth is None: | ||
remaining_breadth = MAX_DATABAG_BREADTH | ||
if is_request_body is None: | ||
is_request_body = _is_request_body() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this needed? not sure if it ever is true if it's already not true above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea was to distinguish between something being a request body vs. any other type of databag. Basically so that if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes that I get, but I wasn't able to see where this code branch is triggered. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah, thanks for spotting that |
||
|
||
if is_databag: | ||
if is_request_body and keep_request_bodies: | ||
remaining_depth = float("inf") | ||
remaining_breadth = float("inf") | ||
else: | ||
if remaining_depth is None: | ||
remaining_depth = MAX_DATABAG_DEPTH | ||
if remaining_breadth is None: | ||
remaining_breadth = MAX_DATABAG_BREADTH | ||
|
||
obj = _flatten_annotated(obj) | ||
|
||
|
@@ -312,6 +342,7 @@ def _serialize_node_impl( | |
segment=str_k, | ||
should_repr_strings=should_repr_strings, | ||
is_databag=is_databag, | ||
is_request_body=is_request_body, | ||
remaining_depth=remaining_depth - 1 | ||
if remaining_depth is not None | ||
else None, | ||
|
@@ -338,6 +369,7 @@ def _serialize_node_impl( | |
segment=i, | ||
should_repr_strings=should_repr_strings, | ||
is_databag=is_databag, | ||
is_request_body=is_request_body, | ||
remaining_depth=remaining_depth - 1 | ||
if remaining_depth is not None | ||
else None, | ||
|
Uh oh!
There was an error while loading. Please reload this page.