Skip to content

Commit 0d46bd4

Browse files
committed
Remove databag trimming
1 parent 760aa90 commit 0d46bd4

File tree

4 files changed

+8
-84
lines changed

4 files changed

+8
-84
lines changed

sentry_sdk/integrations/pure_eval.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,5 @@ def start(n: ast.expr) -> Tuple[int, int]:
128128
atok = source.asttokens()
129129

130130
expressions.sort(key=closeness, reverse=True)
131-
vars = {
132-
atok.get_text(nodes[0]): value
133-
for nodes, value in expressions[: serializer.MAX_DATABAG_BREADTH]
134-
}
131+
vars = {atok.get_text(nodes[0]): value for nodes, value in expressions}
135132
return serializer.serialize(vars, is_vars=True)

sentry_sdk/serializer.py

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@
3838
# Bytes are technically not strings in Python 3, but we can serialize them
3939
serializable_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
4641
CYCLE_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

tests/test_client.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from sentry_sdk.utils import capture_internal_exception
2525
from sentry_sdk.integrations.executing import ExecutingIntegration
2626
from sentry_sdk.transport import Transport
27-
from sentry_sdk.serializer import MAX_DATABAG_BREADTH
2827
from sentry_sdk.consts import DEFAULT_MAX_BREADCRUMBS, DEFAULT_MAX_VALUE_LENGTH
2928

3029
from typing import TYPE_CHECKING
@@ -726,7 +725,7 @@ def inner():
726725
assert len(json.dumps(event)) < DEFAULT_MAX_VALUE_LENGTH * 10
727726

728727

729-
def test_databag_breadth_stripping(sentry_init, capture_events, benchmark):
728+
def test_databag_breadth_no_stripping(sentry_init, capture_events, benchmark):
730729
sentry_init()
731730
events = capture_events()
732731

@@ -743,9 +742,8 @@ def inner():
743742

744743
assert (
745744
len(event["exception"]["values"][0]["stacktrace"]["frames"][0]["vars"]["a"])
746-
== MAX_DATABAG_BREADTH
745+
== 1000000
747746
)
748-
assert len(json.dumps(event)) < 10000
749747

750748

751749
def test_chained_exceptions(sentry_init, capture_events):

tests/test_serializer.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
from sentry_sdk.consts import DEFAULT_MAX_VALUE_LENGTH
6-
from sentry_sdk.serializer import MAX_DATABAG_BREADTH, MAX_DATABAG_DEPTH, serialize
6+
from sentry_sdk.serializer import serialize
77

88
try:
99
from hypothesis import given
@@ -140,32 +140,16 @@ def custom_repr(value):
140140
assert "Foo object" in result["foo"]
141141

142142

143-
def test_trim_databag_breadth(body_normalizer):
144-
data = {
145-
"key{}".format(i): "value{}".format(i) for i in range(MAX_DATABAG_BREADTH + 10)
146-
}
143+
def test_dont_trim_databag_breadth(body_normalizer):
144+
data = {"key{}".format(i): "value{}".format(i) for i in range(10**9)}
147145

148146
result = body_normalizer(data)
149147

150-
assert len(result) == MAX_DATABAG_BREADTH
148+
assert len(result) == 10**9
151149
for key, value in result.items():
152150
assert data.get(key) == value
153151

154152

155-
def test_no_trimming_if_max_request_body_size_is_always(body_normalizer):
156-
data = {
157-
"key{}".format(i): "value{}".format(i) for i in range(MAX_DATABAG_BREADTH + 10)
158-
}
159-
curr = data
160-
for _ in range(MAX_DATABAG_DEPTH + 5):
161-
curr["nested"] = {}
162-
curr = curr["nested"]
163-
164-
result = body_normalizer(data, max_request_body_size="always")
165-
166-
assert result == data
167-
168-
169153
def test_max_value_length_default(body_normalizer):
170154
data = {"key": "a" * (DEFAULT_MAX_VALUE_LENGTH * 10)}
171155

0 commit comments

Comments
 (0)