diff --git a/CHANGELOG.md b/CHANGELOG.md index 1254f58f772..ce99c146575 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Pause replay in session mode when offline (#4264) - Add replay quality option for Objective-C (#4267) +- Expose span baggage API (#4207) ### Fixes diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index da34ccf245c..7b56f2e009c 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -839,7 +839,7 @@ D859697327BECDD20036A46E /* SentryCoreDataSwizzling.m in Sources */ = {isa = PBXBuildFile; fileRef = D859697127BECDD20036A46E /* SentryCoreDataSwizzling.m */; }; D85D3BEA278DF63D001B2889 /* SentryByteCountFormatterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D85D3BE9278DF63D001B2889 /* SentryByteCountFormatterTests.swift */; }; D8603DD6284F8497000E1227 /* SentryBaggage.m in Sources */ = {isa = PBXBuildFile; fileRef = D8603DD4284F8497000E1227 /* SentryBaggage.m */; }; - D8603DD8284F894C000E1227 /* SentryBaggage.h in Headers */ = {isa = PBXBuildFile; fileRef = D8603DD7284F894C000E1227 /* SentryBaggage.h */; }; + D8603DD8284F894C000E1227 /* SentryBaggage.h in Headers */ = {isa = PBXBuildFile; fileRef = D8603DD7284F894C000E1227 /* SentryBaggage.h */; settings = {ATTRIBUTES = (Public, ); }; }; D86130122BB563FD004C0F5E /* SentrySessionReplayIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D86130112BB563FD004C0F5E /* SentrySessionReplayIntegrationTests.swift */; }; D861301C2BB5A267004C0F5E /* SentrySessionReplayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D861301B2BB5A267004C0F5E /* SentrySessionReplayTests.swift */; }; D865892F29D6ECA7000BE151 /* SentryCrashBinaryImageCache.h in Headers */ = {isa = PBXBuildFile; fileRef = D865892D29D6ECA7000BE151 /* SentryCrashBinaryImageCache.h */; }; @@ -863,7 +863,7 @@ D885266427739D01001269FC /* SentryFileIOTrackingIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D885266327739D01001269FC /* SentryFileIOTrackingIntegrationTests.swift */; }; D8853C842833EABC00700D64 /* SentryANRTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BCFA71427D0BAB7008C662C /* SentryANRTracker.h */; }; D88817D826D7149100BF2251 /* SentryTraceContext.m in Sources */ = {isa = PBXBuildFile; fileRef = D88817D626D7149100BF2251 /* SentryTraceContext.m */; }; - D88817DA26D72AB800BF2251 /* SentryTraceContext.h in Headers */ = {isa = PBXBuildFile; fileRef = D88817D926D72AB800BF2251 /* SentryTraceContext.h */; settings = {ATTRIBUTES = (Private, ); }; }; + D88817DA26D72AB800BF2251 /* SentryTraceContext.h in Headers */ = {isa = PBXBuildFile; fileRef = D88817D926D72AB800BF2251 /* SentryTraceContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; D88817DD26D72BA500BF2251 /* SentryTraceStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D88817DB26D72B7B00BF2251 /* SentryTraceStateTests.swift */; }; D8918B222849FA6D00701F9A /* SentrySDKIntegrationTestsBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8918B212849FA6D00701F9A /* SentrySDKIntegrationTestsBase.swift */; }; D8AB40DB2806EC1900E5E9F7 /* SentryScreenshotIntegration.h in Headers */ = {isa = PBXBuildFile; fileRef = D8AB40DA2806EC1900E5E9F7 /* SentryScreenshotIntegration.h */; }; @@ -1903,7 +1903,7 @@ D859697127BECDD20036A46E /* SentryCoreDataSwizzling.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryCoreDataSwizzling.m; sourceTree = ""; }; D85D3BE9278DF63D001B2889 /* SentryByteCountFormatterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryByteCountFormatterTests.swift; sourceTree = ""; }; D8603DD4284F8497000E1227 /* SentryBaggage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryBaggage.m; sourceTree = ""; }; - D8603DD7284F894C000E1227 /* SentryBaggage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryBaggage.h; path = include/SentryBaggage.h; sourceTree = ""; }; + D8603DD7284F894C000E1227 /* SentryBaggage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryBaggage.h; path = Public/SentryBaggage.h; sourceTree = ""; }; D86130112BB563FD004C0F5E /* SentrySessionReplayIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySessionReplayIntegrationTests.swift; sourceTree = ""; }; D861301B2BB5A267004C0F5E /* SentrySessionReplayTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySessionReplayTests.swift; sourceTree = ""; }; D865892D29D6ECA7000BE151 /* SentryCrashBinaryImageCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryCrashBinaryImageCache.h; sourceTree = ""; }; @@ -1930,7 +1930,7 @@ D884A20327C80F2700074664 /* SentryCoreDataTrackerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCoreDataTrackerTest.swift; sourceTree = ""; }; D885266327739D01001269FC /* SentryFileIOTrackingIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryFileIOTrackingIntegrationTests.swift; sourceTree = ""; }; D88817D626D7149100BF2251 /* SentryTraceContext.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryTraceContext.m; sourceTree = ""; }; - D88817D926D72AB800BF2251 /* SentryTraceContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryTraceContext.h; path = include/SentryTraceContext.h; sourceTree = ""; }; + D88817D926D72AB800BF2251 /* SentryTraceContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryTraceContext.h; path = Public/SentryTraceContext.h; sourceTree = ""; }; D88817DB26D72B7B00BF2251 /* SentryTraceStateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryTraceStateTests.swift; sourceTree = ""; }; D88D25E92B8E0BAC0073C3D5 /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = ""; }; D8918B212849FA6D00701F9A /* SentrySDKIntegrationTestsBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySDKIntegrationTestsBase.swift; sourceTree = ""; }; diff --git a/SentryTestUtils/TestTransportAdapter.swift b/SentryTestUtils/TestTransportAdapter.swift index ce542ff88a0..e5c6c513dfc 100644 --- a/SentryTestUtils/TestTransportAdapter.swift +++ b/SentryTestUtils/TestTransportAdapter.swift @@ -6,17 +6,17 @@ public class TestTransportAdapter: SentryTransportAdapter { self.send(event, with: session, traceContext: nil, attachments: attachments) } - public var sentEventsWithSessionTraceState = Invocations<(event: Event, session: SentrySession, traceContext: SentryTraceContext?, attachments: [Attachment])>() - public override func send(_ event: Event, with session: SentrySession, traceContext: SentryTraceContext?, attachments: [Attachment]) { + public var sentEventsWithSessionTraceState = Invocations<(event: Event, session: SentrySession, traceContext: TraceContext?, attachments: [Attachment])>() + public override func send(_ event: Event, with session: SentrySession, traceContext: TraceContext?, attachments: [Attachment]) { sentEventsWithSessionTraceState.record((event, session, traceContext, attachments)) } - public var sendEventWithTraceStateInvocations = Invocations<(event: Event, traceContext: SentryTraceContext?, attachments: [Attachment], additionalEnvelopeItems: [SentryEnvelopeItem])>() - public override func send(event: Event, traceContext: SentryTraceContext?, attachments: [Attachment]) { + public var sendEventWithTraceStateInvocations = Invocations<(event: Event, traceContext: TraceContext?, attachments: [Attachment], additionalEnvelopeItems: [SentryEnvelopeItem])>() + public override func send(event: Event, traceContext: TraceContext?, attachments: [Attachment]) { sendEventWithTraceStateInvocations.record((event, traceContext, attachments, [])) } - public override func send(event: Event, traceContext: SentryTraceContext?, attachments: [Attachment], additionalEnvelopeItems: [SentryEnvelopeItem]) { + public override func send(event: Event, traceContext: TraceContext?, attachments: [Attachment], additionalEnvelopeItems: [SentryEnvelopeItem]) { sendEventWithTraceStateInvocations.record((event, traceContext, attachments, additionalEnvelopeItems)) } diff --git a/Sources/Sentry/Public/Sentry.h b/Sources/Sentry/Public/Sentry.h index 7971af35a16..83d298589f4 100644 --- a/Sources/Sentry/Public/Sentry.h +++ b/Sources/Sentry/Public/Sentry.h @@ -8,6 +8,7 @@ FOUNDATION_EXPORT double SentryVersionNumber; FOUNDATION_EXPORT const unsigned char SentryVersionString[]; # import +# import # import # import # import @@ -41,6 +42,7 @@ FOUNDATION_EXPORT const unsigned char SentryVersionString[]; # import # import # import +# import # import # import # import diff --git a/Sources/Sentry/include/SentryBaggage.h b/Sources/Sentry/Public/SentryBaggage.h similarity index 98% rename from Sources/Sentry/include/SentryBaggage.h rename to Sources/Sentry/Public/SentryBaggage.h index e62ca45cc9a..e306060f381 100644 --- a/Sources/Sentry/include/SentryBaggage.h +++ b/Sources/Sentry/Public/SentryBaggage.h @@ -6,6 +6,7 @@ NS_ASSUME_NONNULL_BEGIN static NSString *const SENTRY_BAGGAGE_HEADER = @"baggage"; +NS_SWIFT_NAME(Baggage) @interface SentryBaggage : NSObject /* diff --git a/Sources/Sentry/Public/SentrySpanProtocol.h b/Sources/Sentry/Public/SentrySpanProtocol.h index 4159d468f1b..4db933158f1 100644 --- a/Sources/Sentry/Public/SentrySpanProtocol.h +++ b/Sources/Sentry/Public/SentrySpanProtocol.h @@ -1,10 +1,9 @@ #import "SentryDefines.h" #import "SentrySerializable.h" #import "SentrySpanContext.h" - NS_ASSUME_NONNULL_BEGIN -@class SentrySpanId, SentryId, SentryTraceHeader, SentryMeasurementUnit; +@class SentrySpanId, SentryId, SentryTraceHeader, SentryMeasurementUnit, SentryTraceContext; NS_SWIFT_NAME(Span) @protocol SentrySpan @@ -80,6 +79,11 @@ NS_SWIFT_NAME(Span) */ @property (readonly) BOOL isFinished; +/** + * Retrieves a trace context from this tracer. + */ +@property (nullable, nonatomic, readonly) SentryTraceContext *traceContext; + /** * Starts a child span. * @param operation Short code identifying the type of operation the span is measuring. @@ -167,6 +171,12 @@ NS_SWIFT_NAME(Span) */ - (SentryTraceHeader *)toTraceHeader; +/** + * Returns the baggage http header + * @return NSString. + */ +- (nullable NSString *)baggageHttpHeader; + @end NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/include/SentryTraceContext.h b/Sources/Sentry/Public/SentryTraceContext.h similarity index 99% rename from Sources/Sentry/include/SentryTraceContext.h rename to Sources/Sentry/Public/SentryTraceContext.h index 9eed40b1f60..0d41a6d233e 100644 --- a/Sources/Sentry/include/SentryTraceContext.h +++ b/Sources/Sentry/Public/SentryTraceContext.h @@ -9,6 +9,7 @@ NS_ASSUME_NONNULL_BEGIN @class SentryScope, SentryOptions, SentryTracer, SentryUser, SentryBaggage; @class SentryId; +NS_SWIFT_NAME(TraceContext) @interface SentryTraceContext : NSObject /** diff --git a/Sources/Sentry/Public/SentryWithoutUIKit.h b/Sources/Sentry/Public/SentryWithoutUIKit.h index c812ce2b2bc..82b500bf1ee 100644 --- a/Sources/Sentry/Public/SentryWithoutUIKit.h +++ b/Sources/Sentry/Public/SentryWithoutUIKit.h @@ -9,6 +9,7 @@ FOUNDATION_EXPORT const unsigned char SentryVersionString[]; # import # import +# import # import # import # import @@ -42,6 +43,7 @@ FOUNDATION_EXPORT const unsigned char SentryVersionString[]; # import # import # import +# import # import # import # import diff --git a/Sources/Sentry/SentrySpan.m b/Sources/Sentry/SentrySpan.m index 5c5aa770bcc..f946cd7f2d6 100644 --- a/Sources/Sentry/SentrySpan.m +++ b/Sources/Sentry/SentrySpan.m @@ -1,3 +1,4 @@ +#import "SentryBaggage.h" #import "SentryCrashThread.h" #import "SentryDependencyContainer.h" #import "SentryFrame.h" @@ -13,6 +14,7 @@ #import "SentrySwift.h" #import "SentryThreadInspector.h" #import "SentryTime.h" +#import "SentryTraceContext.h" #import "SentryTraceHeader.h" #import "SentryTracer.h" @@ -298,6 +300,17 @@ - (SentryTraceHeader *)toTraceHeader sampled:self.sampled]; } +// Getter for the computed property baggage +- (nullable NSString *)baggageHttpHeader +{ + return [[self.tracer.traceContext toBaggage] toHTTPHeaderWithOriginalBaggage:nil]; +} + +- (nullable SentryTraceContext *)traceContext +{ + return self.tracer.traceContext; +} + - (LocalMetricsAggregator *)getLocalMetricsAggregator { if (localMetricsAggregator == nil) { diff --git a/Sources/Sentry/SentryTracer.m b/Sources/Sentry/SentryTracer.m index 98a310c3540..ab40cf526c1 100644 --- a/Sources/Sentry/SentryTracer.m +++ b/Sources/Sentry/SentryTracer.m @@ -412,14 +412,17 @@ - (void)spanFinished:(id)finishedSpan [self canBeFinished]; } -- (SentryTraceContext *)traceContext +- (nullable SentryTraceContext *)traceContext { if (_traceContext == nil) { @synchronized(self) { if (_traceContext == nil) { - _traceContext = [[SentryTraceContext alloc] initWithTracer:self - scope:_hub.scope - options:SentrySDK.options]; + _traceContext = [[SentryTraceContext alloc] + initWithTracer:self + scope:_hub.scope + options:_hub.client.options + ?: SentrySDK.options]; // We should remove static classes and always + // inject dependencies. } } } diff --git a/Sources/Sentry/include/HybridPublic/SentryEnvelope.h b/Sources/Sentry/include/HybridPublic/SentryEnvelope.h index 6caa365e029..76350d6b47a 100644 --- a/Sources/Sentry/include/HybridPublic/SentryEnvelope.h +++ b/Sources/Sentry/include/HybridPublic/SentryEnvelope.h @@ -1,10 +1,9 @@ #import "PrivatesHeader.h" #if COCOAPODS -@class SentrySdkInfo, SentryTraceContext; +@class SentrySdkInfo; #else # import "SentrySdkInfo.h" -# import "SentryTraceContext.h" #endif @@ -14,6 +13,7 @@ @class SentryUserFeedback; @class SentryAttachment; @class SentryEnvelopeItemHeader; +@class SentryTraceContext; NS_ASSUME_NONNULL_BEGIN diff --git a/Sources/Sentry/include/SentryPrivate.h b/Sources/Sentry/include/SentryPrivate.h index 41222128995..5d9f0e21906 100644 --- a/Sources/Sentry/include/SentryPrivate.h +++ b/Sources/Sentry/include/SentryPrivate.h @@ -1,5 +1,4 @@ // Sentry internal headers that are needed for swift code -#import "SentryBaggage.h" #import "SentryDispatchQueueWrapper.h" #import "SentryNSDataUtils.h" #import "SentryRandom.h" diff --git a/Sources/Sentry/include/SentryTracer.h b/Sources/Sentry/include/SentryTracer.h index 25a715adae4..b3c841b3b1b 100644 --- a/Sources/Sentry/include/SentryTracer.h +++ b/Sources/Sentry/include/SentryTracer.h @@ -43,11 +43,6 @@ static const NSTimeInterval SENTRY_AUTO_TRANSACTION_MAX_DURATION = 500.0; @property (nullable, nonatomic, copy) BOOL (^shouldIgnoreWaitForChildrenCallback)(id); -/** - * Retrieves a trace context from this tracer. - */ -@property (nonatomic, readonly) SentryTraceContext *traceContext; - /** * All the spans that where created with this tracer but rootSpan. */ diff --git a/Tests/SentryTests/Helper/SentrySerializationTests.swift b/Tests/SentryTests/Helper/SentrySerializationTests.swift index 7012a5b2263..b3d5fb5fec7 100644 --- a/Tests/SentryTests/Helper/SentrySerializationTests.swift +++ b/Tests/SentryTests/Helper/SentrySerializationTests.swift @@ -5,7 +5,7 @@ class SentrySerializationTests: XCTestCase { private class Fixture { static var invalidData = "hi".data(using: .utf8)! - static var traceContext = SentryTraceContext(trace: SentryId(), publicKey: "PUBLIC_KEY", releaseName: "RELEASE_NAME", environment: "TEST", transaction: "transaction", userSegment: "some segment", sampleRate: "0.25", sampled: "true", replayId: nil) + static var traceContext = TraceContext(trace: SentryId(), publicKey: "PUBLIC_KEY", releaseName: "RELEASE_NAME", environment: "TEST", transaction: "transaction", userSegment: "some segment", sampleRate: "0.25", sampled: "true", replayId: nil) } func testSerializationFailsWithInvalidJSONObject() { @@ -119,7 +119,7 @@ class SentrySerializationTests: XCTestCase { } func testSentryEnvelopeSerializer_TraceStateWithoutUser() throws { - let trace = SentryTraceContext(trace: SentryId(), publicKey: "PUBLIC_KEY", releaseName: "RELEASE_NAME", environment: "TEST", transaction: "transaction", userSegment: nil, sampleRate: nil, sampled: nil, replayId: nil) + let trace = TraceContext(trace: SentryId(), publicKey: "PUBLIC_KEY", releaseName: "RELEASE_NAME", environment: "TEST", transaction: "transaction", userSegment: nil, sampleRate: nil, sampled: nil, replayId: nil) let envelopeHeader = SentryEnvelopeHeader(id: nil, traceContext: trace) let envelope = SentryEnvelope(header: envelopeHeader, singleItem: createItemWithEmptyAttachment()) @@ -288,7 +288,7 @@ class SentrySerializationTests: XCTestCase { XCTAssertEqual(sdkInfo, deserializedEnvelope.header.sdkInfo) } - func assertTraceState(firstTrace: SentryTraceContext, secondTrace: SentryTraceContext) { + func assertTraceState(firstTrace: TraceContext, secondTrace: TraceContext) { XCTAssertEqual(firstTrace.traceId, secondTrace.traceId) XCTAssertEqual(firstTrace.publicKey, secondTrace.publicKey) XCTAssertEqual(firstTrace.releaseName, secondTrace.releaseName) diff --git a/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerIntegrationTests.swift b/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerIntegrationTests.swift index d3badd78bac..d4054c3c361 100644 --- a/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerIntegrationTests.swift +++ b/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerIntegrationTests.swift @@ -164,7 +164,7 @@ class SentryNetworkTrackerIntegrationTests: XCTestCase { self.assertNetworkError(error) let response = String(data: data ?? Data(), encoding: .utf8) ?? "" - let expectedBaggageHeader = transaction.traceContext.toBaggage().toHTTPHeader(withOriginalBaggage: nil) + let expectedBaggageHeader = transaction.traceContext?.toBaggage().toHTTPHeader(withOriginalBaggage: nil) XCTAssertEqual(expectedBaggageHeader, response) expect.fulfill() diff --git a/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerTests.swift b/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerTests.swift index 9509afa696a..99d7058a052 100644 --- a/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerTests.swift +++ b/Tests/SentryTests/Integrations/Performance/Network/SentryNetworkTrackerTests.swift @@ -665,7 +665,7 @@ class SentryNetworkTrackerTests: XCTestCase { let transaction = try XCTUnwrap(startTransaction() as? SentryTracer) sut.urlSessionTaskResume(task) - let expectedBaggageHeader = transaction.traceContext.toBaggage().toHTTPHeader(withOriginalBaggage: nil) + let expectedBaggageHeader = transaction.traceContext?.toBaggage().toHTTPHeader(withOriginalBaggage: nil) XCTAssertEqual(task.currentRequest?.allHTTPHeaderFields?["baggage"] ?? "", expectedBaggageHeader) } @@ -715,7 +715,7 @@ class SentryNetworkTrackerTests: XCTestCase { sut.urlSessionTaskResume(task) let expectedTraceHeader = SentrySDK.currentHub().scope.propagationContext.traceHeader.value() - let traceContext = SentryTraceContext(trace: SentrySDK.currentHub().scope.propagationContext.traceId, options: self.fixture.options, userSegment: self.fixture.scope.userObject?.segment, replayId: nil) + let traceContext = TraceContext(trace: SentrySDK.currentHub().scope.propagationContext.traceId, options: self.fixture.options, userSegment: self.fixture.scope.userObject?.segment, replayId: nil) let expectedBaggageHeader = traceContext.toBaggage().toHTTPHeader(withOriginalBaggage: nil) XCTAssertEqual(task.currentRequest?.allHTTPHeaderFields?["baggage"] ?? "", expectedBaggageHeader) XCTAssertEqual(task.currentRequest?.allHTTPHeaderFields?["sentry-trace"] ?? "", expectedTraceHeader) @@ -728,7 +728,7 @@ class SentryNetworkTrackerTests: XCTestCase { sut.urlSessionTaskResume(task) let expectedTraceHeader = SentrySDK.currentHub().scope.propagationContext.traceHeader.value() - let traceContext = SentryTraceContext(trace: SentrySDK.currentHub().scope.propagationContext.traceId, options: self.fixture.options, userSegment: self.fixture.scope.userObject?.segment, replayId: nil) + let traceContext = TraceContext(trace: SentrySDK.currentHub().scope.propagationContext.traceId, options: self.fixture.options, userSegment: self.fixture.scope.userObject?.segment, replayId: nil) let expectedBaggageHeader = traceContext.toBaggage().toHTTPHeader(withOriginalBaggage: nil) XCTAssertEqual(task.currentRequest?.allHTTPHeaderFields?["baggage"] ?? "", expectedBaggageHeader) XCTAssertEqual(task.currentRequest?.allHTTPHeaderFields?["sentry-trace"] ?? "", expectedTraceHeader) diff --git a/Tests/SentryTests/Protocol/SentryEnvelopeTests.swift b/Tests/SentryTests/Protocol/SentryEnvelopeTests.swift index c5f2648aebe..acabb00d528 100644 --- a/Tests/SentryTests/Protocol/SentryEnvelopeTests.swift +++ b/Tests/SentryTests/Protocol/SentryEnvelopeTests.swift @@ -156,7 +156,7 @@ class SentryEnvelopeTests: XCTestCase { func testInitSentryEnvelopeHeader_SetIdAndTraceState() { let eventId = SentryId() - let traceContext = SentryTraceContext(trace: SentryId(), publicKey: "publicKey", releaseName: "releaseName", environment: "environment", transaction: "transaction", userSegment: nil, sampleRate: nil, sampled: nil, replayId: nil) + let traceContext = TraceContext(trace: SentryId(), publicKey: "publicKey", releaseName: "releaseName", environment: "environment", transaction: "transaction", userSegment: nil, sampleRate: nil, sampled: nil, replayId: nil) let envelopeHeader = SentryEnvelopeHeader(id: eventId, traceContext: traceContext) XCTAssertEqual(eventId, envelopeHeader.eventId) diff --git a/Tests/SentryTests/SentryClientTests.swift b/Tests/SentryTests/SentryClientTests.swift index de775c16117..de9664bc0f4 100644 --- a/Tests/SentryTests/SentryClientTests.swift +++ b/Tests/SentryTests/SentryClientTests.swift @@ -687,7 +687,7 @@ class SentryClientTest: XCTestCase { try assertValidErrorEvent(eventWithSessionArguments.event, error) XCTAssertEqual(fixture.session, eventWithSessionArguments.session) - let expectedTraceContext = SentryTraceContext(trace: scope.propagationContext.traceId, options: Options(), userSegment: "segment", replayId: nil) + let expectedTraceContext = TraceContext(trace: scope.propagationContext.traceId, options: Options(), userSegment: "segment", replayId: nil) XCTAssertEqual(eventWithSessionArguments.traceContext?.traceId, expectedTraceContext.traceId) } diff --git a/Tests/SentryTests/SentrySDKTests.swift b/Tests/SentryTests/SentrySDKTests.swift index b108dd13339..b2e7f1ad392 100644 --- a/Tests/SentryTests/SentrySDKTests.swift +++ b/Tests/SentryTests/SentrySDKTests.swift @@ -398,7 +398,7 @@ class SentrySDKTests: XCTestCase { XCTAssertEqual(operation, transaction.operation) let tracer = try XCTUnwrap(transaction as? SentryTracer) - XCTAssertEqual(name, tracer.traceContext.transaction) + XCTAssertEqual(name, tracer.traceContext?.transaction) XCTAssertNil(SentrySDK.span) } @@ -410,7 +410,7 @@ class SentrySDKTests: XCTestCase { XCTAssertEqual(fixture.operation, transaction.operation) let tracer = try XCTUnwrap(transaction as? SentryTracer) - XCTAssertEqual(fixture.transactionName, tracer.traceContext.transaction) + XCTAssertEqual(fixture.transactionName, tracer.traceContext?.transaction) XCTAssertEqual(.custom, tracer.transactionContext.nameSource) let newSpan = SentrySDK.span diff --git a/Tests/SentryTests/SentryTests-Bridging-Header.h b/Tests/SentryTests/SentryTests-Bridging-Header.h index b60da6ae8e0..c1c12813962 100644 --- a/Tests/SentryTests/SentryTests-Bridging-Header.h +++ b/Tests/SentryTests/SentryTests-Bridging-Header.h @@ -215,7 +215,6 @@ #import "SentryThreadWrapper.h" #import "SentryTime.h" #import "SentryTimeToDisplayTracker.h" -#import "SentryTraceContext.h" #import "SentryTraceOrigins.h" #import "SentryTracer+Private.h" #import "SentryTracer+Test.h" diff --git a/Tests/SentryTests/Transaction/SentryBaggageTests.swift b/Tests/SentryTests/Transaction/SentryBaggageTests.swift index 330e4bb008d..e8bed7def58 100644 --- a/Tests/SentryTests/Transaction/SentryBaggageTests.swift +++ b/Tests/SentryTests/Transaction/SentryBaggageTests.swift @@ -5,13 +5,13 @@ import XCTest class SentryBaggageTests: XCTestCase { func test_baggageToHeader_AppendToOriginal() { - let header = SentryBaggage(trace: SentryId.empty, publicKey: "publicKey", releaseName: "release name", environment: "teste", transaction: "transaction", userSegment: "test user", sampleRate: "0.49", sampled: "true", replayId: "some_replay_id").toHTTPHeader(withOriginalBaggage: ["a": "a", "sentry-trace_id": "to-be-overwritten"]) + let header = Baggage(trace: SentryId.empty, publicKey: "publicKey", releaseName: "release name", environment: "teste", transaction: "transaction", userSegment: "test user", sampleRate: "0.49", sampled: "true", replayId: "some_replay_id").toHTTPHeader(withOriginalBaggage: ["a": "a", "sentry-trace_id": "to-be-overwritten"]) XCTAssertEqual(header, "a=a,sentry-environment=teste,sentry-public_key=publicKey,sentry-release=release%20name,sentry-replay_id=some_replay_id,sentry-sample_rate=0.49,sentry-sampled=true,sentry-trace_id=00000000000000000000000000000000,sentry-transaction=transaction,sentry-user_segment=test%20user") } func test_baggageToHeader_onlyTrace_ignoreNils() { - let header = SentryBaggage(trace: SentryId.empty, publicKey: "publicKey", releaseName: nil, environment: nil, transaction: nil, userSegment: nil, sampleRate: nil, sampled: nil, replayId: nil).toHTTPHeader(withOriginalBaggage: nil) + let header = Baggage(trace: SentryId.empty, publicKey: "publicKey", releaseName: nil, environment: nil, transaction: nil, userSegment: nil, sampleRate: nil, sampled: nil, replayId: nil).toHTTPHeader(withOriginalBaggage: nil) XCTAssertEqual(header, "sentry-public_key=publicKey,sentry-trace_id=00000000000000000000000000000000") } diff --git a/Tests/SentryTests/Transaction/SentrySpanTests.swift b/Tests/SentryTests/Transaction/SentrySpanTests.swift index 0133c8eeb66..b52f6109517 100644 --- a/Tests/SentryTests/Transaction/SentrySpanTests.swift +++ b/Tests/SentryTests/Transaction/SentrySpanTests.swift @@ -676,6 +676,22 @@ class SentrySpanTests: XCTestCase { XCTAssertEqual(nameForSentrySpanStatus(.dataLoss), kSentrySpanStatusNameDataLoss) } + func testTraceContext() { + let client = TestClient(options: fixture.options)! + let sut = fixture.getSut(client: client) as! SentrySpan + + let expectedTraceContext = sut.tracer?.traceContext + XCTAssertEqual(expectedTraceContext, sut.traceContext) + } + + func testBaggageHttpHeader() { + let client = TestClient(options: fixture.options)! + let sut = fixture.getSut(client: client) as! SentrySpan + + let expectedBaggage = sut.tracer?.traceContext?.toBaggage().toHTTPHeader(withOriginalBaggage: nil) + XCTAssertEqual(expectedBaggage, sut.baggageHttpHeader()) + } + #if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) func testAddSlowFrozenFramesToData() { let (displayLinkWrapper, framesTracker) = givenFramesTracker() diff --git a/Tests/SentryTests/Transaction/SentryTraceStateTests.swift b/Tests/SentryTests/Transaction/SentryTraceStateTests.swift index 3d5233b4c08..2503cbf0909 100644 --- a/Tests/SentryTests/Transaction/SentryTraceStateTests.swift +++ b/Tests/SentryTests/Transaction/SentryTraceStateTests.swift @@ -55,7 +55,7 @@ class SentryTraceContextTests: XCTestCase { } func testInit() { - let traceContext = SentryTraceContext( + let traceContext = TraceContext( trace: fixture.traceId, publicKey: fixture.publicKey, releaseName: fixture.releaseName, @@ -71,26 +71,26 @@ class SentryTraceContextTests: XCTestCase { } func testInitWithScopeOptions() { - let traceContext = SentryTraceContext(scope: fixture.scope, options: fixture.options)! + let traceContext = TraceContext(scope: fixture.scope, options: fixture.options)! assertTraceState(traceContext: traceContext) } func testInitWithTracerScopeOptions() { - let traceContext = SentryTraceContext(tracer: fixture.tracer, scope: fixture.scope, options: fixture.options) + let traceContext = TraceContext(tracer: fixture.tracer, scope: fixture.scope, options: fixture.options) assertTraceState(traceContext: traceContext!) } func testInitWithTracerNotSampled() { let tracer = fixture.tracer tracer.sampled = .no - let traceContext = SentryTraceContext(tracer: tracer, scope: fixture.scope, options: fixture.options) + let traceContext = TraceContext(tracer: tracer, scope: fixture.scope, options: fixture.options) XCTAssertEqual(traceContext?.sampled, "false") } func testInitNil() { fixture.scope.span = nil - let traceContext = SentryTraceContext(scope: fixture.scope, options: fixture.options) + let traceContext = TraceContext(scope: fixture.scope, options: fixture.options) XCTAssertNil(traceContext) } @@ -99,7 +99,7 @@ class SentryTraceContextTests: XCTestCase { options.dsn = TestConstants.realDSN let traceId = SentryId() - let traceContext = SentryTraceContext(trace: traceId, options: options, userSegment: "segment", replayId: "replayId") + let traceContext = TraceContext(trace: traceId, options: options, userSegment: "segment", replayId: "replayId") XCTAssertEqual(options.parsedDsn?.url.user, traceContext.publicKey) XCTAssertEqual(traceId, traceContext.traceId) @@ -117,7 +117,7 @@ class SentryTraceContextTests: XCTestCase { options.dsn = TestConstants.realDSN let traceId = SentryId() - let traceContext = SentryTraceContext(trace: traceId, options: options, userSegment: nil, replayId: nil) + let traceContext = TraceContext(trace: traceId, options: options, userSegment: nil, replayId: nil) XCTAssertEqual(options.parsedDsn?.url.user, traceContext.publicKey) XCTAssertEqual(traceId, traceContext.traceId) @@ -130,7 +130,7 @@ class SentryTraceContextTests: XCTestCase { } func test_toBaggage() { - let traceContext = SentryTraceContext( + let traceContext = TraceContext( trace: fixture.traceId, publicKey: fixture.publicKey, releaseName: fixture.releaseName, @@ -153,7 +153,7 @@ class SentryTraceContextTests: XCTestCase { XCTAssertEqual(baggage.replayId, fixture.replayId) } - func assertTraceState(traceContext: SentryTraceContext) { + func assertTraceState(traceContext: TraceContext) { XCTAssertEqual(traceContext.traceId, fixture.traceId) XCTAssertEqual(traceContext.publicKey, fixture.publicKey) XCTAssertEqual(traceContext.releaseName, fixture.releaseName)