Skip to content

Commit

Permalink
ref: Make SpanProtocol.data non nullable (#2409)
Browse files Browse the repository at this point in the history
SpanProtocol.data is now non nullable
  • Loading branch information
brustolin authored Nov 22, 2022
1 parent e2cec76 commit c9129b6
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/Public/SentrySpanProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ NS_SWIFT_NAME(Span)
/**
* An arbitrary mapping of additional metadata of the span.
*/
@property (nullable, readonly) NSDictionary<NSString *, id> *data;
@property (readonly) NSDictionary<NSString *, id> *data;

/**
* key-value pairs holding additional data about the span.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentrySpan.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ - (void)removeDataForKey:(NSString *)key
}
}

- (nullable NSDictionary<NSString *, id> *)data
- (NSDictionary<NSString *, id> *)data
{
@synchronized(_data) {
return [_data copy];
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryTracer.m
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ - (void)setStartTimestamp:(nullable NSDate *)startTimestamp
#endif
}

- (nullable NSDictionary<NSString *, id> *)data
- (NSDictionary<NSString *, id> *)data
{
@synchronized(_data) {
return [_data copy];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions Tests/SentryTests/Transaction/SentrySpanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit c9129b6

Please sign in to comment.