Skip to content

Commit 4ebc62f

Browse files
committed
.
1 parent 0d46bd4 commit 4ebc62f

File tree

10 files changed

+31
-40
lines changed

10 files changed

+31
-40
lines changed

MIGRATION_GUIDE.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
1919
- The `Span()` constructor does not accept a `hub` parameter anymore.
2020
- The `sentry_sdk.Scope()` constructor no longer accepts a `client` parameter.
2121
- `Span.finish()` does not accept a `hub` parameter anymore.
22-
- `Span.finish()` no longer returns the `event_id` if the event is sent to sentry.
22+
- `Span.finish()` no longer returns the `event_id` if the event is sent to Sentry.
23+
- We trim events to a much lesser extent in the SDK. Note that your events might still be subject to server-side trimming.
24+
- The default value of `max_request_body_size` was changed to `"always"`, so request bodies will now be included in events by default, regardless of size.
2325
- The `Profile()` constructor does not accept a `hub` parameter anymore.
2426
- A `Profile` object does not have a `.hub` property anymore.
2527
- `MAX_PROFILE_DURATION_NS`, `PROFILE_MINIMUM_SAMPLES`, `Profile`, `Scheduler`, `ThreadScheduler`, `GeventScheduler`, `has_profiling_enabled`, `setup_profiler`, `teardown_profiler` are no longer accessible from `sentry_sdk.profiler`. They're still accessible from `sentry_sdk.profiler.transaction_profiler`.

