feat: Transport logs error message for HTTP 413 responses#7261
feat: Transport logs error message for HTTP 413 responses#7261philipphofmann merged 16 commits intomainfrom
Conversation
Implements error logging for HTTP 413 (Content Too Large) responses to help users understand why their envelopes are being rejected. The error message includes the envelope size in bytes and item types. Fixes #7248
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧
Other
🤖 This preview updates automatically when you update the PR. |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7261 +/- ##
=============================================
- Coverage 85.050% 85.039% -0.012%
=============================================
Files 470 472 +2
Lines 28396 28414 +18
Branches 12464 12468 +4
=============================================
+ Hits 24151 24163 +12
- Misses 4199 4202 +3
- Partials 46 49 +3
... and 9 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| edcda5a | 1217.52 ms | 1248.72 ms | 31.20 ms |
| 2e5230b | 1207.41 ms | 1240.41 ms | 33.00 ms |
| 3b01aaf | 1194.98 ms | 1210.36 ms | 15.38 ms |
| 387fbe4 | 1226.19 ms | 1251.98 ms | 25.79 ms |
| 7e93d85 | 1205.28 ms | 1243.71 ms | 38.44 ms |
| 5d67f5d | 1225.33 ms | 1262.76 ms | 37.43 ms |
| 45eb835 | 1210.40 ms | 1233.39 ms | 22.99 ms |
| 37bc095 | 1210.00 ms | 1242.69 ms | 32.69 ms |
| ffe0649 | 1213.35 ms | 1248.64 ms | 35.29 ms |
| c424b6a | 1220.38 ms | 1248.18 ms | 27.80 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| edcda5a | 24.14 KiB | 1.08 MiB | 1.06 MiB |
| 2e5230b | 24.14 KiB | 1.04 MiB | 1.02 MiB |
| 3b01aaf | 24.14 KiB | 1.06 MiB | 1.04 MiB |
| 387fbe4 | 24.14 KiB | 1.07 MiB | 1.04 MiB |
| 7e93d85 | 24.14 KiB | 1.06 MiB | 1.04 MiB |
| 5d67f5d | 24.14 KiB | 1.06 MiB | 1.04 MiB |
| 45eb835 | 24.14 KiB | 1.07 MiB | 1.04 MiB |
| 37bc095 | 24.14 KiB | 1.06 MiB | 1.04 MiB |
| ffe0649 | 24.14 KiB | 1.06 MiB | 1.04 MiB |
| c424b6a | 24.14 KiB | 1.06 MiB | 1.04 MiB |
…andling Introduces a new Swift enum to replace magic numbers with named constants for HTTP status codes. The enum is accessible from both Swift and Objective-C and includes custom equality operators for seamless Int comparison without requiring .rawValue. All status codes include MDN documentation references. Updated SentryHttpTransportHttpStatusCodeLogger and its tests to use the enum, improving code readability and type safety.
…P transport - Renamed SentryHttpStatusCodes to SentryHttpStatusCode (singular) for consistency - Added HTTP 201 Created and 400 Bad Request status codes - Updated SentryHttpTransport to use enum values for status code comparisons (200, 400, 429) - Added comprehensive test suite for enum equality operators - All equality operators support direct Int comparison without .rawValue Updated files: - SentryHttpStatusCode.swift (renamed from SentryHttpStatusCodes.swift) - SentryHttpTransport.m: Uses enum for 200, 400, and 429 status codes - SentryHttpTransportHttpStatusCodeLogger.swift: Updated enum references - Tests: Updated all test files to use renamed enum - Added SentryHttpStatusCodeTests.swift with 11 tests for equality and raw value verification
…ests - Renamed raw value tests to status code value tests - Changed all but one test to use == operator instead of .rawValue - Kept one raw value test (testRawValue_shouldReturnCorrectInt) to verify rawValue works - All 12 tests passing
Changed from (200 == SentryHttpStatusCode.ok) to (SentryHttpStatusCode.ok == 200) for more natural reading order.
|
@philprime, I added the HTTP status code enum. Please have another look 😃 |
Regenerated sdk_api.json to include the new SentryHttpStatusCode enum exposed to Objective-C via @objc annotation.
Removed @_spi(Private) and public modifiers from the equality operators. These operators are only needed within the module and don't need to be exposed as SPI.
📜 Description
Implements error logging for HTTP 413 (Content Too Large) responses to help users understand why their envelopes are being rejected. When the SDK receives an HTTP 413 response, it now logs an error message.
💡 Motivation and Context
Fixes #7248
Users need visibility into why their envelopes are being rejected by the server. HTTP 413 responses indicate the envelope is too large, but without detailed logging, it's difficult to diagnose which events or attachments are causing the issue.
This follows the Sentry SDK specification: https://develop.sentry.dev/sdk/expected-features/#dealing-with-network-failures
💚 How did you test it?
Unit tests and tested with a sample app and capturing a message exceeding 1 MiB to double-check if Relay returns 413.
📝 Checklist
You have to check all boxes before merging:
sendDefaultPIIis enabled.