Skip to content

Commit 2991d63

Browse files
authored
ref: SentryOptions in Swift (#6628)
* ref: SentryOptions in Swift * Renames * Improve defaults * Fix * Fix duplicate test
1 parent 68d6f41 commit 2991d63

File tree

107 files changed

+25302
-26325
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+25302
-26325
lines changed

Samples/iOS-Swift/iOS-Swift/Profiling/ProfilingViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Sentry
1+
@_spi(Private) import Sentry
22
import SentrySampleShared
33
import UIKit
44

Samples/iOS-Swift/iOS-Swift/Tools/iOS-Swift-Bridging-Header.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
#import "SentryExposure.h"
44
#import <Sentry/PrivateSentrySDKOnly.h>
55
#import <Sentry/SentryDsn+Private.h>
6-
#import <Sentry/SentryOptions+Private.h>

Sentry.xcodeproj/project.pbxproj

Lines changed: 18 additions & 23 deletions
Large diffs are not rendered by default.

SentryTestUtils/Sources/TestClient.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import _SentryPrivate
22
import Foundation
3-
@_spi(Private) import Sentry
3+
@_spi(Private) @testable import Sentry
44

55
public class TestClient: SentryClientInternal {
6-
public override init?(options: Options) {
6+
public override init?(options: NSObject) {
77
super.init(
88
options: options,
9-
transportAdapter: TestTransportAdapter(transports: [TestTransport()], options: options),
9+
transportAdapter: TestTransportAdapter(transports: [TestTransport()], options: options as! Options),
1010
fileManager: try! TestFileManager(
11-
options: options,
11+
options: options as? Options,
1212
dateProvider: TestCurrentDateProvider(),
1313
dispatchQueueWrapper: TestSentryDispatchQueueWrapper()
1414
),
@@ -22,7 +22,7 @@ public class TestClient: SentryClientInternal {
2222

2323
// Without this override we get a fatal error: use of unimplemented initializer
2424
// see https://stackoverflow.com/questions/28187261/ios-swift-fatal-error-use-of-unimplemented-initializer-init
25-
@_spi(Private) public override init(options: Options, transportAdapter: SentryTransportAdapter, fileManager: SentryFileManager, threadInspector: SentryDefaultThreadInspector, debugImageProvider: SentryDebugImageProvider, random: SentryRandomProtocol, locale: Locale, timezone: TimeZone) {
25+
@_spi(Private) public override init(options: NSObject, transportAdapter: SentryTransportAdapter, fileManager: SentryFileManager, threadInspector: SentryDefaultThreadInspector, debugImageProvider: SentryDebugImageProvider, random: SentryRandomProtocol, locale: Locale, timezone: TimeZone) {
2626
super.init(
2727
options: options,
2828
transportAdapter: transportAdapter,

SentryTestUtils/Sources/TestFileManager.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import Foundation
77
var readTimestampLastInForegroundInvocations: Int = 0
88
var storeTimestampLastInForegroundInvocations: Int = 0
99
var deleteTimestampLastInForegroundInvocations: Int = 0
10+
11+
public init(options: Options?, dateProvider: any SentryCurrentDateProvider, dispatchQueueWrapper: SentryDispatchQueueWrapper) throws {
12+
let helper = try SentryFileManagerHelper(options: options)
13+
super.init(helper: helper, dateProvider: dateProvider, dispatchQueueWrapper: dispatchQueueWrapper)
14+
}
1015

1116
@_spi(Private) public var storeEnvelopeInvocations = Invocations<SentryEnvelope>()
1217
public var storeEnvelopePath: String?

Sources/Sentry/PrivateSentrySDKOnly.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#import "SentryInstallation.h"
77
#import "SentryInternalDefines.h"
88
#import "SentryMeta.h"
9-
#import "SentryOptions+Private.h"
109
#import "SentryProfileCollector.h"
1110
#import "SentryPropagationContext.h"
1211
#import "SentrySDK+Private.h"

Sources/Sentry/Profiling/SentryLaunchProfiling.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# import "SentryInternalDefines.h"
88
# import "SentryLaunchProfiling.h"
99
# import "SentryLogC.h"
10-
# import "SentryOptions+Private.h"
1110
# import "SentryProfileConfiguration.h"
1211
# import "SentryProfiler+Private.h"
1312
# import "SentrySamplerDecision.h"

Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
# import "SentryContinuousProfiler.h"
66
# import "SentryInternalDefines.h"
77
# import "SentryLogC.h"
8-
# import "SentryOptions+Private.h"
98
# import "SentryProfiler+Private.h"
109
# include <mutex>
1110

1211
# import "SentryEvent+Private.h"
1312
# import "SentryHub+Private.h"
1413
# import "SentryInternalDefines.h"
1514
# import "SentryLaunchProfiling.h"
16-
# import "SentryOptions+Private.h"
1715
# import "SentryProfileConfiguration.h"
1816
# import "SentryProfiledTracerConcurrency.h"
1917
# import "SentryProfiler+Private.h"

Sources/Sentry/Profiling/SentryProfilingSwiftHelpers.m

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
#if SENTRY_TARGET_PROFILING_SUPPORTED
33

44
# import "SentryClient.h"
5+
# import "SentryDependencyContainerSwiftHelper.h"
6+
# import "SentryHub.h"
7+
# import "SentryInternalDefines.h"
8+
# import "SentryLaunchProfiling.h"
59
# import "SentryLogC.h"
6-
# import "SentryOptions+Private.h"
10+
# import "SentryProfileConfiguration.h"
711
# import "SentryProfiler+Private.h"
12+
# import "SentrySDK+Private.h"
813
# import "SentrySamplerDecision.h"
914
# import "SentrySwift.h"
1015

@@ -159,6 +164,24 @@
159164
}
160165

161166
# if SENTRY_HAS_UIKIT
167+
BOOL
168+
sentry_appHangsDisabled(void)
169+
{
170+
SentryOptions *options = [[[SentrySDKInternal currentHub] getClient] options];
171+
if (options == nil) {
172+
return NO;
173+
}
174+
return [options isAppHangTrackingDisabled];
175+
}
176+
BOOL
177+
sentry_autoPerformanceTracingDisabled(void)
178+
{
179+
SentryOptions *options = [[[SentrySDKInternal currentHub] getClient] options];
180+
if (options == nil) {
181+
return YES;
182+
}
183+
return ![options enableAutoPerformanceTracing];
184+
}
162185
void
163186
sentry_startFramesTracker(void)
164187
{
@@ -183,4 +206,93 @@
183206
return [SentryDependencyContainer.sharedInstance.framesTracker currentFrames];
184207
}
185208
# endif // SENTRY_HAS_UIKIT
209+
210+
void
211+
sentry_configureContinuousProfiling(SentryOptions *options)
212+
{
213+
if (options.configureProfiling == nil) {
214+
SENTRY_LOG_DEBUG(@"Continuous profiling V2 configuration not set by SDK consumer, nothing "
215+
@"to do here.");
216+
return;
217+
}
218+
219+
SentryProfileOptions *_Nonnull profilingOptions = sentry_getSentryProfileOptions();
220+
options.profiling = profilingOptions;
221+
options.configureProfiling(profilingOptions);
222+
223+
if (sentry_isTraceLifecycle(profilingOptions) && !options.isTracingEnabled) {
224+
SENTRY_LOG_WARN(
225+
@"Tracing must be enabled in order to configure profiling with trace lifecycle.");
226+
return;
227+
}
228+
229+
// if a launch profiler was started, sentry_profileConfiguration will have been set at that time
230+
// with the hydrated options that were persisted from the previous SDK start, which are used to
231+
// help determine when/how to stop the launch profile. otherwise, there won't yet be a
232+
// SentryProfileConfiguration instance, so we'll instantiate one which will be used to access
233+
// the profile session sample rate henceforth
234+
if (sentry_profileConfiguration == nil) {
235+
sentry_profileConfiguration =
236+
[[SentryProfileConfiguration alloc] initWithProfileOptions:profilingOptions];
237+
}
238+
239+
sentry_reevaluateSessionSampleRate();
240+
241+
SENTRY_LOG_DEBUG(@"Configured profiling options: <%@: {\n lifecycle: %@\n sessionSampleRate: "
242+
@"%.2f\n profileAppStarts: %@\n}",
243+
options.profiling, sentry_isTraceLifecycle(profilingOptions) ? @"trace" : @"manual",
244+
sentry_sessionSampleRate(profilingOptions),
245+
sentry_profileAppStarts(profilingOptions) ? @"YES" : @"NO");
246+
}
247+
248+
void
249+
sentry_sdkInitProfilerTasks(SentryOptions *options, SentryHubInternal *hub)
250+
{
251+
// get the configuration options from the last time the launch config was written; it may be
252+
// different than the new options the SDK was just started with
253+
SentryProfileConfiguration *configurationFromLaunch = sentry_profileConfiguration;
254+
255+
sentry_configureContinuousProfiling(options);
256+
257+
sentry_dispatchAsync(SentryDependencyContainerSwiftHelper.dispatchQueueWrapper, ^{
258+
if (configurationFromLaunch.isProfilingThisLaunch) {
259+
BOOL shouldStopAndTransmitLaunchProfile = YES;
260+
261+
BOOL profileIsContinuousV2 = configurationFromLaunch.profileOptions != nil;
262+
BOOL v2LifecycleIsManual = profileIsContinuousV2
263+
&& !sentry_isTraceLifecycle(SENTRY_UNWRAP_NULLABLE(
264+
SentryProfileOptions, configurationFromLaunch.profileOptions));
265+
266+
# if SENTRY_HAS_UIKIT
267+
BOOL v2LifecycleIsTrace = profileIsContinuousV2
268+
&& sentry_isTraceLifecycle(SENTRY_UNWRAP_NULLABLE(
269+
SentryProfileOptions, configurationFromLaunch.profileOptions));
270+
BOOL profileIsCorrelatedToTrace = !profileIsContinuousV2 || v2LifecycleIsTrace;
271+
if (profileIsCorrelatedToTrace && configurationFromLaunch.waitForFullDisplay) {
272+
SENTRY_LOG_DEBUG(
273+
@"Will wait to stop launch profile correlated to a trace until full "
274+
@"display reported.");
275+
shouldStopAndTransmitLaunchProfile = NO;
276+
}
277+
# endif // SENTRY_HAS_UIKIT
278+
279+
if (v2LifecycleIsManual) {
280+
SENTRY_LOG_DEBUG(@"Continuous manual launch profiles aren't stopped on calls to "
281+
@"SentrySDK.start, "
282+
@"not stopping profile.");
283+
shouldStopAndTransmitLaunchProfile = NO;
284+
}
285+
286+
if (shouldStopAndTransmitLaunchProfile) {
287+
SENTRY_LOG_DEBUG(
288+
@"Stopping launch profile in SentrySDK.start because there is no time "
289+
@"to display tracker to stop it.");
290+
sentry_stopAndDiscardLaunchProfileTracer(hub);
291+
}
292+
}
293+
294+
sentry_configureLaunchProfilingForNextLaunch(options);
295+
});
296+
}
297+
186298
#endif // SENTRY_TARGET_PROFILING_SUPPORTED

Sources/Sentry/Public/Sentry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ FOUNDATION_EXPORT const unsigned char SentryVersionString[];
2828
# import <Sentry/SentryMechanismContext.h>
2929
# import <Sentry/SentryMessage.h>
3030
# import <Sentry/SentryNSError.h>
31-
# import <Sentry/SentryOptions.h>
31+
# import <Sentry/SentryProfilingConditionals.h>
3232
# import <Sentry/SentryReplayApi.h>
3333
# import <Sentry/SentryRequest.h>
3434
# import <Sentry/SentrySampleDecision.h>

0 commit comments

Comments
 (0)