diff --git a/CHANGELOG.md b/CHANGELOG.md index dc96321894..a02db0c19e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +- Keep PropagationContext when cloning scope (#4518) + ## 8.40.1 ### Fixes diff --git a/Sources/Sentry/SentryPropagationContext.h b/Sources/Sentry/SentryPropagationContext.h index 553dffb445..54b6e5bd54 100644 --- a/Sources/Sentry/SentryPropagationContext.h +++ b/Sources/Sentry/SentryPropagationContext.h @@ -8,8 +8,8 @@ NS_ASSUME_NONNULL_BEGIN @interface SentryPropagationContext : NSObject -@property (nonatomic, strong) SentryId *traceId; -@property (nonatomic, strong) SentrySpanId *spanId; +@property (nonatomic, strong, readonly) SentryId *traceId; +@property (nonatomic, strong, readonly) SentrySpanId *spanId; @property (nonatomic, readonly) SentryTraceHeader *traceHeader; - (NSDictionary *)traceContextForEvent; diff --git a/Sources/Sentry/SentryPropagationContext.m b/Sources/Sentry/SentryPropagationContext.m index 965f3ab19b..ac56aa1fad 100644 --- a/Sources/Sentry/SentryPropagationContext.m +++ b/Sources/Sentry/SentryPropagationContext.m @@ -8,8 +8,8 @@ @implementation SentryPropagationContext - (instancetype)init { if (self = [super init]) { - self.traceId = [[SentryId alloc] init]; - self.spanId = [[SentrySpanId alloc] init]; + _traceId = [[SentryId alloc] init]; + _spanId = [[SentrySpanId alloc] init]; } return self; } diff --git a/Sources/Sentry/SentryScope.m b/Sources/Sentry/SentryScope.m index 21fb2e873b..b515944db5 100644 --- a/Sources/Sentry/SentryScope.m +++ b/Sources/Sentry/SentryScope.m @@ -97,7 +97,7 @@ - (instancetype)initWithScope:(SentryScope *)scope [_fingerprintArray addObjectsFromArray:[scope fingerprints]]; [_attachmentArray addObjectsFromArray:[scope attachments]]; - self.propagationContext = [[SentryPropagationContext alloc] init]; + self.propagationContext = scope.propagationContext; self.maxBreadcrumbs = scope.maxBreadcrumbs; self.userObject = scope.userObject.copy; self.distString = scope.distString; diff --git a/Tests/SentryTests/SentryScopeSwiftTests.swift b/Tests/SentryTests/SentryScopeSwiftTests.swift index f6ec28907b..697e21e7d9 100644 --- a/Tests/SentryTests/SentryScopeSwiftTests.swift +++ b/Tests/SentryTests/SentryScopeSwiftTests.swift @@ -127,6 +127,8 @@ class SentryScopeSwiftTests: XCTestCase { let cloned = Scope(scope: scope) XCTAssertEqual(try XCTUnwrap(cloned.serialize() as? [String: AnyHashable]), snapshot) + XCTAssertEqual(scope.propagationContext.spanId, cloned.propagationContext.spanId) + XCTAssertEqual(scope.propagationContext.traceId, cloned.propagationContext.traceId) let (event1, event2) = (Event(), Event()) (event1.timestamp, event2.timestamp) = (fixture.date, fixture.date)