From 5c536dfd740cc89f72c28228054abc3767af8619 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Wed, 14 May 2025 17:43:50 +0200 Subject: [PATCH 01/12] Update envelope item with item count and try to send envelope --- .../iOS-Swift/ErrorsViewController.swift | 62 ++++++++++++++++++- .../Sentry/Public/SentryEnvelopeItemHeader.h | 6 ++ Sources/Sentry/SentryEnvelopeItemHeader.m | 15 +++++ Sources/Sentry/SentrySerialization.m | 3 + .../Helper/SentrySerializationTests.swift | 34 ++++++++++ 5 files changed, 119 insertions(+), 1 deletion(-) diff --git a/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift b/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift index 3d328f8ff5a..b57f515c98b 100644 --- a/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift @@ -27,13 +27,73 @@ class ErrorsViewController: UIViewController { super.viewDidAppear(animated) SentrySDK.reportFullyDisplayed() + + + + + if SentrySDKOverrides.Feedback.injectScreenshot.boolValue { NotificationCenter.default.post(name: UIApplication.userDidTakeScreenshotNotification, object: nil) } } @IBAction func useAfterFree(_ sender: UIButton) { - imageView.image = UIImage(named: "") +// imageView.image = UIImage(named: "") + + let sdkInfo = SentrySdkInfo.global() + sdkInfo.serialize() + + let sdkInfoJson = try! JSONSerialization.data(withJSONObject: sdkInfo.serialize()) + let sdkInfoJsonString = String(data: sdkInfoJson, encoding: .utf8)! + let traceId = SentrySDK.currentHub().scope.span?.traceContext?.traceId.sentryIdString ?? "00000000000000000000000000000000" + + let header = [ + "sdk": sdkInfo.serialize() + ] + let headerData = try! JSONSerialization.data(withJSONObject: header) + + let logs = [ + "items": [ + [ + "timestamp": "1969-07-20T20:18:04.000Z", + "trace_id": traceId, + "level": "info", + "body": "foobar", + "attributes": [ + "test": [ + "value": "foobar", + "type": "string" + ] + ], + "severity_number": 1 + ] + ] + ] + let logsData = try! JSONSerialization.data(withJSONObject: logs) + + let itemHeader: [String: Any] = [ + "length": logsData.count, + "type":"log", + "item_count": 1, + "content_type": "application/vnd.sentry.items.log+json" + ] + let itemHeaderData = try! JSONSerialization.data(withJSONObject: itemHeader) + + + var itemData = Data() + itemData.append(headerData) + itemData.append(Data("\n".utf8)) + + itemData.append(itemHeaderData) + itemData.append(Data("\n".utf8)) + + itemData.append(logsData) + + guard let envelope = PrivateSentrySDKOnly.envelope(with: itemData) else { + print("Cannot parse the envelope data") + return + } + SentrySDK.capture(envelope) } @IBAction func diskWriteException(_ sender: UIButton) { diff --git a/Sources/Sentry/Public/SentryEnvelopeItemHeader.h b/Sources/Sentry/Public/SentryEnvelopeItemHeader.h index 0612432a4ae..89a935e47a5 100644 --- a/Sources/Sentry/Public/SentryEnvelopeItemHeader.h +++ b/Sources/Sentry/Public/SentryEnvelopeItemHeader.h @@ -20,6 +20,11 @@ SENTRY_NO_INIT filenname:(NSString *)filename contentType:(NSString *)contentType; +- (instancetype)initWithType:(NSString *)type + length:(NSUInteger)length + contentType:(NSString *)contentType + itemCount:(NSNumber *)itemCount; + /** * The type of the envelope item. */ @@ -27,6 +32,7 @@ SENTRY_NO_INIT @property (nonatomic, readonly) NSUInteger length; @property (nonatomic, readonly, copy, nullable) NSString *filename; @property (nonatomic, readonly, copy, nullable) NSString *contentType; +@property (nonatomic, readonly, copy, nullable) NSNumber *itemCount; /** * Some envelopes need to report the platform name for enhanced rate limiting functionality in diff --git a/Sources/Sentry/SentryEnvelopeItemHeader.m b/Sources/Sentry/SentryEnvelopeItemHeader.m index 8ba8fff3d43..80aa5b16784 100644 --- a/Sources/Sentry/SentryEnvelopeItemHeader.m +++ b/Sources/Sentry/SentryEnvelopeItemHeader.m @@ -32,6 +32,17 @@ - (instancetype)initWithType:(NSString *)type return self; } +- (instancetype)initWithType:(NSString *)type + length:(NSUInteger)length + contentType:(NSString *)contentType + itemCount:(NSNumber *)itemCount +{ + if (self = [self initWithType:type length:length contentType:contentType]) { + _itemCount = itemCount; + } + return self; +} + - (NSDictionary *)serialize { @@ -51,6 +62,10 @@ - (NSDictionary *)serialize if (self.platform) { [target setValue:self.contentType forKey:@"platform"]; } + + if (self.itemCount) { + [target setValue:self.itemCount forKey:@"item_count"]; + } [target setValue:[NSNumber numberWithUnsignedInteger:self.length] forKey:@"length"]; diff --git a/Sources/Sentry/SentrySerialization.m b/Sources/Sentry/SentrySerialization.m index add4536a024..92f7a324db0 100644 --- a/Sources/Sentry/SentrySerialization.m +++ b/Sources/Sentry/SentrySerialization.m @@ -182,6 +182,7 @@ + (SentryEnvelope *_Nullable)envelopeWithData:(NSData *)data NSString *filename = [headerDictionary valueForKey:@"filename"]; NSString *contentType = [headerDictionary valueForKey:@"content_type"]; NSString *attachmentType = [headerDictionary valueForKey:@"attachment_type"]; + NSNumber *itemCount = [headerDictionary valueForKey:@"item_count"]; SentryEnvelopeItemHeader *itemHeader; if (nil != filename) { @@ -191,6 +192,8 @@ + (SentryEnvelope *_Nullable)envelopeWithData:(NSData *)data filename:filename contentType:contentType attachmentType:typeForSentryAttachmentName(attachmentType)]; + } else if (nil != itemCount) { + itemHeader = [[SentryEnvelopeItemHeader alloc] initWithType:type length:bodyLength contentType:contentType itemCount:itemCount]; } else { itemHeader = [[SentryEnvelopeItemHeader alloc] initWithType:type length:bodyLength]; } diff --git a/Tests/SentryTests/Helper/SentrySerializationTests.swift b/Tests/SentryTests/Helper/SentrySerializationTests.swift index f0d811ce0d1..9f3124c8ab8 100644 --- a/Tests/SentryTests/Helper/SentrySerializationTests.swift +++ b/Tests/SentryTests/Helper/SentrySerializationTests.swift @@ -365,6 +365,40 @@ class SentrySerializationTests: XCTestCase { XCTAssertEqual(Data(payloadAsString.utf8), item.data) } + func testEnvelopeWithData_log() throws { + let logs = Data(""" + [ + \"timestamp\":\"1969-07-20T20:18:04.000Z\", + \"trace_id\":\"00000000000000000000000000000000\", + \"level\":\"info\", + \"body\":\"foobar\", + \"attrributes\":{} + ] + """.utf8) + + var itemData = Data() + itemData.appendString("{}\n") + itemData.appendString("{\"length\":\(logs.count),\"type\":\"log\",\"item_count\":1,\"content_type\":\"application/vnd.sentry.items.log+json\"}\n") + itemData.append(logs) + + let sting = String(data: itemData, encoding: .utf8) ?? "" + print(sting) + + let envelope = try XCTUnwrap(SentrySerialization.envelope(with: itemData), "Failed to deserialize envelope") + + XCTAssertEqual(1, envelope.items.count) + let item = try XCTUnwrap(envelope.items.first) + + let header = try XCTUnwrap(item.header) + XCTAssertEqual(UInt(logs.count), header.length) + XCTAssertEqual("log", header.type) + XCTAssertEqual(1, header.itemCount?.intValue) + XCTAssertEqual("application/vnd.sentry.items.log+json", header.contentType) + XCTAssertEqual(logs, item.data) + + let data = SentrySerialization.data + } + func testEnvelopeWithData_EmptyEnvelope_ReturnsNil() throws { XCTAssertNil(SentrySerialization.envelope(with: Data())) } From 989303dcc6a09e23bda96897ee083924ada2085b Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Wed, 14 May 2025 15:48:57 +0000 Subject: [PATCH 02/12] Format code --- Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift | 8 +------- Sources/Sentry/SentryEnvelopeItemHeader.m | 2 +- Sources/Sentry/SentrySerialization.m | 5 ++++- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift b/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift index b57f515c98b..193438649d5 100644 --- a/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift @@ -27,11 +27,6 @@ class ErrorsViewController: UIViewController { super.viewDidAppear(animated) SentrySDK.reportFullyDisplayed() - - - - - if SentrySDKOverrides.Feedback.injectScreenshot.boolValue { NotificationCenter.default.post(name: UIApplication.userDidTakeScreenshotNotification, object: nil) } @@ -73,13 +68,12 @@ class ErrorsViewController: UIViewController { let itemHeader: [String: Any] = [ "length": logsData.count, - "type":"log", + "type": "log", "item_count": 1, "content_type": "application/vnd.sentry.items.log+json" ] let itemHeaderData = try! JSONSerialization.data(withJSONObject: itemHeader) - var itemData = Data() itemData.append(headerData) itemData.append(Data("\n".utf8)) diff --git a/Sources/Sentry/SentryEnvelopeItemHeader.m b/Sources/Sentry/SentryEnvelopeItemHeader.m index 80aa5b16784..a94ee64f68f 100644 --- a/Sources/Sentry/SentryEnvelopeItemHeader.m +++ b/Sources/Sentry/SentryEnvelopeItemHeader.m @@ -62,7 +62,7 @@ - (NSDictionary *)serialize if (self.platform) { [target setValue:self.contentType forKey:@"platform"]; } - + if (self.itemCount) { [target setValue:self.itemCount forKey:@"item_count"]; } diff --git a/Sources/Sentry/SentrySerialization.m b/Sources/Sentry/SentrySerialization.m index 92f7a324db0..472321e98a4 100644 --- a/Sources/Sentry/SentrySerialization.m +++ b/Sources/Sentry/SentrySerialization.m @@ -193,7 +193,10 @@ + (SentryEnvelope *_Nullable)envelopeWithData:(NSData *)data contentType:contentType attachmentType:typeForSentryAttachmentName(attachmentType)]; } else if (nil != itemCount) { - itemHeader = [[SentryEnvelopeItemHeader alloc] initWithType:type length:bodyLength contentType:contentType itemCount:itemCount]; + itemHeader = [[SentryEnvelopeItemHeader alloc] initWithType:type + length:bodyLength + contentType:contentType + itemCount:itemCount]; } else { itemHeader = [[SentryEnvelopeItemHeader alloc] initWithType:type length:bodyLength]; } From fa4799e193bec194bb6182313a11bb87c92dd55e Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Thu, 15 May 2025 11:00:01 +0200 Subject: [PATCH 03/12] update sample --- .../iOS-Swift/ErrorsViewController.swift | 47 +++++++++++++++---- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift b/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift index 193438649d5..db27a7972c7 100644 --- a/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift @@ -31,15 +31,20 @@ class ErrorsViewController: UIViewController { NotificationCenter.default.post(name: UIApplication.userDidTakeScreenshotNotification, object: nil) } } + + static let isoFormatter: DateFormatter = { + let formatter = DateFormatter() + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(abbreviation: "UTC") + formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" + return formatter + }() @IBAction func useAfterFree(_ sender: UIButton) { // imageView.image = UIImage(named: "") let sdkInfo = SentrySdkInfo.global() - sdkInfo.serialize() - - let sdkInfoJson = try! JSONSerialization.data(withJSONObject: sdkInfo.serialize()) - let sdkInfoJsonString = String(data: sdkInfoJson, encoding: .utf8)! + let releaseName = SentrySDK.options?.releaseName ?? "iOS-Swift" let traceId = SentrySDK.currentHub().scope.span?.traceContext?.traceId.sentryIdString ?? "00000000000000000000000000000000" let header = [ @@ -47,20 +52,42 @@ class ErrorsViewController: UIViewController { ] let headerData = try! JSONSerialization.data(withJSONObject: header) + let timestamp = Self.isoFormatter.string(from: Date()) + let logs = [ "items": [ [ - "timestamp": "1969-07-20T20:18:04.000Z", + "timestamp": timestamp, "trace_id": traceId, "level": "info", - "body": "foobar", + "body": "foobar3", "attributes": [ - "test": [ - "value": "foobar", + "foo": [ + "value": "bar3", + "type": "string" + ], + "sentry.sdk.name": + [ + "value": "sentry.cocoa", + "type": "string" + ], + "sentry.sdk.version": + [ + "value": "8.50.1", + "type": "string" + ], + "sentry.environment": + [ + "value": "debug", + "type": "string" + ], + "sentry.release": + [ + "value": releaseName, "type": "string" - ] + ] ], - "severity_number": 1 + "severity_number": 9 ] ] ] From bf14852a789423adaf0abe07c0bb11293bfd7671 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Thu, 15 May 2025 11:07:21 +0200 Subject: [PATCH 04/12] revert sample --- .../iOS-Swift/ErrorsViewController.swift | 83 +------------------ 1 file changed, 1 insertion(+), 82 deletions(-) diff --git a/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift b/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift index db27a7972c7..3d328f8ff5a 100644 --- a/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ErrorsViewController.swift @@ -31,90 +31,9 @@ class ErrorsViewController: UIViewController { NotificationCenter.default.post(name: UIApplication.userDidTakeScreenshotNotification, object: nil) } } - - static let isoFormatter: DateFormatter = { - let formatter = DateFormatter() - formatter.locale = Locale(identifier: "en_US_POSIX") - formatter.timeZone = TimeZone(abbreviation: "UTC") - formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" - return formatter - }() @IBAction func useAfterFree(_ sender: UIButton) { -// imageView.image = UIImage(named: "") - - let sdkInfo = SentrySdkInfo.global() - let releaseName = SentrySDK.options?.releaseName ?? "iOS-Swift" - let traceId = SentrySDK.currentHub().scope.span?.traceContext?.traceId.sentryIdString ?? "00000000000000000000000000000000" - - let header = [ - "sdk": sdkInfo.serialize() - ] - let headerData = try! JSONSerialization.data(withJSONObject: header) - - let timestamp = Self.isoFormatter.string(from: Date()) - - let logs = [ - "items": [ - [ - "timestamp": timestamp, - "trace_id": traceId, - "level": "info", - "body": "foobar3", - "attributes": [ - "foo": [ - "value": "bar3", - "type": "string" - ], - "sentry.sdk.name": - [ - "value": "sentry.cocoa", - "type": "string" - ], - "sentry.sdk.version": - [ - "value": "8.50.1", - "type": "string" - ], - "sentry.environment": - [ - "value": "debug", - "type": "string" - ], - "sentry.release": - [ - "value": releaseName, - "type": "string" - ] - ], - "severity_number": 9 - ] - ] - ] - let logsData = try! JSONSerialization.data(withJSONObject: logs) - - let itemHeader: [String: Any] = [ - "length": logsData.count, - "type": "log", - "item_count": 1, - "content_type": "application/vnd.sentry.items.log+json" - ] - let itemHeaderData = try! JSONSerialization.data(withJSONObject: itemHeader) - - var itemData = Data() - itemData.append(headerData) - itemData.append(Data("\n".utf8)) - - itemData.append(itemHeaderData) - itemData.append(Data("\n".utf8)) - - itemData.append(logsData) - - guard let envelope = PrivateSentrySDKOnly.envelope(with: itemData) else { - print("Cannot parse the envelope data") - return - } - SentrySDK.capture(envelope) + imageView.image = UIImage(named: "") } @IBAction func diskWriteException(_ sender: UIButton) { From ee0480b61a8f9cdeace3097548e9e386049f7ab2 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Thu, 15 May 2025 11:29:58 +0200 Subject: [PATCH 05/12] fix test --- .../Helper/SentrySerializationTests.swift | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Tests/SentryTests/Helper/SentrySerializationTests.swift b/Tests/SentryTests/Helper/SentrySerializationTests.swift index 9f3124c8ab8..900644b4613 100644 --- a/Tests/SentryTests/Helper/SentrySerializationTests.swift +++ b/Tests/SentryTests/Helper/SentrySerializationTests.swift @@ -367,13 +367,17 @@ class SentrySerializationTests: XCTestCase { func testEnvelopeWithData_log() throws { let logs = Data(""" - [ - \"timestamp\":\"1969-07-20T20:18:04.000Z\", - \"trace_id\":\"00000000000000000000000000000000\", - \"level\":\"info\", - \"body\":\"foobar\", - \"attrributes\":{} + { + \"items\": [ + { + \"timestamp\":\"1969-07-20T20:18:04.000Z\", + \"trace_id\":\"00000000000000000000000000000000\", + \"level\":\"info\", + \"body\":\"foobar\", + \"attributes\":{} + } ] + } """.utf8) var itemData = Data() @@ -395,8 +399,6 @@ class SentrySerializationTests: XCTestCase { XCTAssertEqual(1, header.itemCount?.intValue) XCTAssertEqual("application/vnd.sentry.items.log+json", header.contentType) XCTAssertEqual(logs, item.data) - - let data = SentrySerialization.data } func testEnvelopeWithData_EmptyEnvelope_ReturnsNil() throws { From fc047c3b2d3ee1cfe9964a0060ba4276ee4e1bfb Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Thu, 15 May 2025 11:45:02 +0200 Subject: [PATCH 06/12] add cl entry --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9a9c9616fc..e493396eb18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Improvements + +- Add `itemCount` to `SentryEnvelopeItemHeader` ([#5230](https://github.com/getsentry/sentry-cocoa/pull/5230)) + ## 8.50.2 ### Fixes From b71a38a9e8ebf8a1bf3de6b0b1ec810cad21d6d6 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Fri, 16 May 2025 14:06:49 +0200 Subject: [PATCH 07/12] remove debug code --- Tests/SentryTests/Helper/SentrySerializationTests.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/Tests/SentryTests/Helper/SentrySerializationTests.swift b/Tests/SentryTests/Helper/SentrySerializationTests.swift index 900644b4613..505be8b397b 100644 --- a/Tests/SentryTests/Helper/SentrySerializationTests.swift +++ b/Tests/SentryTests/Helper/SentrySerializationTests.swift @@ -385,9 +385,6 @@ class SentrySerializationTests: XCTestCase { itemData.appendString("{\"length\":\(logs.count),\"type\":\"log\",\"item_count\":1,\"content_type\":\"application/vnd.sentry.items.log+json\"}\n") itemData.append(logs) - let sting = String(data: itemData, encoding: .utf8) ?? "" - print(sting) - let envelope = try XCTUnwrap(SentrySerialization.envelope(with: itemData), "Failed to deserialize envelope") XCTAssertEqual(1, envelope.items.count) From ac6f4fdb5ebf2ed8215e915c9747d7bf9b670d67 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Fri, 16 May 2025 14:07:40 +0200 Subject: [PATCH 08/12] update test name --- Tests/SentryTests/Helper/SentrySerializationTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SentryTests/Helper/SentrySerializationTests.swift b/Tests/SentryTests/Helper/SentrySerializationTests.swift index 505be8b397b..6b15c3c496d 100644 --- a/Tests/SentryTests/Helper/SentrySerializationTests.swift +++ b/Tests/SentryTests/Helper/SentrySerializationTests.swift @@ -365,7 +365,7 @@ class SentrySerializationTests: XCTestCase { XCTAssertEqual(Data(payloadAsString.utf8), item.data) } - func testEnvelopeWithData_log() throws { + func testEnvelopeWithData_withLogItems_shouldDeserializeLogItemFields() throws { let logs = Data(""" { \"items\": [ From b639416f381c7f616abc273130f6f4c2d8b999f0 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Fri, 16 May 2025 14:20:05 +0200 Subject: [PATCH 09/12] Add own envelope item header tests --- Sentry.xcodeproj/project.pbxproj | 4 ++ .../SentryEnvelopeItemHeaderTests.swift | 53 +++++++++++++++++++ .../Protocol/SentryEnvelopeTests.swift | 32 ----------- 3 files changed, 57 insertions(+), 32 deletions(-) create mode 100644 Tests/SentryTests/Protocol/SentryEnvelopeItemHeaderTests.swift diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index 5955cf45ac4..5ef658f1dcc 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -803,6 +803,7 @@ 92136D672C9D7660002A9FB8 /* SentryNSURLRequestBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92136D662C9D765D002A9FB8 /* SentryNSURLRequestBuilderTests.swift */; }; 925824C22CB5897700C9B20B /* SentrySessionReplayIntegration-Hybrid.h in Headers */ = {isa = PBXBuildFile; fileRef = D80382BE2C09C6FD0090E048 /* SentrySessionReplayIntegration-Hybrid.h */; settings = {ATTRIBUTES = (Private, ); }; }; 92672BB629C9A2A9006B021C /* SentryBreadcrumb+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 92672BB529C9A2A9006B021C /* SentryBreadcrumb+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 927A5CC42DD7626B00B82404 /* SentryEnvelopeItemHeaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 927A5CC32DD7626400B82404 /* SentryEnvelopeItemHeaderTests.swift */; }; 9286059529A5096600F96038 /* SentryGeo.h in Headers */ = {isa = PBXBuildFile; fileRef = 9286059429A5096600F96038 /* SentryGeo.h */; settings = {ATTRIBUTES = (Public, ); }; }; 9286059729A5098900F96038 /* SentryGeo.m in Sources */ = {isa = PBXBuildFile; fileRef = 9286059629A5098900F96038 /* SentryGeo.m */; }; 9286059929A50BAB00F96038 /* SentryGeoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9286059829A50BAA00F96038 /* SentryGeoTests.swift */; }; @@ -1974,6 +1975,7 @@ 8FF94DF22B06A24C00BCD650 /* SentryCrash+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryCrash+Test.h"; sourceTree = ""; }; 92136D662C9D765D002A9FB8 /* SentryNSURLRequestBuilderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSURLRequestBuilderTests.swift; sourceTree = ""; }; 92672BB529C9A2A9006B021C /* SentryBreadcrumb+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "SentryBreadcrumb+Private.h"; path = "include/HybridPublic/SentryBreadcrumb+Private.h"; sourceTree = ""; }; + 927A5CC32DD7626400B82404 /* SentryEnvelopeItemHeaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryEnvelopeItemHeaderTests.swift; sourceTree = ""; }; 9286059429A5096600F96038 /* SentryGeo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryGeo.h; path = Public/SentryGeo.h; sourceTree = ""; }; 9286059629A5098900F96038 /* SentryGeo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SentryGeo.m; sourceTree = ""; }; 9286059829A50BAA00F96038 /* SentryGeoTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SentryGeoTests.swift; sourceTree = ""; }; @@ -3116,6 +3118,7 @@ 7B869EBB249B91D8004F4FDB /* SentryDebugMetaEquality.swift */, 7B869EBD249B964D004F4FDB /* SentryThreadEquality.swift */, 7BF536D024BDF3E7004FA6A2 /* SentryEnvelopeTests.swift */, + 927A5CC32DD7626400B82404 /* SentryEnvelopeItemHeaderTests.swift */, 7BC6EBF3255C044A0059822A /* SentryEventTests.swift */, 7B88F30124BC5C6D00ADF90A /* SentrySdkInfoTests.swift */, 7B26BBFA24C0A66D00A79CCC /* SentrySdkInfoNilTests.m */, @@ -5396,6 +5399,7 @@ 62277BBC2DA5183500EF06B7 /* SentryTracer+Test.m in Sources */, 7B58816727FC5D790098B121 /* SentryDiscardReasonMapperTests.swift in Sources */, 63FE720320DA66EC00CDBAE8 /* SentryCrashCPU_Tests.m in Sources */, + 927A5CC42DD7626B00B82404 /* SentryEnvelopeItemHeaderTests.swift in Sources */, 63FE721020DA66EC00CDBAE8 /* SentryCrashCachedData_Tests.m in Sources */, 0A9BF4E928A125390068D266 /* TestSentryViewHierarchy.swift in Sources */, 7BC6EC10255C3F560059822A /* SentryMechanismTests.swift in Sources */, diff --git a/Tests/SentryTests/Protocol/SentryEnvelopeItemHeaderTests.swift b/Tests/SentryTests/Protocol/SentryEnvelopeItemHeaderTests.swift new file mode 100644 index 00000000000..0faad2c7f41 --- /dev/null +++ b/Tests/SentryTests/Protocol/SentryEnvelopeItemHeaderTests.swift @@ -0,0 +1,53 @@ +@testable import Sentry +import SentryTestUtils +import XCTest + +class SentryEnvelopeItemHeaderTests: XCTestCase { + + func test_SentryEnvelopeItemHeaderSerialization_DefaultInit() { + let header = SentryEnvelopeItemHeader(type: "SomeType", length: 10) + + let data = header.serialize() + XCTAssertEqual(data.count, 2) + XCTAssertEqual(data.count, 2) + XCTAssertEqual(data["type"] as? String, "SomeType") + XCTAssertEqual(data["length"] as? Int, 10) + XCTAssertNil(data["filename"]) + XCTAssertNil(data["content_type"]) + XCTAssertEqual(data.count, 2) + } + + func test_SentryEnvelopeItemHeaderSerialization_WithContentType() { + let header = SentryEnvelopeItemHeader(type: "SomeType", length: 10, contentType: "text/html") + + let data = header.serialize() + XCTAssertEqual(data["type"] as? String, "SomeType") + XCTAssertEqual(data["length"] as? Int, 10) + XCTAssertNil(data["filename"]) + XCTAssertEqual(data["content_type"] as? String, "text/html") + XCTAssertEqual(data.count, 3) + } + + func test_SentryEnvelopeItemHeaderSerialization_WithItemCount() { + let header = SentryEnvelopeItemHeader(type: "SomeType", length: 10, contentType: "text/html", itemCount: NSNumber(value: 3)) + + let data = header.serialize() + XCTAssertEqual(data["type"] as? String, "SomeType") + XCTAssertEqual(data["length"] as? Int, 10) + XCTAssertNil(data["filename"]) + XCTAssertEqual(data["content_type"] as? String, "text/html") + XCTAssertEqual(data["item_count"] as? NSNumber, NSNumber(value: 3)) + XCTAssertEqual(data.count, 4) + } + + func test_SentryEnvelopeItemHeaderSerialization_WithFilename() { + let header = SentryEnvelopeItemHeader(type: "SomeType", length: 10, filenname: "SomeFileName", contentType: "text/html") + + let data = header.serialize() + XCTAssertEqual(data["type"] as? String, "SomeType") + XCTAssertEqual(data["length"] as? Int, 10) + XCTAssertEqual(data["filename"] as? String, "SomeFileName") + XCTAssertEqual(data["content_type"] as? String, "text/html") + XCTAssertEqual(data.count, 4) + } +} diff --git a/Tests/SentryTests/Protocol/SentryEnvelopeTests.swift b/Tests/SentryTests/Protocol/SentryEnvelopeTests.swift index 792c43d4545..3e12343e798 100644 --- a/Tests/SentryTests/Protocol/SentryEnvelopeTests.swift +++ b/Tests/SentryTests/Protocol/SentryEnvelopeTests.swift @@ -310,39 +310,7 @@ class SentryEnvelopeTests: XCTestCase { XCTAssertEqual(data2.count, 3) } - func test_SentryEnvelopeItemHeaderSerialization_DefaultInit() { - let header = SentryEnvelopeItemHeader(type: "SomeType", length: 10) - - let data = header.serialize() - XCTAssertEqual(data.count, 2) - XCTAssertEqual(data.count, 2) - XCTAssertEqual(data["type"] as? String, "SomeType") - XCTAssertEqual(data["length"] as? Int, 10) - XCTAssertNil(data["filename"]) - XCTAssertNil(data["content_type"]) - } - func test_SentryEnvelopeItemHeaderSerialization_WithoutFileName() { - let header = SentryEnvelopeItemHeader(type: "SomeType", length: 10, contentType: "text/html") - - let data = header.serialize() - XCTAssertEqual(data["type"] as? String, "SomeType") - XCTAssertEqual(data["length"] as? Int, 10) - XCTAssertNil(data["filename"]) - XCTAssertEqual(data["content_type"] as? String, "text/html") - XCTAssertEqual(data.count, 3) - } - - func test_SentryEnvelopeItemHeaderSerialization_AllParameters() { - let header = SentryEnvelopeItemHeader(type: "SomeType", length: 10, filenname: "SomeFileName", contentType: "text/html") - - let data = header.serialize() - XCTAssertEqual(data["type"] as? String, "SomeType") - XCTAssertEqual(data["length"] as? Int, 10) - XCTAssertEqual(data["filename"] as? String, "SomeFileName") - XCTAssertEqual(data["content_type"] as? String, "text/html") - XCTAssertEqual(data.count, 4) - } func testInitWithDataAttachment_MaxAttachmentSize() { let attachmentTooBig = Attachment(data: fixture.dataTooBig, filename: "") From 4805353e62395dafcb3abb8a4ad287118b5269cc Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Fri, 16 May 2025 14:22:55 +0200 Subject: [PATCH 10/12] remove duplicate expectation --- Tests/SentryTests/Protocol/SentryEnvelopeItemHeaderTests.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Tests/SentryTests/Protocol/SentryEnvelopeItemHeaderTests.swift b/Tests/SentryTests/Protocol/SentryEnvelopeItemHeaderTests.swift index 0faad2c7f41..d17439213e8 100644 --- a/Tests/SentryTests/Protocol/SentryEnvelopeItemHeaderTests.swift +++ b/Tests/SentryTests/Protocol/SentryEnvelopeItemHeaderTests.swift @@ -8,8 +8,6 @@ class SentryEnvelopeItemHeaderTests: XCTestCase { let header = SentryEnvelopeItemHeader(type: "SomeType", length: 10) let data = header.serialize() - XCTAssertEqual(data.count, 2) - XCTAssertEqual(data.count, 2) XCTAssertEqual(data["type"] as? String, "SomeType") XCTAssertEqual(data["length"] as? Int, 10) XCTAssertNil(data["filename"]) From 2028cef79c267260b32ae07477334b961eec593a Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Fri, 16 May 2025 12:24:20 +0000 Subject: [PATCH 11/12] Format code --- Tests/SentryTests/Protocol/SentryEnvelopeTests.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Tests/SentryTests/Protocol/SentryEnvelopeTests.swift b/Tests/SentryTests/Protocol/SentryEnvelopeTests.swift index 3e12343e798..640710c92f7 100644 --- a/Tests/SentryTests/Protocol/SentryEnvelopeTests.swift +++ b/Tests/SentryTests/Protocol/SentryEnvelopeTests.swift @@ -309,8 +309,6 @@ class SentryEnvelopeTests: XCTestCase { XCTAssertEqual(data2["attachment_type"] as? String, "event.attachment") XCTAssertEqual(data2.count, 3) } - - func testInitWithDataAttachment_MaxAttachmentSize() { let attachmentTooBig = Attachment(data: fixture.dataTooBig, filename: "") From 9c9b46efb008d1222b380e92ea580cebcd368529 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Mon, 19 May 2025 10:13:38 +0200 Subject: [PATCH 12/12] format cl --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3ef6f83223..a3eeacb835d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Improvements - Add `itemCount` to `SentryEnvelopeItemHeader` ([#5230](https://github.com/getsentry/sentry-cocoa/pull/5230)) + ### Features - Apps can now manually show and hide the included feedback widget button (#5236)