From 45a5fea346fd9acdbff215ddf736c78e9dd154e6 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Tue, 22 Nov 2022 08:03:14 +0100 Subject: [PATCH 1/3] test: Disable NSDataTracker in clearTestState (#2418) --- Tests/SentryTests/ClearTestState.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/SentryTests/ClearTestState.swift b/Tests/SentryTests/ClearTestState.swift index 02db84e1294..ac2f1958b51 100644 --- a/Tests/SentryTests/ClearTestState.swift +++ b/Tests/SentryTests/ClearTestState.swift @@ -25,4 +25,6 @@ func clearTestState() { SentryDependencyContainer.reset() Dynamic(SentryGlobalEventProcessor.shared()).removeAllProcessors() SentrySwizzleWrapper.sharedInstance.removeAllCallbacks() + + SentryNSDataTracker.sharedInstance.disable() } From d10145a3fd32fa7e8b1bb8c7f1dc3bc0c88bef69 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Mon, 21 Nov 2022 22:04:00 -0900 Subject: [PATCH 2/3] typos (#2421) --- Sources/Sentry/SentryUIEventTracker.m | 12 ++++++------ .../SentrySubClassFinderTests.swift | 2 +- .../Performance/SentryTracerTests.swift | 4 ++-- .../SentryCrashReportSinkTests.swift | 14 +++++++------- .../SentryThreadInspectorTests.swift | 18 +++++++++--------- Tests/SentryTests/TestClient.swift | 4 ++-- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Sources/Sentry/SentryUIEventTracker.m b/Sources/Sentry/SentryUIEventTracker.m index efeb27443f8..1d041d3dd39 100644 --- a/Sources/Sentry/SentryUIEventTracker.m +++ b/Sources/Sentry/SentryUIEventTracker.m @@ -169,13 +169,13 @@ - (NSString *)getOperation:(id)sender */ - (NSString *)getTransactionName:(NSString *)action target:(NSString *)target { - NSArray *componens = [action componentsSeparatedByString:@":"]; - if (componens.count > 2) { + NSArray *components = [action componentsSeparatedByString:@":"]; + if (components.count > 2) { NSMutableString *result = - [[NSMutableString alloc] initWithFormat:@"%@.%@(", target, componens.firstObject]; + [[NSMutableString alloc] initWithFormat:@"%@.%@(", target, components.firstObject]; - for (int i = 1; i < (componens.count - 1); i++) { - [result appendFormat:@"%@:", componens[i]]; + for (int i = 1; i < (components.count - 1); i++) { + [result appendFormat:@"%@:", components[i]]; } [result appendFormat:@")"]; @@ -183,7 +183,7 @@ - (NSString *)getTransactionName:(NSString *)action target:(NSString *)target return result; } - return [NSString stringWithFormat:@"%@.%@", target, componens.firstObject]; + return [NSString stringWithFormat:@"%@.%@", target, components.firstObject]; } NS_ASSUME_NONNULL_END diff --git a/Tests/SentryTests/Integrations/Performance/SentrySubClassFinderTests.swift b/Tests/SentryTests/Integrations/Performance/SentrySubClassFinderTests.swift index c50f3128c18..bc4340ba311 100644 --- a/Tests/SentryTests/Integrations/Performance/SentrySubClassFinderTests.swift +++ b/Tests/SentryTests/Integrations/Performance/SentrySubClassFinderTests.swift @@ -57,7 +57,7 @@ class SentrySubClassFinderTests: XCTestCase { assertActOnSubclassesOfViewController(expected: [], imageName: "OtherImage") } - func testGettingSublcasses_DoesNotCallInitializer() { + func testGettingSubclasses_DoesNotCallInitializer() { let sut = SentrySubClassFinder(dispatchQueue: TestSentryDispatchQueueWrapper(), objcRuntimeWrapper: fixture.runtimeWrapper) var actual: [AnyClass] = [] diff --git a/Tests/SentryTests/Performance/SentryTracerTests.swift b/Tests/SentryTests/Performance/SentryTracerTests.swift index 53be5bcfe32..9498f409ce2 100644 --- a/Tests/SentryTests/Performance/SentryTracerTests.swift +++ b/Tests/SentryTests/Performance/SentryTracerTests.swift @@ -751,13 +751,13 @@ class SentryTracerTests: XCTestCase { XCTAssertEqual(transactions, fixture.hub.capturedEventsWithScopes.count) - let transactionsWithAppStartMeasrurement = fixture.hub.capturedEventsWithScopes.filter { pair in + let transactionsWithAppStartMeasurement = fixture.hub.capturedEventsWithScopes.filter { pair in let serializedTransaction = pair.event.serialize() let measurements = serializedTransaction["measurements"] as? [String: [String: Int]] return measurements == ["app_start_warm": ["value": 500]] } - XCTAssertEqual(1, transactionsWithAppStartMeasrurement.count) + XCTAssertEqual(1, transactionsWithAppStartMeasurement.count) } #if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) diff --git a/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift b/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift index 0b213b277d1..211c841f90e 100644 --- a/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift +++ b/Tests/SentryTests/SentryCrash/SentryCrashReportSinkTests.swift @@ -52,8 +52,8 @@ class SentryCrashReportSinkTests: SentrySDKIntegrationTestsBase { filterReportWithAttachment() let client = getTestClient() - XCTAssertEqual(1, client.flushInvoctions.count) - XCTAssertEqual(5, client.flushInvoctions.first) + XCTAssertEqual(1, client.flushInvocations.count) + XCTAssertEqual(5, client.flushInvocations.first) XCTAssertEqual(0, fixture.dispatchQueue.dispatchAsyncCalled) } @@ -63,8 +63,8 @@ class SentryCrashReportSinkTests: SentrySDKIntegrationTestsBase { filterReportWithAttachment() let client = getTestClient() - XCTAssertEqual(1, client.flushInvoctions.count) - XCTAssertEqual(5, client.flushInvoctions.first) + XCTAssertEqual(1, client.flushInvocations.count) + XCTAssertEqual(5, client.flushInvocations.first) XCTAssertEqual(0, fixture.dispatchQueue.dispatchAsyncCalled) } @@ -74,7 +74,7 @@ class SentryCrashReportSinkTests: SentrySDKIntegrationTestsBase { filterReportWithAttachment() let client = getTestClient() - XCTAssertEqual(0, client.flushInvoctions.count) + XCTAssertEqual(0, client.flushInvocations.count) XCTAssertEqual(1, fixture.dispatchQueue.dispatchAsyncCalled) } @@ -84,7 +84,7 @@ class SentryCrashReportSinkTests: SentrySDKIntegrationTestsBase { filterReportWithAttachment() let client = getTestClient() - XCTAssertEqual(0, client.flushInvoctions.count) + XCTAssertEqual(0, client.flushInvocations.count) XCTAssertEqual(1, fixture.dispatchQueue.dispatchAsyncCalled) } @@ -94,7 +94,7 @@ class SentryCrashReportSinkTests: SentrySDKIntegrationTestsBase { filterReportWithAttachment() let client = getTestClient() - XCTAssertEqual(0, client.flushInvoctions.count) + XCTAssertEqual(0, client.flushInvocations.count) XCTAssertEqual(1, fixture.dispatchQueue.dispatchAsyncCalled) } diff --git a/Tests/SentryTests/SentryCrash/SentryThreadInspectorTests.swift b/Tests/SentryTests/SentryCrash/SentryThreadInspectorTests.swift index fcf32564fc6..1ca14af6974 100644 --- a/Tests/SentryTests/SentryCrash/SentryThreadInspectorTests.swift +++ b/Tests/SentryTests/SentryCrash/SentryThreadInspectorTests.swift @@ -6,10 +6,10 @@ import XCTest var testMachineContextWrapper = TestMachineContextWrapper() var stacktraceBuilder = TestSentryStacktraceBuilder(crashStackEntryMapper: SentryCrashStackEntryMapper(inAppLogic: SentryInAppLogic(inAppIncludes: [], inAppExcludes: []))) - func getSut(testWithRealMachineConextWrapper: Bool = false) -> SentryThreadInspector { + func getSut(testWithRealMachineContextWrapper: Bool = false) -> SentryThreadInspector { - let machineContextWrapper = testWithRealMachineConextWrapper ? SentryCrashDefaultMachineContextWrapper() : testMachineContextWrapper as SentryCrashMachineContextWrapper - let stacktraceBuilder = testWithRealMachineConextWrapper ? SentryStacktraceBuilder(crashStackEntryMapper: SentryCrashStackEntryMapper(inAppLogic: SentryInAppLogic(inAppIncludes: [], inAppExcludes: []))) : self.stacktraceBuilder + let machineContextWrapper = testWithRealMachineContextWrapper ? SentryCrashDefaultMachineContextWrapper() : testMachineContextWrapper as SentryCrashMachineContextWrapper + let stacktraceBuilder = testWithRealMachineContextWrapper ? SentryStacktraceBuilder(crashStackEntryMapper: SentryCrashStackEntryMapper(inAppLogic: SentryInAppLogic(inAppIncludes: [], inAppExcludes: []))) : self.stacktraceBuilder return SentryThreadInspector( stacktraceBuilder: stacktraceBuilder, @@ -31,7 +31,7 @@ import XCTest } func testStacktraceHasFrames() { - let actual = fixture.getSut(testWithRealMachineConextWrapper: true).getCurrentThreads() + let actual = fixture.getSut(testWithRealMachineContextWrapper: true).getCurrentThreads() let stacktrace = actual[0].stacktrace // The stacktrace has usually more than 40 frames. Feel free to change the number if the tests are failing @@ -57,7 +57,7 @@ import XCTest let expect = expectation(description: "Read every thread") expect.expectedFulfillmentCount = 10 - let sut = self.fixture.getSut(testWithRealMachineConextWrapper: true) + let sut = self.fixture.getSut(testWithRealMachineContextWrapper: true) for _ in 0..<10 { queue.async { @@ -84,7 +84,7 @@ import XCTest } func testOnlyCurrentThreadHasStacktrace() { - let actual = fixture.getSut(testWithRealMachineConextWrapper: true).getCurrentThreads() + let actual = fixture.getSut(testWithRealMachineContextWrapper: true).getCurrentThreads() XCTAssertEqual(true, actual[0].current) XCTAssertNotNil(actual[0].stacktrace) @@ -93,7 +93,7 @@ import XCTest } func testOnlyFirstThreadIsCurrent() { - let actual = fixture.getSut(testWithRealMachineConextWrapper: true).getCurrentThreads() + let actual = fixture.getSut(testWithRealMachineContextWrapper: true).getCurrentThreads() let thread0 = actual[0] XCTAssertEqual(true, thread0.current) @@ -105,7 +105,7 @@ import XCTest } func testStacktraceOnlyForCurrentThread() { - let actual = fixture.getSut(testWithRealMachineConextWrapper: true).getCurrentThreads() + let actual = fixture.getSut(testWithRealMachineContextWrapper: true).getCurrentThreads() XCTAssertNotNil(actual[0].stacktrace) @@ -117,7 +117,7 @@ import XCTest } func testCrashedIsFalseForAllThreads() { - let actual = fixture.getSut(testWithRealMachineConextWrapper: true).getCurrentThreads() + let actual = fixture.getSut(testWithRealMachineContextWrapper: true).getCurrentThreads() let threadCount = actual.count for i in 0..() + var flushInvocations = Invocations() override func flush(timeout: TimeInterval) { - flushInvoctions.record(timeout) + flushInvocations.record(timeout) } } From dcac8ad115f21b3952fa4c7971cf2c1b44eb6362 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Tue, 22 Nov 2022 05:58:13 -0300 Subject: [PATCH 3/3] 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