Skip to content

Commit 6e196fe

Browse files
impr: Remove char limit of 8192 for SentryMessage (#5005)
Let Relay truncate the max char length. The benefit is that users see that the message was truncated. Fixes GH-5004
1 parent 8f4cd6f commit 6e196fe

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- Continuous profile stop requests are cancelled by subsequent timely calls to start (#4993)
88

9+
### Improvements
10+
11+
- Remove SDK side character limit of 8192 for SentryMessage (#5005) Now, the backend handles the character limit, which has the advantage of showing in the UI when the message was truncated.
12+
913
## 8.48.0
1014

1115
### Features

Sources/Sentry/Public/SentryMessage.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ SENTRY_NO_INIT
2020
/**
2121
* Returns a @c SentryMessage with setting formatted.
2222
* @param formatted The fully formatted message. If missing, Sentry will try to interpolate the
23-
* message. It must not exceed 8192 characters. Longer messages will be truncated.
23+
* message. The backend will truncate messages longer than 8192 characters.
2424
*/
2525
- (instancetype)initWithFormatted:(NSString *)formatted;
2626

Sources/Sentry/SentryMessage.m

+2-12
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,19 @@
22

33
NS_ASSUME_NONNULL_BEGIN
44

5-
const NSUInteger MAX_STRING_LENGTH = 8192;
6-
75
@implementation SentryMessage
86

97
- (instancetype)initWithFormatted:(NSString *)formatted
108
{
119
if (self = [super init]) {
12-
if (nil != formatted && formatted.length > MAX_STRING_LENGTH) {
13-
_formatted = [formatted substringToIndex:MAX_STRING_LENGTH];
14-
} else {
15-
_formatted = formatted;
16-
}
10+
_formatted = formatted;
1711
}
1812
return self;
1913
}
2014

2115
- (void)setMessage:(NSString *_Nullable)message
2216
{
23-
if (nil != message && message.length > MAX_STRING_LENGTH) {
24-
_message = [message substringToIndex:MAX_STRING_LENGTH];
25-
} else {
26-
_message = message;
27-
}
17+
_message = message;
2818
}
2919

3020
- (NSDictionary<NSString *, id> *)serialize

Tests/SentryTests/Protocol/SentryMessageTests.swift

+10-9
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,32 @@ class SentryMessageTests: XCTestCase {
1717
message.message = "A message %s %s"
1818
message.params = ["my", "params"]
1919
}
20-
2120
}
2221

2322
private let fixture = Fixture()
2423

25-
func testTruncateFormatted() {
24+
func testFormatted_NotTruncated() {
2625
let message = SentryMessage(formatted: "aaaaa")
2726
XCTAssertEqual(5, message.formatted.count)
2827

2928
XCTAssertEqual(fixture.stringMaxCount, SentryMessage(formatted: fixture.maximumCount).formatted.count)
30-
31-
XCTAssertEqual(fixture.stringMaxCount, SentryMessage(formatted: fixture.tooLong).formatted.count)
29+
30+
// Let Relay do the truncation
31+
XCTAssertEqual(fixture.tooLong.count, SentryMessage(formatted: fixture.tooLong).formatted.count)
3232
}
3333

34-
func testTruncateMessage() {
34+
func testMessage_NotTruncated() {
3535
let message = SentryMessage(formatted: "")
3636
message.message = "aaaaa %s"
37-
37+
3838
XCTAssertEqual(8, message.message?.count)
39-
39+
4040
message.message = fixture.maximumCount
4141
XCTAssertEqual(fixture.stringMaxCount, message.message?.count)
42-
42+
43+
// Let Relay do the truncation
4344
message.message = fixture.tooLong
44-
XCTAssertEqual(fixture.stringMaxCount, message.message?.count)
45+
XCTAssertEqual(fixture.tooLong.count, message.message?.count)
4546
}
4647

4748
func testSerialize() {

0 commit comments

Comments
 (0)