Skip to content

Commit d7dcd2c

Browse files
authored
chore: Convert SentryAutoSessionTrackingIntegration to Swift (#6961)
* Convert `SentryAutoSessionTrackingIntegration` to Swift * Add log message * Use `enableWatchdogTerminationTracking` * Enable auto session tracking in SentrySessionGeneratorTests * Remove `SentryAutoSessionTrackingIntegration.stop()`
1 parent 4b6ec4f commit d7dcd2c

16 files changed

+71
-122
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
0A9BF4EB28A127120068D266 /* SentryViewHierarchyIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A9BF4EA28A127120068D266 /* SentryViewHierarchyIntegrationTests.swift */; };
4848
0A9E917128DC7E7000FB4182 /* SentryInternalCDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = 0A9E917028DC7E7000FB4182 /* SentryInternalCDefines.h */; };
4949
0ADC33F128D9BE940078D980 /* TestSentryUIDeviceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ADC33EF28D9BE690078D980 /* TestSentryUIDeviceWrapper.swift */; };
50-
15360CD62432832400112302 /* SentryAutoSessionTrackingIntegration.m in Sources */ = {isa = PBXBuildFile; fileRef = 15360CD52432832400112302 /* SentryAutoSessionTrackingIntegration.m */; };
51-
15360CD92432835400112302 /* SentryAutoSessionTrackingIntegration.h in Headers */ = {isa = PBXBuildFile; fileRef = 15360CD82432835400112302 /* SentryAutoSessionTrackingIntegration.h */; settings = {ATTRIBUTES = (Private, ); }; };
5250
15360CED2433A15500112302 /* SentryInstallation.m in Sources */ = {isa = PBXBuildFile; fileRef = 15360CEC2433A15500112302 /* SentryInstallation.m */; };
5351
15360CF02433A16D00112302 /* SentryInstallation.h in Headers */ = {isa = PBXBuildFile; fileRef = 15360CEF2433A16D00112302 /* SentryInstallation.h */; };
5452
15D0AC882459EE4D006541C2 /* SentryNSURLRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15D0AC872459EE4D006541C2 /* SentryNSURLRequestTests.swift */; };
@@ -973,6 +971,7 @@
973971
F429D39A2E85360F00DBF387 /* RetryAfterHeaderParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = F429D3992E85360F00DBF387 /* RetryAfterHeaderParser.swift */; };
974972
F429D3AA2E8562EF00DBF387 /* RateLimitParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = F429D3A82E8562EF00DBF387 /* RateLimitParser.swift */; };
975973
F443DB272E09BE8C009A9045 /* LoadValidatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F443DB262E09BE8C009A9045 /* LoadValidatorTests.swift */; };
974+
F44544012EDF5A6200EFE964 /* SentryAutoSessionTrackingIntegration.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44544002EDF5A5C00EFE964 /* SentryAutoSessionTrackingIntegration.swift */; };
976975
F44858132E03579D0013E63B /* SentryCrashDynamicLinker+Test.h in Headers */ = {isa = PBXBuildFile; fileRef = F44858122E0357940013E63B /* SentryCrashDynamicLinker+Test.h */; };
977976
F44D2B592E6B779E00FF31FA /* SentryScreenFrames.swift in Sources */ = {isa = PBXBuildFile; fileRef = F44D2B582E6B779E00FF31FA /* SentryScreenFrames.swift */; };
978977
F44D2B5C2E6B7E8700FF31FA /* SentryProfilingScreenFramesHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = F44D2B5A2E6B7E8700FF31FA /* SentryProfilingScreenFramesHelper.h */; };
@@ -1324,8 +1323,6 @@
13241323
0A9BF4EA28A127120068D266 /* SentryViewHierarchyIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryViewHierarchyIntegrationTests.swift; sourceTree = "<group>"; };
13251324
0A9E917028DC7E7000FB4182 /* SentryInternalCDefines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryInternalCDefines.h; path = include/SentryInternalCDefines.h; sourceTree = "<group>"; };
13261325
0ADC33EF28D9BE690078D980 /* TestSentryUIDeviceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestSentryUIDeviceWrapper.swift; sourceTree = "<group>"; };
1327-
15360CD52432832400112302 /* SentryAutoSessionTrackingIntegration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryAutoSessionTrackingIntegration.m; sourceTree = "<group>"; };
1328-
15360CD82432835400112302 /* SentryAutoSessionTrackingIntegration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryAutoSessionTrackingIntegration.h; path = include/SentryAutoSessionTrackingIntegration.h; sourceTree = "<group>"; };
13291326
15360CEC2433A15500112302 /* SentryInstallation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryInstallation.m; sourceTree = "<group>"; };
13301327
15360CEF2433A16D00112302 /* SentryInstallation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryInstallation.h; path = include/SentryInstallation.h; sourceTree = "<group>"; };
13311328
15D0AC872459EE4D006541C2 /* SentryNSURLRequestTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSURLRequestTests.swift; sourceTree = "<group>"; };
@@ -2353,6 +2350,7 @@
23532350
F429D3992E85360F00DBF387 /* RetryAfterHeaderParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RetryAfterHeaderParser.swift; sourceTree = "<group>"; };
23542351
F429D3A82E8562EF00DBF387 /* RateLimitParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RateLimitParser.swift; sourceTree = "<group>"; };
23552352
F443DB262E09BE8C009A9045 /* LoadValidatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadValidatorTests.swift; sourceTree = "<group>"; };
2353+
F44544002EDF5A5C00EFE964 /* SentryAutoSessionTrackingIntegration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryAutoSessionTrackingIntegration.swift; sourceTree = "<group>"; };
23562354
F44858122E0357940013E63B /* SentryCrashDynamicLinker+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryCrashDynamicLinker+Test.h"; sourceTree = "<group>"; };
23572355
F44D2B582E6B779E00FF31FA /* SentryScreenFrames.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryScreenFrames.swift; sourceTree = "<group>"; };
23582356
F44D2B5A2E6B7E8700FF31FA /* SentryProfilingScreenFramesHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryProfilingScreenFramesHelper.h; sourceTree = "<group>"; };
@@ -3687,8 +3685,6 @@
36873685
7BE0DC36272AE80A004FA8B7 /* Session */ = {
36883686
isa = PBXGroup;
36893687
children = (
3690-
15360CD82432835400112302 /* SentryAutoSessionTrackingIntegration.h */,
3691-
15360CD52432832400112302 /* SentryAutoSessionTrackingIntegration.m */,
36923688
7B4E23BD251A2BD500060D68 /* SentryCrashIntegrationSessionHandler.h */,
36933689
7B4E23C1251A2C2B00060D68 /* SentryCrashIntegrationSessionHandler.m */,
36943690
);
@@ -5064,6 +5060,7 @@
50645060
FAB0073C2E9F47DE001C806A /* Session */ = {
50655061
isa = PBXGroup;
50665062
children = (
5063+
F44544002EDF5A5C00EFE964 /* SentryAutoSessionTrackingIntegration.swift */,
50675064
FAB007422E9F47E4001C806A /* SessionTracker.swift */,
50685065
);
50695066
path = Session;
@@ -5298,7 +5295,6 @@
52985295
63FE715B20DA4C1100CDBAE8 /* SentryCrashSignalInfo.h in Headers */,
52995296
63FE70E520DA4C1000CDBAE8 /* SentryCrashMonitor_CPPException.h in Headers */,
53005297
7B127B0D27CF6F2300A71ED2 /* SentryANRTrackingIntegration.h in Headers */,
5301-
15360CD92432835400112302 /* SentryAutoSessionTrackingIntegration.h in Headers */,
53025298
8E564AF0267AF24400FE117D /* SentryNetworkTrackingIntegration.h in Headers */,
53035299
D867063E27C3BC2400048851 /* SentryCoreDataSwizzling.h in Headers */,
53045300
7D9B07A023D1E89900C5FC8E /* SentryMeta.h in Headers */,
@@ -5809,7 +5805,6 @@
58095805
63FE712920DA4C1000CDBAE8 /* SentryCrashCPU_arm.c in Sources */,
58105806
03F84D3427DD4191008FE43F /* SentryThreadMetadataCache.cpp in Sources */,
58115807
62862B1E2B1DDC35009B16E3 /* SentryDelayedFrame.m in Sources */,
5812-
15360CD62432832400112302 /* SentryAutoSessionTrackingIntegration.m in Sources */,
58135808
848A451D2BBF9504006AAAEC /* SentryProfilerTestHelpers.m in Sources */,
58145809
7B63459F280EBA7200CFA05A /* SentryUIEventTracker.m in Sources */,
58155810
7BF9EF782722B35D00B5BBEF /* SentrySubClassFinder.m in Sources */,
@@ -6102,6 +6097,7 @@
61026097
D88817D826D7149100BF2251 /* SentryTraceContext.m in Sources */,
61036098
D8F67B1B2BE9728600C9197B /* SentrySRDefaultBreadcrumbConverter.swift in Sources */,
61046099
8EBF870926140D37001A6853 /* SentryPerformanceTracker.m in Sources */,
6100+
F44544012EDF5A6200EFE964 /* SentryAutoSessionTrackingIntegration.swift in Sources */,
61056101
D865893029D6ECA7000BE151 /* SentryCrashBinaryImageCache.c in Sources */,
61066102
D859696B27BECD8F0036A46E /* SentryCoreDataTrackingIntegration.m in Sources */,
61076103
7BD86EC7264A641D005439DB /* SentrySysctlObjC.m in Sources */,

Sources/Sentry/SentryAutoSessionTrackingIntegration.m

Lines changed: 0 additions & 47 deletions
This file was deleted.

Sources/Sentry/SentryBaseIntegration.m

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ - (BOOL)shouldBeEnabledWithOptions:(SentryOptions *)options
3434
return YES;
3535
}
3636

37-
if ((integrationOptions & kIntegrationOptionEnableAutoSessionTracking)
38-
&& !options.enableAutoSessionTracking) {
39-
[self logWithOptionName:@"enableAutoSessionTracking"];
40-
return NO;
41-
}
42-
4337
if ((integrationOptions & kIntegrationOptionEnableWatchdogTerminationTracking)
4438
&& !options.enableWatchdogTerminationTracking) {
4539
[self logWithOptionName:@"enableWatchdogTerminationTracking"];

Sources/Sentry/SentrySDKInternal.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#import "SentryANRTrackingIntegration.h"
44
#import "SentryAppStartMeasurement.h"
55
#import "SentryAutoBreadcrumbTrackingIntegration.h"
6-
#import "SentryAutoSessionTrackingIntegration.h"
76
#import "SentryBreadcrumb.h"
87
#import "SentryClient+Private.h"
98
#import "SentryCoreDataTrackingIntegration.h"
@@ -528,8 +527,8 @@ + (void)endSession
528527
[SentryScreenshotIntegration class],
529528
#endif // SENTRY_TARGET_REPLAY_SUPPORTED
530529
[SentryANRTrackingIntegration class], [SentryAutoBreadcrumbTrackingIntegration class],
531-
[SentryAutoSessionTrackingIntegration class], [SentryCoreDataTrackingIntegration class],
532-
[SentryFileIOTrackingIntegration class], [SentryNetworkTrackingIntegration class], nil];
530+
[SentryCoreDataTrackingIntegration class], [SentryFileIOTrackingIntegration class],
531+
[SentryNetworkTrackingIntegration class], nil];
533532

