You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sentry_sdk/serializer.py
+23-28Lines changed: 23 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -96,6 +96,24 @@ def __exit__(
96
96
97
97
defserialize(event, **kwargs):
98
98
# type: (Dict[str, Any], **Any) -> Dict[str, Any]
99
+
"""
100
+
A very smart serializer that takes a dict and emits a json-friendly dict.
101
+
Currently used for serializing the final Event and also prematurely while fetching the stack
102
+
local variables for each frame in a stacktrace.
103
+
104
+
It works internally with 'databags' which are arbitrary data structures like Mapping, Sequence and Set.
105
+
The algorithm itself is a recursive graph walk down the data structures it encounters.
106
+
107
+
It has the following responsibilities:
108
+
* Trimming databags and keeping them withing MAX_DATABAG_BREADTH and MAX_DATABAG_DEPTH.
109
+
* Calling safe_repr() on objects appropriately to keep them informative and readable in the final payload.
110
+
* Annotating the payload with the _meta field whenever trimming happens.
111
+
112
+
:param max_request_body_size: If set to "always", will never trim request bodies.
113
+
:param max_value_length: The max length to strip strings to, defaults to sentry_sdk.consts.DEFAULT_MAX_VALUE_LENGTH
114
+
:param is_vars: If we're serializing vars early, we want to repr() things that are JSON-serializable to make their type more apparent. For example, it's useful to see the difference between a unicode-string and a bytestring when viewing a stacktrace.
115
+
116
+
"""
99
117
memo=Memo()
100
118
path= [] # type: List[Segment]
101
119
meta_stack= [] # type: List[Dict[str, Any]]
@@ -119,40 +137,17 @@ def _annotate(**meta):
119
137
120
138
meta_stack[-1].setdefault("", {}).update(meta)
121
139
122
-
def_should_repr_strings():
123
-
# type: () -> Optional[bool]
124
-
"""
125
-
By default non-serializable objects are going through
126
-
safe_repr(). For certain places in the event (local vars) we
127
-
want to repr() even things that are JSON-serializable to
128
-
make their type more apparent. For example, it's useful to
129
-
see the difference between a unicode-string and a bytestring
130
-
when viewing a stacktrace.
131
-
132
-
For container-types we still don't do anything different.
133
-
Generally we just try to make the Sentry UI present exactly
134
-
what a pretty-printed repr would look like.
135
-
136
-
:returns: `True` if we are somewhere in frame variables, and `False` if
137
-
we are in a position where we will never encounter frame variables
138
-
when recursing (for example, we're in `event.extra`). `None` if we
139
-
are not (yet) in frame variables, but might encounter them when
140
-
recursing (e.g. we're in `event.exception`)
141
-
"""
142
-
returnis_vars
143
-
144
140
def_is_databag():
145
141
# type: () -> Optional[bool]
146
142
"""
147
143
A databag is any value that we need to trim.
144
+
True for stuff like vars, request bodies, breadcrumbs and extra.
148
145
149
-
:returns: Works like `_should_repr_strings()`. `True` for "yes",
150
-
`False` for :"no", `None` for "maybe soon".
146
+
:returns: `True` for "yes", `False` for :"no", `None` for "maybe soon".
0 commit comments