Skip to content

Commit 2137530

Browse files
authored
ref: Convert SentryRandom to Swift (#6022)
* ref: Convert `SentryRandom` to Swift * Increase range to allow up to 1
1 parent ef2c9b3 commit 2137530

File tree

16 files changed

+34
-66
lines changed

16 files changed

+34
-66
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,6 @@
734734
8E0551E026A7A63C00400526 /* TestProtocolClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E0551DF26A7A63C00400526 /* TestProtocolClient.swift */; };
735735
8E133FA225E72DEF00ABD0BF /* SentrySamplingContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E133FA025E72DEF00ABD0BF /* SentrySamplingContext.m */; };
736736
8E133FA625E72EB400ABD0BF /* SentrySamplingContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 8E133FA525E72EB400ABD0BF /* SentrySamplingContext.h */; settings = {ATTRIBUTES = (Public, ); }; };
737-
8E25C95325F836D000DC215B /* SentryRandom.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E25C95125F836D000DC215B /* SentryRandom.m */; };
738-
8E25C95725F836EE00DC215B /* SentryRandom.h in Headers */ = {isa = PBXBuildFile; fileRef = 8E25C95625F836EE00DC215B /* SentryRandom.h */; };
739737
8E4A037825F6F52100000D77 /* SentrySampleDecision.h in Headers */ = {isa = PBXBuildFile; fileRef = 8E4A037725F6F52100000D77 /* SentrySampleDecision.h */; settings = {ATTRIBUTES = (Public, ); }; };
740738
8E4E7C6D25DAAAFE006AB9E2 /* SentryTransaction.h in Headers */ = {isa = PBXBuildFile; fileRef = 8E4E7C6B25DAAAFE006AB9E2 /* SentryTransaction.h */; };
741739
8E4E7C6E25DAAAFE006AB9E2 /* SentrySpan.h in Headers */ = {isa = PBXBuildFile; fileRef = 8E4E7C6C25DAAAFE006AB9E2 /* SentrySpan.h */; };
@@ -1038,8 +1036,8 @@
10381036
F48F74F32E5F9959009D4E7D /* SentryCrashBinaryImageCacheTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F48F74F22E5F9959009D4E7D /* SentryCrashBinaryImageCacheTests.m */; };
10391037
F48F75712E5FA630009D4E7D /* SentryBinaryImageCacheCallbacks.m in Sources */ = {isa = PBXBuildFile; fileRef = F48F75702E5FA630009D4E7D /* SentryBinaryImageCacheCallbacks.m */; };
10401038
F48F75732E5FA649009D4E7D /* SentryBinaryImageCacheCallbacks.h in Headers */ = {isa = PBXBuildFile; fileRef = F48F75722E5FA649009D4E7D /* SentryBinaryImageCacheCallbacks.h */; };
1041-
F49236EB2E5E4B2F00663673 /* SentryBinaryImageCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = F49236EA2E5E4B2F00663673 /* SentryBinaryImageCache.swift */; };
10421039
F48F767C2E60B555009D4E7D /* SentryNSTimerFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = F48F767B2E60B555009D4E7D /* SentryNSTimerFactory.swift */; };
1040+
F49236EB2E5E4B2F00663673 /* SentryBinaryImageCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = F49236EA2E5E4B2F00663673 /* SentryBinaryImageCache.swift */; };
10431041
F49D41982DEA27AF00D9244E /* SentryUseNSExceptionCallstackWrapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F49D41972DEA27AF00D9244E /* SentryUseNSExceptionCallstackWrapperTests.swift */; };
10441042
F49D419A2DEA2FB000D9244E /* SentryCrashExceptionApplicationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F49D41992DEA2FB000D9244E /* SentryCrashExceptionApplicationTests.swift */; };
10451043
F49D419C2DEA30C300D9244E /* SentryCrashExceptionApplicationHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = F49D419B2DEA30B800D9244E /* SentryCrashExceptionApplicationHelper.h */; };
@@ -1050,6 +1048,7 @@
10501048
F4DCC9DD2E4AA9D0008ECE45 /* SentrySDKSettingsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4DCC9DC2E4AA9D0008ECE45 /* SentrySDKSettingsTests.swift */; };
10511049
F4DCC9E52E4AACE0008ECE45 /* SentrySDKSettings+Equality.m in Sources */ = {isa = PBXBuildFile; fileRef = F4DCC9E42E4AACE0008ECE45 /* SentrySDKSettings+Equality.m */; };
10521050
F4E3DCCB2E1579240093CB80 /* SentryScopePersistentStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4E3DCCA2E1579240093CB80 /* SentryScopePersistentStore.swift */; };
1051+
F4FE9DBD2E621F100014FED5 /* SentryRandom.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FE9DBC2E621F100014FED5 /* SentryRandom.swift */; };
10531052
FA034AC82DD3DB4900FE3107 /* SentryIntegrationProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = FA034AC72DD3DB4900FE3107 /* SentryIntegrationProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
10541053
FA21F0B42E4A2A80008B4E5A /* SentryAppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA4C32972DF7513F001D7B01 /* SentryAppState.swift */; };
10551054
FA3734822E0EEA670091EF24 /* SentryScreenshot.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA3734812E0EEA670091EF24 /* SentryScreenshot.swift */; };
@@ -2050,8 +2049,6 @@
20502049
8E0551DF26A7A63C00400526 /* TestProtocolClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestProtocolClient.swift; sourceTree = "<group>"; };
20512050
8E133FA025E72DEF00ABD0BF /* SentrySamplingContext.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySamplingContext.m; sourceTree = "<group>"; };
20522051
8E133FA525E72EB400ABD0BF /* SentrySamplingContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentrySamplingContext.h; path = Public/SentrySamplingContext.h; sourceTree = "<group>"; };
2053-
8E25C95125F836D000DC215B /* SentryRandom.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryRandom.m; sourceTree = "<group>"; };
2054-
8E25C95625F836EE00DC215B /* SentryRandom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryRandom.h; path = include/SentryRandom.h; sourceTree = "<group>"; };
20552052
8E25C97425F8511A00DC215B /* TestRandom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestRandom.swift; sourceTree = "<group>"; };
20562053
8E4A037725F6F52100000D77 /* SentrySampleDecision.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentrySampleDecision.h; path = Public/SentrySampleDecision.h; sourceTree = "<group>"; };
20572054
8E4A037D25F76A1D00000D77 /* Dynamic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dynamic.swift; sourceTree = "<group>"; };
@@ -2383,8 +2380,8 @@
23832380
F48F74F22E5F9959009D4E7D /* SentryCrashBinaryImageCacheTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryCrashBinaryImageCacheTests.m; sourceTree = "<group>"; };
23842381
F48F75702E5FA630009D4E7D /* SentryBinaryImageCacheCallbacks.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryBinaryImageCacheCallbacks.m; sourceTree = "<group>"; };
23852382
F48F75722E5FA649009D4E7D /* SentryBinaryImageCacheCallbacks.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryBinaryImageCacheCallbacks.h; path = ../../Sentry/include/SentryBinaryImageCacheCallbacks.h; sourceTree = "<group>"; };
2386-
F49236EA2E5E4B2F00663673 /* SentryBinaryImageCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryBinaryImageCache.swift; sourceTree = "<group>"; };
23872383
F48F767B2E60B555009D4E7D /* SentryNSTimerFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSTimerFactory.swift; sourceTree = "<group>"; };
2384+
F49236EA2E5E4B2F00663673 /* SentryBinaryImageCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryBinaryImageCache.swift; sourceTree = "<group>"; };
23882385
F49D41972DEA27AF00D9244E /* SentryUseNSExceptionCallstackWrapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUseNSExceptionCallstackWrapperTests.swift; sourceTree = "<group>"; };
23892386
F49D41992DEA2FB000D9244E /* SentryCrashExceptionApplicationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCrashExceptionApplicationTests.swift; sourceTree = "<group>"; };
23902387
F49D419B2DEA30B800D9244E /* SentryCrashExceptionApplicationHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryCrashExceptionApplicationHelper.h; path = include/SentryCrashExceptionApplicationHelper.h; sourceTree = "<group>"; };
@@ -2396,6 +2393,7 @@
23962393
F4DCC9E32E4AACE0008ECE45 /* SentrySDKSettings+Equality.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentrySDKSettings+Equality.h"; sourceTree = "<group>"; };
23972394
F4DCC9E42E4AACE0008ECE45 /* SentrySDKSettings+Equality.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "SentrySDKSettings+Equality.m"; sourceTree = "<group>"; };
23982395
F4E3DCCA2E1579240093CB80 /* SentryScopePersistentStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryScopePersistentStore.swift; sourceTree = "<group>"; };
2396+
F4FE9DBC2E621F100014FED5 /* SentryRandom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryRandom.swift; sourceTree = "<group>"; };
23992397
FA034AC72DD3DB4900FE3107 /* SentryIntegrationProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryIntegrationProtocol.h; path = Public/SentryIntegrationProtocol.h; sourceTree = "<group>"; };
24002398
FA3734812E0EEA670091EF24 /* SentryScreenshot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryScreenshot.swift; sourceTree = "<group>"; };
24012399
FA3734832E0F07A20091EF24 /* SentryDependencyContainerSwiftHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryDependencyContainerSwiftHelper.h; path = include/SentryDependencyContainerSwiftHelper.h; sourceTree = "<group>"; };
@@ -2600,6 +2598,7 @@
26002598
621D9F2D2B9B030E003D94DE /* Helper */ = {
26012599
isa = PBXGroup;
26022600
children = (
2601+
F4FE9DBC2E621F100014FED5 /* SentryRandom.swift */,
26032602
F48F767B2E60B555009D4E7D /* SentryNSTimerFactory.swift */,
26042603
FABE8E162E307A7C0040809A /* Dependencies.swift */,
26052604
FABE8E142E307A5C0040809A /* SentrySDK.swift */,
@@ -4134,8 +4133,6 @@
41344133
8E25C94F25F836AB00DC215B /* Tools */ = {
41354134
isa = PBXGroup;
41364135
children = (
4137-
8E25C95625F836EE00DC215B /* SentryRandom.h */,
4138-
8E25C95125F836D000DC215B /* SentryRandom.m */,
41394136
D406044A2DD2483D00C40DC0 /* SentryApplication.h */,
41404137
D8C67E9928000E23007E326E /* SentryUIApplication.h */,
41414138
D85852B827EDDC5900C6D8AE /* SentryUIApplication.m */,
@@ -5161,7 +5158,6 @@
51615158
638DC9A01EBC6B6400A66E41 /* SentryRequestOperation.h in Headers */,
51625159
7B7A599526B692540060A676 /* SentryScreenFrames.h in Headers */,
51635160
6344DDB01EC308E400D9160D /* SentryCrashInstallationReporter.h in Headers */,
5164-
8E25C95725F836EE00DC215B /* SentryRandom.h in Headers */,
51655161
7B5CAF7527F5A67C00ED0DB6 /* SentryNSURLRequestBuilder.h in Headers */,
51665162
63FE70ED20DA4C1000CDBAE8 /* SentryCrashMonitor_NSException.h in Headers */,
51675163
7BA61CB4247BC3EB00C130A8 /* SentryCrashBinaryImageProvider.h in Headers */,
@@ -5879,7 +5875,6 @@
58795875
63FE70DB20DA4C1000CDBAE8 /* SentryCrashMonitor_System.m in Sources */,
58805876
7BA61CBB247BC5D800C130A8 /* SentryCrashDefaultBinaryImageProvider.m in Sources */,
58815877
63FE713120DA4C1100CDBAE8 /* SentryCrashDynamicLinker.c in Sources */,
5882-
8E25C95325F836D000DC215B /* SentryRandom.m in Sources */,
58835878
03F84D3527DD4191008FE43F /* SentryThreadHandle.cpp in Sources */,
58845879
0A2D8DA9289BC905008720F6 /* SentryViewHierarchyProvider.m in Sources */,
58855880
D84D2CDD2C2BF7370011AF8A /* SentryReplayEvent.swift in Sources */,
@@ -5930,6 +5925,7 @@
59305925
861265FA2404EC1500C4AFDE /* SentryArray.m in Sources */,
59315926
D802994E2BA836EF000F0081 /* SentryOnDemandReplay.swift in Sources */,
59325927
D8603DD6284F8497000E1227 /* SentryBaggage.m in Sources */,
5928+
F4FE9DBD2E621F100014FED5 /* SentryRandom.swift in Sources */,
59335929
63FE711520DA4C1000CDBAE8 /* SentryCrashJSONCodec.c in Sources */,
59345930
03F84D3327DD4191008FE43F /* SentryMachLogging.cpp in Sources */,
59355931
92235CAC2E15369900865983 /* SentryLogBatcher.swift in Sources */,

SentryTestUtils/TestClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class TestClient: SentryClient {
1616

1717
// Without this override we get a fatal error: use of unimplemented initializer
1818
// see https://stackoverflow.com/questions/28187261/ios-swift-fatal-error-use-of-unimplemented-initializer-init
19-
public override init(options: Options, transportAdapter: SentryTransportAdapter, fileManager: SentryFileManager, deleteOldEnvelopeItems: Bool, threadInspector: SentryThreadInspector, debugImageProvider: SentryDebugImageProvider, random: SentryRandomProtocol, locale: Locale, timezone: TimeZone) {
19+
@_spi(Private) public override init(options: Options, transportAdapter: SentryTransportAdapter, fileManager: SentryFileManager, deleteOldEnvelopeItems: Bool, threadInspector: SentryThreadInspector, debugImageProvider: SentryDebugImageProvider, random: SentryRandomProtocol, locale: Locale, timezone: TimeZone) {
2020
super.init(
2121
options: options,
2222
transportAdapter: transportAdapter,

SentryTestUtils/TestRandom.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import _SentryPrivate
22
import Foundation
3+
@_spi(Private) @testable import Sentry
34

4-
public class TestRandom: SentryRandomProtocol {
5+
@_spi(Private) public class TestRandom: SentryRandomProtocol {
56

67
public var value: Double
78

Sources/Sentry/Profiling/SentryLaunchProfiling.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# import "SentryOptions+Private.h"
1212
# import "SentryProfileConfiguration.h"
1313
# import "SentryProfiler+Private.h"
14-
# import "SentryRandom.h"
1514
# import "SentrySamplerDecision.h"
1615
# import "SentrySampling.h"
1716
# import "SentrySamplingContext.h"

Sources/Sentry/SentryClient.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#import "SentryNSError.h"
3030
#import "SentryOptions+Private.h"
3131
#import "SentryPropagationContext.h"
32-
#import "SentryRandom.h"
3332
#import "SentrySDK+Private.h"
3433
#import "SentryScope+Private.h"
3534
#import "SentryScope+PrivateSwift.h"
@@ -60,7 +59,7 @@ @interface SentryClient ()
6059

6160
@property (nonatomic, strong) SentryTransportAdapter *transportAdapter;
6261
@property (nonatomic, strong) SentryDebugImageProvider *debugImageProvider;
63-
@property (nonatomic, strong) id<SentryRandom> random;
62+
@property (nonatomic, strong) id<SentryRandomProtocol> random;
6463
@property (nonatomic, strong) NSLocale *locale;
6564
@property (nonatomic, strong) NSTimeZone *timezone;
6665

@@ -142,7 +141,7 @@ - (instancetype)initWithOptions:(SentryOptions *)options
142141
deleteOldEnvelopeItems:(BOOL)deleteOldEnvelopeItems
143142
threadInspector:(SentryThreadInspector *)threadInspector
144143
debugImageProvider:(SentryDebugImageProvider *)debugImageProvider
145-
random:(id<SentryRandom>)random
144+
random:(id<SentryRandomProtocol>)random
146145
locale:(NSLocale *)locale
147146
timezone:(NSTimeZone *)timezone
148147
{

Sources/Sentry/SentryDependencyContainer.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#import "SentryLogC.h"
1313
#import "SentryNSProcessInfoWrapper.h"
1414
#import "SentryOptions+Private.h"
15-
#import "SentryRandom.h"
1615
#import "SentrySDK+Private.h"
1716
#import "SentrySessionTracker.h"
1817
#import "SentrySwift.h"

Sources/Sentry/SentryRandom.m

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

Sources/Sentry/SentrySampling.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#import "SentryDependencyContainer.h"
33
#import "SentryInternalDefines.h"
44
#import "SentryOptions.h"
5-
#import "SentryRandom.h"
65
#import "SentrySampleDecision.h"
76
#import "SentrySamplerDecision.h"
87
#import "SentrySamplingContext.h"
8+
#import "SentrySwift.h"
99
#import "SentryTransactionContext.h"
1010
#import <SentryOptions+Private.h>
1111

Sources/Sentry/SentrySessionReplayIntegration.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# import "SentryHub+Private.h"
1515
# import "SentryLogC.h"
1616
# import "SentryOptions.h"
17-
# import "SentryRandom.h"
1817
# import "SentryRateLimits.h"
1918
# import "SentryReachability.h"
2019
# import "SentrySDK+Private.h"
@@ -714,7 +713,7 @@ - (SentryTouchTracker *)getTouchTracker
714713

715714
- (BOOL)sessionReplayShouldCaptureReplayForError
716715
{
717-
return SentryDependencyContainer.sharedInstance.random.nextNumber
716+
return [SentryDependencyContainer.sharedInstance.random nextNumber]
718717
<= _replayOptions.onErrorSampleRate;
719718
}
720719

Sources/Sentry/SentryTracer.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#import "SentryNoOpSpan.h"
1313
#import "SentryOptions+Private.h"
1414
#import "SentryProfilingConditionals.h"
15-
#import "SentryRandom.h"
1615
#import "SentrySDK+Private.h"
1716
#import "SentrySamplerDecision.h"
1817
#import "SentryScope+Private.h"

0 commit comments

Comments
 (0)