534533
#if SENTRY_HAS_METRIC_KIT
535534
[defaultIntegrations addObject:[SentryMetricKitIntegration class]];

Sources/Sentry/include/SentryAutoSessionTrackingIntegration.h

Lines changed: 0 additions & 14 deletions
This file was deleted.

Sources/Sentry/include/SentryBaseIntegration.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ NS_ASSUME_NONNULL_BEGIN
1010

1111
typedef NS_OPTIONS(NSUInteger, SentryIntegrationOption) {
1212
kIntegrationOptionNone = 0,
13-
kIntegrationOptionEnableAutoSessionTracking = 1 << 0,
1413
kIntegrationOptionEnableWatchdogTerminationTracking = 1 << 1,
1514
kIntegrationOptionEnableAutoPerformanceTracing = 1 << 2,
1615
kIntegrationOptionEnableUIViewControllerTracing = 1 << 3,

Sources/Swift/Core/Integrations/Integrations.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ private struct AnyIntegration {
3434
@_spi(Private) @objc public final class SentrySwiftIntegrationInstaller: NSObject {
3535
@objc public class func install(with options: Options) {
3636
let dependencies = SentryDependencyContainer.sharedInstance()
37-
let commonIntegrations: [AnyIntegration] = [.init(SwiftAsyncIntegration.self)]
37+
let commonIntegrations: [AnyIntegration] = [
38+
.init(SwiftAsyncIntegration.self),
39+
.init(SentryAutoSessionTrackingIntegration.self)
40+
]
3841
#if os(iOS) && !SENTRY_NO_UIKIT
3942
let integrations: [AnyIntegration] = commonIntegrations + [.init(UserFeedbackIntegration<SentryDependencyContainer>.self)]
4043
#else
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@_implementationOnly import _SentryPrivate
2+
3+
protocol SessionTrackerProvider {
4+
func getSessionTracker(with options: Options) -> SessionTracker
5+
}
6+
7+
final class SentryAutoSessionTrackingIntegration<Dependencies: SessionTrackerProvider>: NSObject, SwiftIntegration {
8+
let tracker: SessionTracker
9+
10+
init?(with options: Options, dependencies: Dependencies) {
11+
guard options.enableAutoSessionTracking else {
12+
SentrySDKLog.debug("Not going to enable \(Self.name) because enableAutoSessionTracking is disabled.")
13+
return nil
14+
}
15+
16+
tracker = dependencies.getSessionTracker(with: options)
17+
tracker.start()
18+
}
19+
20+
func uninstall() {
21+
tracker.stop()
22+
}
23+
24+
static var name: String {
25+
"SentryAutoSessionTrackingIntegration"
26+
}
27+
}

Sources/Swift/SentryDependencyContainer.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,5 @@ extension SentryFileManager: SentryFileManagerProtocol { }
256256
#if os(iOS) && !SENTRY_NO_UIKIT
257257
extension SentryDependencyContainer: ScreenshotSourceProvider { }
258258
#endif
259+
260+
extension SentryDependencyContainer: SessionTrackerProvider { }

Tests/SentryProfilerTests/SentryProfilingPublicAPITests.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class SentryProfilingPublicAPITests: XCTestCase {
1111
let options = Options.noIntegrations()
1212
options.dsn = TestConstants.dsnAsString(username: "SentrySDKTests")
1313
options.releaseName = "1.0.0"
14+
options.enableAutoSessionTracking = false
1415
return options
1516
}()
1617

@@ -57,12 +58,6 @@ class SentryProfilingPublicAPITests: XCTestCase {
5758

5859
givenSdkWithHubButNoClient()
5960

60-
if let autoSessionTracking = SentrySDKInternal.currentHub().installedIntegrations().first(where: { it in
61-
it is SentryAutoSessionTrackingIntegration
62-
}) as? SentryAutoSessionTrackingIntegration {
63-
autoSessionTracking.stop()
64-
}
65-
6661
clearTestState()
6762
}
6863
}

0 commit comments

Comments
 (0)