Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Deprecate SentryUser.segment #4092

Merged
merged 4 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion Sources/Sentry/Public/SentryUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Sources/Sentry/SentryClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions Sources/Sentry/SentryNetworkTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions Sources/Sentry/SentryTraceContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]]) {
Expand Down
15 changes: 15 additions & 0 deletions Sources/Sentry/SentryUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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"];
Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ class SentryNetworkTrackerTests: XCTestCase {
XCTAssertEqual(task.currentRequest?.allHTTPHeaderFields?["sentry-trace"] ?? "", "test")
}

@available(*, deprecated)
func testDefaultHeadersWhenDisabled() {
let sut = fixture.getSut()
sut.disable()
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions Tests/SentryTests/Protocol/SentryUserTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import XCTest

@available(*, deprecated)
class SentryUserTests: XCTestCase {

func testInitWithDictionary() {
Expand Down
1 change: 0 additions & 1 deletion Tests/SentryTests/Protocol/TestData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class TestData {
user.email = "[email protected]"
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]]
Expand Down
2 changes: 2 additions & 0 deletions Tests/SentryTests/SentryScopeSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SentryScopeSwiftTests: XCTestCase {
let transactionOperation = "Some Operation"
let maxBreadcrumbs = 5

@available(*, deprecated)
init() {
date = Date(timeIntervalSince1970: 10)

Expand Down Expand Up @@ -81,6 +82,7 @@ class SentryScopeSwiftTests: XCTestCase {

private var fixture: Fixture!

@available(*, deprecated)
override func setUp() {
super.setUp()
fixture = Fixture()
Expand Down
2 changes: 2 additions & 0 deletions Tests/SentryTests/Transaction/SentryTraceStateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class SentryTraceContextTests: XCTestCase {
let sampled = "true"
let replayId = "some_replay_id"

@available(*, deprecated)
init() {
options = Options()
options.dsn = SentryTraceContextTests.dsnAsString
Expand All @@ -43,6 +44,7 @@ class SentryTraceContextTests: XCTestCase {

private var fixture: Fixture!

@available(*, deprecated)
override func setUp() {
super.setUp()
fixture = Fixture()
Expand Down
Loading