From dcac8ad115f21b3952fa4c7971cf2c1b44eb6362 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Tue, 22 Nov 2022 05:58:13 -0300 Subject: [PATCH] ref: Mark [SpanProtocol setExtraValue:forKey] as deprecated (#2413) Marked `[SpanProtocol setExtraValue:forKey]' deprecated --- CHANGELOG.md | 4 ++++ Sources/Sentry/Public/SentrySpanProtocol.h | 5 +++-- Sources/Sentry/SentryNoOpSpan.h | 1 + Sources/Sentry/include/SentrySpan.h | 1 + Sources/Sentry/include/SentryTracer.h | 2 ++ .../Performance/SentryTracerTests.swift | 1 + .../Transaction/SentryNoOpSpanTests.swift | 1 - .../SentryTests/Transaction/SentrySpanTests.swift | 15 ++++++++------- Tests/SentryTests/Transaction/TestSentrySpan.h | 2 ++ 9 files changed, 22 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d26cd9fa82..bd915cf1116 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ This version adds a dependency on Swift. +### Breaking Changes + +- Mark `- [SpanProtocol setExtraValue:forKey:]` as deprecated (#2413) + ### Features - Properly demangle Swift class name (#2162) diff --git a/Sources/Sentry/Public/SentrySpanProtocol.h b/Sources/Sentry/Public/SentrySpanProtocol.h index ce206fe8778..45c4906ba93 100644 --- a/Sources/Sentry/Public/SentrySpanProtocol.h +++ b/Sources/Sentry/Public/SentrySpanProtocol.h @@ -68,9 +68,10 @@ NS_SWIFT_NAME(Span) /** * Use setDataValue instead. This method calls setDataValue, was added by mistake, and will be - * deprecated in a future version. + * removed in a future version. */ -- (void)setExtraValue:(nullable id)value forKey:(NSString *)key NS_SWIFT_NAME(setExtra(value:key:)); +- (void)setExtraValue:(nullable id)value + forKey:(NSString *)key DEPRECATED_ATTRIBUTE NS_SWIFT_NAME(setExtra(value:key:)); /** * Removes a data value. diff --git a/Sources/Sentry/SentryNoOpSpan.h b/Sources/Sentry/SentryNoOpSpan.h index 6056730a2ed..8bbaefd830a 100644 --- a/Sources/Sentry/SentryNoOpSpan.h +++ b/Sources/Sentry/SentryNoOpSpan.h @@ -17,6 +17,7 @@ SENTRY_NO_INIT @property (nullable, readonly) NSDictionary *data; @property (readonly) NSDictionary *tags; +- (void)setExtraValue:(nullable id)value forKey:(NSString *)key DEPRECATED_ATTRIBUTE; @end NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/include/SentrySpan.h b/Sources/Sentry/include/SentrySpan.h index c0c9e3ae170..7b7fa04a290 100644 --- a/Sources/Sentry/include/SentrySpan.h +++ b/Sources/Sentry/include/SentrySpan.h @@ -45,6 +45,7 @@ SENTRY_NO_INIT */ - (instancetype)initWithTracer:(SentryTracer *)transaction context:(SentrySpanContext *)context; +- (void)setExtraValue:(nullable id)value forKey:(NSString *)key DEPRECATED_ATTRIBUTE; @end NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/include/SentryTracer.h b/Sources/Sentry/include/SentryTracer.h index cc113df4a5c..054ea890e20 100644 --- a/Sources/Sentry/include/SentryTracer.h +++ b/Sources/Sentry/include/SentryTracer.h @@ -143,6 +143,8 @@ static NSTimeInterval const SentryTracerDefaultTimeout = 3.0; */ - (void)spanFinished:(id)finishedSpan; +- (void)setExtraValue:(nullable id)value forKey:(NSString *)key DEPRECATED_ATTRIBUTE; + /** * Get the tracer from a span. */ diff --git a/Tests/SentryTests/Performance/SentryTracerTests.swift b/Tests/SentryTests/Performance/SentryTracerTests.swift index 9498f409ce2..15cf2368764 100644 --- a/Tests/SentryTests/Performance/SentryTracerTests.swift +++ b/Tests/SentryTests/Performance/SentryTracerTests.swift @@ -810,6 +810,7 @@ class SentryTracerTests: XCTestCase { } #endif + @available(*, deprecated) func testSetExtra_ForwardsToSetData() { let sut = fixture.getSut() sut.setExtra(value: 0, key: "key") diff --git a/Tests/SentryTests/Transaction/SentryNoOpSpanTests.swift b/Tests/SentryTests/Transaction/SentryNoOpSpanTests.swift index db1d0600cf0..73875e4ef63 100644 --- a/Tests/SentryTests/Transaction/SentryNoOpSpanTests.swift +++ b/Tests/SentryTests/Transaction/SentryNoOpSpanTests.swift @@ -27,7 +27,6 @@ class SentryNoOpSpanTests: XCTestCase { let sut = SentryNoOpSpan.shared() XCTAssertNil(sut.data) sut.setData(value: "tet", key: "key") - sut.setExtra(value: "tet", key: "key") sut.removeData(key: "any") XCTAssertNil(sut.data) } diff --git a/Tests/SentryTests/Transaction/SentrySpanTests.swift b/Tests/SentryTests/Transaction/SentrySpanTests.swift index c853504c520..5be36249459 100644 --- a/Tests/SentryTests/Transaction/SentrySpanTests.swift +++ b/Tests/SentryTests/Transaction/SentrySpanTests.swift @@ -185,10 +185,10 @@ class SentrySpanTests: XCTestCase { XCTAssertFalse(logOutput.loggedMessages.filter({ $0.contains(" Starting a child on a finished span is not supported; it won\'t be sent to Sentry.") }).isEmpty) } - func testAddAndRemoveExtras() { + func testAddAndRemoveData() { let span = fixture.getSut() - span.setExtra(value: fixture.extraValue, key: fixture.extraKey) + span.setData(value: fixture.extraValue, key: fixture.extraKey) XCTAssertEqual(span.data!.count, 1) XCTAssertEqual(span.data![fixture.extraKey] as! String, fixture.extraValue) @@ -214,7 +214,7 @@ class SentrySpanTests: XCTestCase { func testSerialization() { let span = fixture.getSut() - span.setExtra(value: fixture.extraValue, key: fixture.extraKey) + span.setData(value: fixture.extraValue, key: fixture.extraKey) span.setTag(value: fixture.extraValue, key: fixture.extraKey) span.finish() @@ -234,7 +234,7 @@ class SentrySpanTests: XCTestCase { func testSanitizeData() { let span = fixture.getSut() - span.setExtra(value: Date(timeIntervalSince1970: 10), key: "date") + span.setData(value: Date(timeIntervalSince1970: 10), key: "date") span.finish() let serialization = span.serialize() @@ -244,7 +244,7 @@ class SentrySpanTests: XCTestCase { func testSanitizeDataSpan() { let span = SentrySpan(tracer: fixture.tracer, context: SpanContext(operation: fixture.someOperation, sampled: .undecided)) - span.setExtra(value: Date(timeIntervalSince1970: 10), key: "date") + span.setData(value: Date(timeIntervalSince1970: 10), key: "date") span.finish() let serialization = span.serialize() @@ -305,13 +305,14 @@ class SentrySpanTests: XCTestCase { XCTAssertEqual(header.value(), "\(span.context.traceId)-\(span.context.spanId)") } + @available(*, deprecated) func testSetExtra_ForwardsToSetData() { let sut = SentrySpan(tracer: fixture.tracer, context: SpanContext(operation: "test")) sut.setExtra(value: 0, key: "key") XCTAssertEqual(["key": 0], sut.data as! [String: Int]) } - + func testSpanWithoutTracer_StartChild_ReturnsNoOpSpan() { // Span has a weak reference to tracer. If we don't keep a reference // to the tracer ARC will deallocate the tracer. @@ -349,7 +350,7 @@ class SentrySpanTests: XCTestCase { queue.async { for j in 0.. +- (void)setExtraValue:(nullable id)value forKey:(nonnull NSString *)key DEPRECATED_ATTRIBUTE; + @end NS_ASSUME_NONNULL_END