Skip to content

Conversation

@adinauer
Copy link
Member

📜 Description

Detect oversized events and reduce their size by removing breadcrumbs and reducing stack trace size.
Also add onOversizedError callback that allows customers to customize what's dropped.

💡 Motivation and Context

So we can be more lenient with truncation in SDK and only perform it if required to reduce event size.

💚 How did you test it?

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

@github-actions
Copy link
Contributor

github-actions bot commented Nov 14, 2025

Fails
🚫 Please consider adding a changelog entry for the next release.
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Features

- Detect oversized events and reduce their size ([#4903](https://github.com/getsentry/sentry-java/pull/4903))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against 486fc42

* Callback invoked when an oversized event is detected. This allows custom handling of oversized
* events before the automatic reduction steps are applied.
*/
private @Nullable OnOversizedErrorCallback onOversizedError;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should we best call this so customers know what it's used for?
Should this instead be more like an EventProcessor interface, where we can add methods for each feature (error events, spans, ...) in the future?

Suggested change
private @Nullable OnOversizedErrorCallback onOversizedError;
private @Nullable OnOversizedEventCallback onOversizedEvent;

@adinauer adinauer marked this pull request as draft November 14, 2025 08:41
reducedEvent = onOversizedError.execute(reducedEvent, hint);
if (!isTooLarge(reducedEvent, options)) {
return reducedEvent;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Misinterpreted Null Leads to Silent Data Loss

When onOversizedError callback returns null (violating its @NotNull contract), the code treats this as success because byteSizeOf(null) returns 0, making isTooLarge return false. This causes the event to be silently dropped without error logging, instead of continuing with automatic reduction. The callback result needs validation before the size check.

Fix in Cursor Fix in Web

if (!isTooLarge(reducedEvent, options)) {
return reducedEvent;
}
} catch (Exception e) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Callback Errors: A Crash Hazard

The callback exception handler catches Exception instead of Throwable, inconsistent with other callback handlers in the codebase like executeBeforeSend. This means Error subclasses (like OutOfMemoryError) thrown by the callback won't be caught, potentially crashing the SDK instead of continuing with automatic reduction.

Fix in Cursor Fix in Web

@github-actions
Copy link
Contributor

github-actions bot commented Nov 14, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 312.72 ms 354.90 ms 42.18 ms
Size 1.58 MiB 2.13 MiB 556.24 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
ee747ae 415.92 ms 470.15 ms 54.23 ms
9fbb112 401.87 ms 515.87 ms 114.00 ms
9fbb112 404.51 ms 475.65 ms 71.14 ms
604a261 380.65 ms 451.27 ms 70.62 ms
674d437 355.28 ms 504.18 ms 148.90 ms
33a08cc 267.08 ms 340.45 ms 73.37 ms
27d7cf8 309.43 ms 364.27 ms 54.85 ms
96449e8 361.30 ms 423.39 ms 62.09 ms
c8125f3 397.65 ms 485.14 ms 87.49 ms
ee747ae 382.73 ms 435.41 ms 52.68 ms

App size

Revision Plain With Sentry Diff
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB
9fbb112 1.58 MiB 2.11 MiB 539.18 KiB
9fbb112 1.58 MiB 2.11 MiB 539.18 KiB
604a261 1.58 MiB 2.10 MiB 533.42 KiB
674d437 1.58 MiB 2.10 MiB 530.94 KiB
33a08cc 1.58 MiB 2.12 MiB 555.28 KiB
27d7cf8 1.58 MiB 2.12 MiB 549.42 KiB
96449e8 1.58 MiB 2.11 MiB 539.35 KiB
c8125f3 1.58 MiB 2.10 MiB 532.32 KiB
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB

Previous results on branch: feat/detect-oversized-error-events

Startup times

Revision Plain With Sentry Diff
606e793 329.40 ms 395.16 ms 65.76 ms

App size

Revision Plain With Sentry Diff
606e793 1.58 MiB 2.13 MiB 556.48 KiB

* Enables event size limiting with {@link EventSizeLimitingEventProcessor}. When enabled, events
* exceeding 1MB will have breadcrumbs and stack frames reduced to stay under the limit.
*/
private boolean enableEventSizeLimiting = false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kepping this opt-in for now, we could turn it on by default in the next major.

* @return the modified event (should ideally be reduced in size)
*/
@NotNull
SentryEvent execute(@NotNull SentryEvent event, @NotNull Hint hint);
Copy link
Member Author

@adinauer adinauer Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO running this between beforeSend and passing this on to the transport is the best place to check since customers might be adding large amounts of data in beforeSend, so first reducing size and then adding back to it could easily cause the event to become too large again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants