From c9129b61cacbb239cad1ff4cb057bbe09dc78906 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Tue, 22 Nov 2022 10:59:48 -0300 Subject: [PATCH] ref: Make SpanProtocol.data non nullable (#2409) SpanProtocol.data is now non nullable --- CHANGELOG.md | 1 + .../ViewControllers/TraceTestViewController.swift | 2 +- Sources/Sentry/Public/SentrySpanProtocol.h | 2 +- Sources/Sentry/SentrySpan.m | 2 +- Sources/Sentry/SentryTracer.m | 2 +- .../CoreData/SentryCoreDataTrackerTest.swift | 4 ++-- .../Performance/IO/SentryNSDataTrackerTests.swift | 4 ++-- .../Network/SentryNetworkTrackerTests.swift | 6 +++--- Tests/SentryTests/Transaction/SentrySpanTests.swift | 10 +++++----- 9 files changed, 17 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28531f5055b..628a646b4ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ This version adds a dependency on Swift. - Remove `- [SentryOptions initWithDict:didFailWithError:]` (#2404) - Rename `- [SentrySDK startWithOptionsObject:]` to `- [SentrySDK startWithOptions:]` (#2404) - Remove `- [SentryOptions sdkInfo]` (#2404) +- Make `SpanProtocol.data` non nullable (#2409) - Mark `- [SpanProtocol setExtraValue:forKey:]` as deprecated (#2413) - Bump minimum supported OS versions to macOS 10.13, iOS 11, tvOS 11, and watchOS 4 (#2414) diff --git a/Samples/iOS-Swift/iOS-Swift/ViewControllers/TraceTestViewController.swift b/Samples/iOS-Swift/iOS-Swift/ViewControllers/TraceTestViewController.swift index 915ea81d2be..8993f131699 100644 --- a/Samples/iOS-Swift/iOS-Swift/ViewControllers/TraceTestViewController.swift +++ b/Samples/iOS-Swift/iOS-Swift/ViewControllers/TraceTestViewController.swift @@ -72,7 +72,7 @@ class TraceTestViewController: UIViewController { return } - UIAssert.isEqual(child.data?["url"] as? String, "/sentry-logo-black.png", "Could not read url data value") + UIAssert.isEqual(child.data["url"] as? String, "/sentry-logo-black.png", "Could not read url data value") UIAssert.isEqual(child.tags["http.status_code"], "200", "Could not read status_code tag value") diff --git a/Sources/Sentry/Public/SentrySpanProtocol.h b/Sources/Sentry/Public/SentrySpanProtocol.h index 45c4906ba93..6c685a7c536 100644 --- a/Sources/Sentry/Public/SentrySpanProtocol.h +++ b/Sources/Sentry/Public/SentrySpanProtocol.h @@ -27,7 +27,7 @@ NS_SWIFT_NAME(Span) /** * An arbitrary mapping of additional metadata of the span. */ -@property (nullable, readonly) NSDictionary *data; +@property (readonly) NSDictionary *data; /** * key-value pairs holding additional data about the span. diff --git a/Sources/Sentry/SentrySpan.m b/Sources/Sentry/SentrySpan.m index 732f07f2ba9..66506b2ff80 100644 --- a/Sources/Sentry/SentrySpan.m +++ b/Sources/Sentry/SentrySpan.m @@ -74,7 +74,7 @@ - (void)removeDataForKey:(NSString *)key } } -- (nullable NSDictionary *)data +- (NSDictionary *)data { @synchronized(_data) { return [_data copy]; diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index af64da2b2cb..cea5432cf56 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -332,7 +332,7 @@ - (void)setStartTimestamp:(nullable NSDate *)startTimestamp #endif } -- (nullable NSDictionary *)data +- (NSDictionary *)data { @synchronized(_data) { return [_data copy]; diff --git a/Tests/SentryTests/Integrations/Performance/CoreData/SentryCoreDataTrackerTest.swift b/Tests/SentryTests/Integrations/Performance/CoreData/SentryCoreDataTrackerTest.swift index 66303f720c2..6687543876b 100644 --- a/Tests/SentryTests/Integrations/Performance/CoreData/SentryCoreDataTrackerTest.swift +++ b/Tests/SentryTests/Integrations/Performance/CoreData/SentryCoreDataTrackerTest.swift @@ -151,7 +151,7 @@ class SentryCoreDataTrackerTests: XCTestCase { XCTAssertEqual(transaction.children.count, 1) - guard let operations = transaction.children[0].data?["operations"] as? [String: Any?] else { + guard let operations = transaction.children[0].data["operations"] as? [String: Any?] else { XCTFail("Transaction has no `operations` extra") return } @@ -230,7 +230,7 @@ class SentryCoreDataTrackerTests: XCTestCase { XCTAssertEqual(transaction.children.count, 1) XCTAssertEqual(transaction.children[0].context.operation, SENTRY_COREDATA_FETCH_OPERATION) XCTAssertEqual(transaction.children[0].context.spanDescription, expectedDescription) - XCTAssertEqual(transaction.children[0].data!["read_count"] as? Int, 1) + XCTAssertEqual(transaction.children[0].data["read_count"] as? Int, 1) } private func startTransaction() -> SentryTracer { diff --git a/Tests/SentryTests/Integrations/Performance/IO/SentryNSDataTrackerTests.swift b/Tests/SentryTests/Integrations/Performance/IO/SentryNSDataTrackerTests.swift index 4af9c2bd313..f799402e0a3 100644 --- a/Tests/SentryTests/Integrations/Performance/IO/SentryNSDataTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Performance/IO/SentryNSDataTrackerTests.swift @@ -224,8 +224,8 @@ class SentryNSDataTrackerTests: XCTestCase { XCTAssertNotNil(span) XCTAssertEqual(span?.context.operation, operation) XCTAssertTrue(span?.isFinished ?? false) - XCTAssertEqual(span?.data?["file.size"] as? Int, size) - XCTAssertEqual(span?.data?["file.path"] as? String, path) + XCTAssertEqual(span?.data["file.size"] as? Int, size) + XCTAssertEqual(span?.data["file.path"] as? String, path) let lastComponent = (path as NSString).lastPathComponent diff --git a/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerTests.swift b/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerTests.swift index 53b1a7d1f2f..6f05da0988c 100644 --- a/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerTests.swift @@ -746,9 +746,9 @@ class SentryNetworkTrackerTests: XCTestCase { XCTAssertNil(httpStatusCode) } - let path = span.data!["url"] as? String - let method = span.data!["method"] as? String - let requestType = span.data!["type"] as? String + let path = span.data["url"] as? String + let method = span.data["method"] as? String + let requestType = span.data["type"] as? String XCTAssertEqual(path, task.currentRequest!.url!.path) XCTAssertEqual(method, task.currentRequest!.httpMethod) diff --git a/Tests/SentryTests/Transaction/SentrySpanTests.swift b/Tests/SentryTests/Transaction/SentrySpanTests.swift index 214ae819e06..1bb2c53fd7d 100644 --- a/Tests/SentryTests/Transaction/SentrySpanTests.swift +++ b/Tests/SentryTests/Transaction/SentrySpanTests.swift @@ -190,12 +190,12 @@ class SentrySpanTests: XCTestCase { span.setData(value: fixture.extraValue, key: fixture.extraKey) - XCTAssertEqual(span.data!.count, 1) - XCTAssertEqual(span.data![fixture.extraKey] as! String, fixture.extraValue) + XCTAssertEqual(span.data.count, 1) + XCTAssertEqual(span.data[fixture.extraKey] as! String, fixture.extraValue) span.removeData(key: fixture.extraKey) - XCTAssertEqual(span.data!.count, 0) - XCTAssertNil(span.data![fixture.extraKey]) + XCTAssertEqual(span.data.count, 0) + XCTAssertNil(span.data[fixture.extraKey]) } func testAddAndRemoveTags() { @@ -357,7 +357,7 @@ class SentrySpanTests: XCTestCase { queue.activate() group.wait() - XCTAssertEqual(span.data!.count, outerLoop * innerLoop) + XCTAssertEqual(span.data.count, outerLoop * innerLoop) } func testSpanStatusNames() {