From 81980bdd8699901d231df487e53a53c36ec17c5d Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Thu, 20 Jun 2024 15:41:30 +0200 Subject: [PATCH 1/2] fix: Deprecate SentryUser.segment Fixes GH-4090 --- CHANGELOG.md | 1 + Sources/Sentry/Public/SentryUser.h | 4 +++- Sources/Sentry/SentryClient.m | 3 +++ Sources/Sentry/SentryNetworkTracker.m | 3 +++ Sources/Sentry/SentryTraceContext.m | 3 +++ Sources/Sentry/SentryUser.m | 15 +++++++++++++++ 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bca98dd572..2e809f55540 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Fixes - `storeEnvelope` ends session for unhandled errors (#4073) +- Deprecate `SentryUser.segment`(#4092). Please remove usages of this property. We will remove it in the next major. ## 8.29.1 diff --git a/Sources/Sentry/Public/SentryUser.h b/Sources/Sentry/Public/SentryUser.h index 525f8c444fe..3587e0e7a8d 100644 --- a/Sources/Sentry/Public/SentryUser.h +++ b/Sources/Sentry/Public/SentryUser.h @@ -30,8 +30,10 @@ NS_SWIFT_NAME(User) /** * The user segment, for apps that divide users in user segments. + * @deprecated This field will be removed in the next major version. */ -@property (atomic, copy) NSString *_Nullable segment; +@property (atomic, copy) NSString *_Nullable segment DEPRECATED_MSG_ATTRIBUTE( + "This field is deprecated and will be removed in the next major update."); /** * Optional: Human readable name diff --git a/Sources/Sentry/SentryClient.m b/Sources/Sentry/SentryClient.m index 68793363f7a..3517f7713b6 100644 --- a/Sources/Sentry/SentryClient.m +++ b/Sources/Sentry/SentryClient.m @@ -381,9 +381,12 @@ - (nullable SentryTraceContext *)getTraceStateWithEvent:(SentryEvent *)event } if (event.error || event.exceptions.count > 0) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" return [[SentryTraceContext alloc] initWithTraceId:scope.propagationContext.traceId options:self.options userSegment:scope.userObject.segment]; +#pragma clang diagnostic pop } return nil; diff --git a/Sources/Sentry/SentryNetworkTracker.m b/Sources/Sentry/SentryNetworkTracker.m index ef91506a6e6..15016d616fb 100644 --- a/Sources/Sentry/SentryNetworkTracker.m +++ b/Sources/Sentry/SentryNetworkTracker.m @@ -232,10 +232,13 @@ - (void)urlSessionTaskResume:(NSURLSessionTask *)sessionTask - (void)addTraceWithoutTransactionToTask:(NSURLSessionTask *)sessionTask { SentryPropagationContext *propagationContext = SentrySDK.currentHub.scope.propagationContext; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" SentryTraceContext *traceContext = [[SentryTraceContext alloc] initWithTraceId:propagationContext.traceId options:SentrySDK.currentHub.client.options userSegment:SentrySDK.currentHub.scope.userObject.segment]; +#pragma clang diagnostic pop [self addBaggageHeader:[traceContext toBaggage] traceHeader:[propagationContext traceHeader] diff --git a/Sources/Sentry/SentryTraceContext.m b/Sources/Sentry/SentryTraceContext.m index d249209c553..afe2a1b541f 100644 --- a/Sources/Sentry/SentryTraceContext.m +++ b/Sources/Sentry/SentryTraceContext.m @@ -59,9 +59,12 @@ - (nullable instancetype)initWithTracer:(SentryTracer *)tracer NSString *userSegment; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" if (scope.userObject.segment) { userSegment = scope.userObject.segment; } +#pragma clang diagnostic pop NSString *sampleRate = nil; if ([tracer isKindOfClass:[SentryTransactionContext class]]) { diff --git a/Sources/Sentry/SentryUser.m b/Sources/Sentry/SentryUser.m index 5a7ec63a50e..6952055e9b6 100644 --- a/Sources/Sentry/SentryUser.m +++ b/Sources/Sentry/SentryUser.m @@ -32,7 +32,10 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary } else if ([key isEqualToString:@"ip_address"] && isString) { self.ipAddress = value; } else if ([key isEqualToString:@"segment"] && isString) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" self.segment = value; +#pragma clang diagnostic pop } else if ([key isEqualToString:@"data"] && isDictionary) { self.data = value; } else { @@ -69,7 +72,10 @@ - (id)copyWithZone:(nullable NSZone *)zone copy.email = self.email; copy.username = self.username; copy.ipAddress = self.ipAddress; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" copy.segment = self.segment; +#pragma clang diagnostic pop copy.name = self.name; copy.geo = self.geo.copy; copy.data = self.data.copy; @@ -87,7 +93,10 @@ - (id)copyWithZone:(nullable NSZone *)zone [serializedData setValue:self.email forKey:@"email"]; [serializedData setValue:self.username forKey:@"username"]; [serializedData setValue:self.ipAddress forKey:@"ip_address"]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" [serializedData setValue:self.segment forKey:@"segment"]; +#pragma clang diagnostic pop [serializedData setValue:self.name forKey:@"name"]; [serializedData setValue:[self.geo serialize] forKey:@"geo"]; [serializedData setValue:sentry_sanitize(self.data) forKey:@"data"]; @@ -142,10 +151,13 @@ - (BOOL)isEqualToUser:(SentryUser *)user return NO; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" NSString *otherSegment = user.segment; if (self.segment != otherSegment && ![self.segment isEqualToString:otherSegment]) { return NO; } +#pragma clang diagnostic pop NSString *otherName = user.name; if (self.name != otherName && ![self.name isEqualToString:otherName]) { @@ -178,7 +190,10 @@ - (NSUInteger)hash hash = hash * 23 + [self.email hash]; hash = hash * 23 + [self.username hash]; hash = hash * 23 + [self.ipAddress hash]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" hash = hash * 23 + [self.segment hash]; +#pragma clang diagnostic pop hash = hash * 23 + [self.name hash]; hash = hash * 23 + [self.geo hash]; hash = hash * 23 + [self.data hash]; From 112855d665044b987742d5eb527e35f2b5041166 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Fri, 21 Jun 2024 09:45:48 +0200 Subject: [PATCH 2/2] fix tests --- .../Performance/Network/SentryNetworkTrackerTests.swift | 2 ++ Tests/SentryTests/Protocol/SentryUserTests.swift | 1 + Tests/SentryTests/Protocol/TestData.swift | 1 - Tests/SentryTests/SentryScopeSwiftTests.swift | 2 ++ Tests/SentryTests/Transaction/SentryTraceStateTests.swift | 2 ++ 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerTests.swift b/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerTests.swift index fc34d2e38cb..71f589ba257 100644 --- a/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerTests.swift @@ -674,6 +674,7 @@ class SentryNetworkTrackerTests: XCTestCase { XCTAssertEqual(task.currentRequest?.allHTTPHeaderFields?["sentry-trace"] ?? "", "test") } + @available(*, deprecated) func testDefaultHeadersWhenDisabled() { let sut = fixture.getSut() sut.disable() @@ -689,6 +690,7 @@ class SentryNetworkTrackerTests: XCTestCase { XCTAssertEqual(task.currentRequest?.allHTTPHeaderFields?["sentry-trace"] ?? "", expectedTraceHeader) } + @available(*, deprecated) func testDefaultHeadersWhenNoTransaction() { let sut = fixture.getSut() let task = createDataTask() diff --git a/Tests/SentryTests/Protocol/SentryUserTests.swift b/Tests/SentryTests/Protocol/SentryUserTests.swift index 109721f2106..6e6ed248598 100644 --- a/Tests/SentryTests/Protocol/SentryUserTests.swift +++ b/Tests/SentryTests/Protocol/SentryUserTests.swift @@ -1,5 +1,6 @@ import XCTest +@available(*, deprecated) class SentryUserTests: XCTestCase { func testInitWithDictionary() { diff --git a/Tests/SentryTests/Protocol/TestData.swift b/Tests/SentryTests/Protocol/TestData.swift index 8fe7a64f5c5..4d9b5de9467 100644 --- a/Tests/SentryTests/Protocol/TestData.swift +++ b/Tests/SentryTests/Protocol/TestData.swift @@ -63,7 +63,6 @@ class TestData { user.email = "user@sentry.io" user.username = "user123" user.ipAddress = "127.0.0.1" - user.segment = "segmentA" user.name = "User" user.geo = geo user.data = ["some": ["data": "data", "date": timestamp] as [String: Any]] diff --git a/Tests/SentryTests/SentryScopeSwiftTests.swift b/Tests/SentryTests/SentryScopeSwiftTests.swift index a7fea59b7cc..2191026884a 100644 --- a/Tests/SentryTests/SentryScopeSwiftTests.swift +++ b/Tests/SentryTests/SentryScopeSwiftTests.swift @@ -24,6 +24,7 @@ class SentryScopeSwiftTests: XCTestCase { let transactionOperation = "Some Operation" let maxBreadcrumbs = 5 + @available(*, deprecated) init() { date = Date(timeIntervalSince1970: 10) @@ -81,6 +82,7 @@ class SentryScopeSwiftTests: XCTestCase { private var fixture: Fixture! + @available(*, deprecated) override func setUp() { super.setUp() fixture = Fixture() diff --git a/Tests/SentryTests/Transaction/SentryTraceStateTests.swift b/Tests/SentryTests/Transaction/SentryTraceStateTests.swift index 7ecd00628bb..67ce2e49234 100644 --- a/Tests/SentryTests/Transaction/SentryTraceStateTests.swift +++ b/Tests/SentryTests/Transaction/SentryTraceStateTests.swift @@ -22,6 +22,7 @@ class SentryTraceContextTests: XCTestCase { let sampled = "true" let replayId = "some_replay_id" + @available(*, deprecated) init() { options = Options() options.dsn = SentryTraceContextTests.dsnAsString @@ -43,6 +44,7 @@ class SentryTraceContextTests: XCTestCase { private var fixture: Fixture! + @available(*, deprecated) override func setUp() { super.setUp() fixture = Fixture()