sentry_sdk/client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,6 @@ def _prepare_event(
547547
if event is not None:
548548
event: Event = serialize( # type: ignore[no-redef]
549549
event,
550-
max_request_body_size=self.options.get("max_request_body_size"),
551550
max_value_length=self.options.get("max_value_length"),
552551
custom_repr=self.options.get("custom_repr"),
553552
)

sentry_sdk/consts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ def __init__(
812812
http_proxy: Optional[str] = None,
813813
https_proxy: Optional[str] = None,
814814
ignore_errors: Sequence[Union[type, str]] = [], # noqa: B006
815-
max_request_body_size: str = "medium",
815+
max_request_body_size: str = "always",
816816
socket_options: Optional[List[Tuple[int, int, int | bytes]]] = None,
817817
keep_alive: Optional[bool] = None,
818818
before_send: Optional[EventProcessor] = None,

sentry_sdk/serializer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ def serialize(event: Union[Dict[str, Any], Event], **kwargs: Any) -> Dict[str, A
9797
* Calling safe_repr() on objects appropriately to keep them informative and readable in the final payload.
9898
* Annotating the payload with the _meta field whenever trimming happens.
9999
100-
:param max_request_body_size: If set to "always", will never trim request bodies.
101100
:param max_value_length: The max length to strip strings to, defaults to sentry_sdk.consts.DEFAULT_MAX_VALUE_LENGTH
102101
: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.
103102
:param custom_repr: A custom repr function that runs before safe_repr on the object to be serialized. If it returns None or throws internally, we will fallback to safe_repr.

tests/integrations/bottle/test_bottle.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from sentry_sdk import capture_message
88
from sentry_sdk.consts import DEFAULT_MAX_VALUE_LENGTH
99
from sentry_sdk.integrations.bottle import BottleIntegration
10-
from sentry_sdk.serializer import MAX_DATABAG_BREADTH
1110

1211
from sentry_sdk.integrations.logging import LoggingIntegration
1312
from werkzeug.test import Client
@@ -122,7 +121,7 @@ def index():
122121

123122

124123
def test_large_json_request(sentry_init, capture_events, app, get_client):
125-
sentry_init(integrations=[BottleIntegration()], max_request_body_size="always")
124+
sentry_init(integrations=[BottleIntegration()])
126125

127126
data = {"foo": {"bar": "a" * (DEFAULT_MAX_VALUE_LENGTH + 10)}}
128127

@@ -180,7 +179,7 @@ def index():
180179

181180

182181
def test_medium_formdata_request(sentry_init, capture_events, app, get_client):
183-
sentry_init(integrations=[BottleIntegration()], max_request_body_size="always")
182+
sentry_init(integrations=[BottleIntegration()])
184183

185184
data = {"foo": "a" * (DEFAULT_MAX_VALUE_LENGTH + 10)}
186185

@@ -242,7 +241,7 @@ def index():
242241

243242

244243
def test_files_and_form(sentry_init, capture_events, app, get_client):
245-
sentry_init(integrations=[BottleIntegration()], max_request_body_size="always")
244+
sentry_init(integrations=[BottleIntegration()])
246245

247246
data = {
248247
"foo": "a" * (DEFAULT_MAX_VALUE_LENGTH + 10),
@@ -287,11 +286,9 @@ def index():
287286
def test_json_not_truncated_if_max_request_body_size_is_always(
288287
sentry_init, capture_events, app, get_client
289288
):
290-
sentry_init(integrations=[BottleIntegration()], max_request_body_size="always")
289+
sentry_init(integrations=[BottleIntegration()])
291290

292-
data = {
293-
"key{}".format(i): "value{}".format(i) for i in range(MAX_DATABAG_BREADTH + 10)
294-
}
291+
data = {"key{}".format(i): "value{}".format(i) for i in range(10**5)}
295292

296293
@app.route("/", method="POST")
297294
def index():

tests/integrations/falcon/test_falcon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def on_get(self, req, resp):
208208

209209

210210
def test_falcon_large_json_request(sentry_init, capture_events):
211-
sentry_init(integrations=[FalconIntegration()], max_request_body_size="always")
211+
sentry_init(integrations=[FalconIntegration()])
212212

213213
data = {"foo": {"bar": "a" * (DEFAULT_MAX_VALUE_LENGTH + 10)}}
214214

tests/integrations/flask/test_flask.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
)
3030
from sentry_sdk.consts import DEFAULT_MAX_VALUE_LENGTH
3131
from sentry_sdk.integrations.logging import LoggingIntegration
32-
from sentry_sdk.serializer import MAX_DATABAG_BREADTH
3332

3433

3534
login_manager = LoginManager()
@@ -249,9 +248,7 @@ def login():
249248

250249

251250
def test_flask_large_json_request(sentry_init, capture_events, app):
252-
sentry_init(
253-
integrations=[flask_sentry.FlaskIntegration()], max_request_body_size="always"
254-
)
251+
sentry_init(integrations=[flask_sentry.FlaskIntegration()])
255252

256253
data = {"foo": {"bar": "a" * (DEFAULT_MAX_VALUE_LENGTH + 10)}}
257254

@@ -344,9 +341,7 @@ def index():
344341

345342

346343
def test_flask_medium_formdata_request(sentry_init, capture_events, app):
347-
sentry_init(
348-
integrations=[flask_sentry.FlaskIntegration()], max_request_body_size="always"
349-
)
344+
sentry_init(integrations=[flask_sentry.FlaskIntegration()])
350345

351346
data = {"foo": "a" * (DEFAULT_MAX_VALUE_LENGTH + 10)}
352347

@@ -452,9 +447,7 @@ def index():
452447

453448

454449
def test_flask_files_and_form(sentry_init, capture_events, app):
455-
sentry_init(
456-
integrations=[flask_sentry.FlaskIntegration()], max_request_body_size="always"
457-
)
450+
sentry_init(integrations=[flask_sentry.FlaskIntegration()])
458451

459452
data = {
460453
"foo": "a" * (DEFAULT_MAX_VALUE_LENGTH + 10),
@@ -497,13 +490,9 @@ def index():
497490
def test_json_not_truncated_if_max_request_body_size_is_always(
498491
sentry_init, capture_events, app
499492
):
500-
sentry_init(
501-
integrations=[flask_sentry.FlaskIntegration()], max_request_body_size="always"
502-
)
493+
sentry_init(integrations=[flask_sentry.FlaskIntegration()])
503494

504-
data = {
505-
"key{}".format(i): "value{}".format(i) for i in range(MAX_DATABAG_BREADTH + 10)
506-
}
495+
data = {"key{}".format(i): "value{}".format(i) for i in range(10**5)}
507496

508497
@app.route("/", methods=["POST"])
509498
def index():

tests/integrations/pure_eval/test_pure_eval.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from sentry_sdk import capture_exception, serializer
5+
from sentry_sdk import capture_exception
66
from sentry_sdk.integrations.pure_eval import PureEvalIntegration
77

88

@@ -62,6 +62,14 @@ def foo():
6262
"i",
6363
"u",
6464
"y",
65+
"t",
66+
"r",
67+
"e",
68+
"w",
69+
"q",
70+
"(q, w, e, r, t, y, u, i, o, p, a, s)",
71+
"str((q, w, e, r, t, y, u, i, o, p, a, s))",
72+
"events",
6573
]
6674
assert list(frame_vars.keys()) == expected_keys
6775
assert frame_vars["namespace.d"] == {"1": "2"}
@@ -85,4 +93,4 @@ def foo():
8593
"s",
8694
"events",
8795
}
88-
assert len(frame_vars) == serializer.MAX_DATABAG_BREADTH
96+
assert len(frame_vars) == 14

tests/integrations/pyramid/test_pyramid.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from sentry_sdk import capture_message, add_breadcrumb
1212
from sentry_sdk.consts import DEFAULT_MAX_VALUE_LENGTH
1313
from sentry_sdk.integrations.pyramid import PyramidIntegration
14-
from sentry_sdk.serializer import MAX_DATABAG_BREADTH
1514
from tests.conftest import unpack_werkzeug_response
1615

1716

@@ -157,7 +156,7 @@ def test_transaction_style(
157156

158157

159158
def test_large_json_request(sentry_init, capture_events, route, get_client):
160-
sentry_init(integrations=[PyramidIntegration()], max_request_body_size="always")
159+
sentry_init(integrations=[PyramidIntegration()])
161160

162161
data = {"foo": {"bar": "a" * (DEFAULT_MAX_VALUE_LENGTH + 10)}}
163162

@@ -211,11 +210,9 @@ def index(request):
211210
def test_json_not_truncated_if_max_request_body_size_is_always(
212211
sentry_init, capture_events, route, get_client
213212
):
214-
sentry_init(integrations=[PyramidIntegration()], max_request_body_size="always")
213+
sentry_init(integrations=[PyramidIntegration()])
215214

216-
data = {
217-
"key{}".format(i): "value{}".format(i) for i in range(MAX_DATABAG_BREADTH + 10)
218-
}
215+
data = {"key{}".format(i): "value{}".format(i) for i in range(10**5)}
219216

220217
@route("/")
221218
def index(request):
@@ -234,7 +231,7 @@ def index(request):
234231

235232

236233
def test_files_and_form(sentry_init, capture_events, route, get_client):
237-
sentry_init(integrations=[PyramidIntegration()], max_request_body_size="always")
234+
sentry_init(integrations=[PyramidIntegration()])
238235

239236
data = {
240237
"foo": "a" * (DEFAULT_MAX_VALUE_LENGTH + 10),

tests/test_serializer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ def custom_repr(value):
141141

142142

143143
def test_dont_trim_databag_breadth(body_normalizer):
144-
data = {"key{}".format(i): "value{}".format(i) for i in range(10**9)}
144+
data = {"key{}".format(i): "value{}".format(i) for i in range(10**5)}
145145

146146
result = body_normalizer(data)
147147

148-
assert len(result) == 10**9
148+
assert len(result) == 10**5
149149
for key, value in result.items():
150150
assert data.get(key) == value
151151

0 commit comments

Comments
 (0)