Skip to content

test: shared sdk wrapper other platforms #5085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: armcknight/test/share-sdk-wrapper
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// swiftlint:disable file_length function_body_length

import Sentry

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) || os(visionOS)
import UIKit
#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) || os(visionOS)

public struct SentrySDKWrapper {
public static let shared = SentrySDKWrapper()
Expand Down Expand Up @@ -29,7 +32,8 @@ public struct SentrySDKWrapper {
return true
}
options.debug = true


#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
if #available(iOS 16.0, *), !SentrySDKOverrides.Other.disableSessionReplay.boolValue {
options.sessionReplay = SentryReplayOptions(
sessionSampleRate: 0,
Expand All @@ -38,12 +42,19 @@ public struct SentrySDKWrapper {
maskAllImages: true
)
options.sessionReplay.quality = .high
options.sessionReplay.enableExperimentalViewRenderer = true

// Disable the fast view renderering, because we noticed parts (like the tab bar) are not rendered correctly
options.sessionReplay.enableFastViewRendering = false
}

if #available(iOS 15.0, *), !SentrySDKOverrides.Other.disableMetricKit.boolValue {
#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)

#if !os(tvOS) && !os(watchOS)
if #available(iOS 15.0, macOS 12.0, *), !SentrySDKOverrides.Other.disableMetricKit.boolValue {
options.enableMetricKit = true
options.enableMetricKitRawPayload = true
}
#endif // !os(tvOS) && !os(watchOS)

options.tracesSampleRate = 1
if let sampleRate = SentrySDKOverrides.Tracing.sampleRate.floatValue {
Expand All @@ -55,42 +66,53 @@ public struct SentrySDKWrapper {
}
}

#if !os(tvOS) && !os(watchOS) && !os(visionOS)
configureProfiling(options)
#endif // !os(tvOS) && !os(watchOS) && !os(visionOS)

options.enableAutoSessionTracking = !SentrySDKOverrides.Performance.disableSessionTracking.boolValue
if let sessionTrackingIntervalMillis = env["--io.sentry.sessionTrackingIntervalMillis"] {
options.sessionTrackingIntervalMillis = UInt((sessionTrackingIntervalMillis as NSString).integerValue)
} else {
options.sessionTrackingIntervalMillis = 5_000
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't set for many of the sample apps as the default

}

options.add(inAppInclude: "iOS_External")

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) || os(visionOS)
// the benchmark test starts and stops a custom transaction using a UIButton, and automatic user interaction tracing stops the transaction that begins with that button press after the idle timeout elapses, stopping the profiler (only one profiler runs regardless of the number of concurrent transactions)
options.enableUserInteractionTracing = !isBenchmarking && !SentrySDKOverrides.Performance.disableUITracing.boolValue

options.enablePreWarmedAppStartTracing = !isBenchmarking && !SentrySDKOverrides.Performance.disablePrewarmedAppStartTracing.boolValue
options.enableTracing = !isBenchmarking && !SentrySDKOverrides.Tracing.disableTracing.boolValue
options.enableUIViewControllerTracing = !SentrySDKOverrides.Performance.disableUIVCTracing.boolValue
options.attachScreenshot = !SentrySDKOverrides.Other.disableAttachScreenshot.boolValue
options.attachViewHierarchy = !SentrySDKOverrides.Other.disableAttachViewHierarchy.boolValue
options.enableAppHangTrackingV2 = !SentrySDKOverrides.Performance.disableAppHangTrackingV2.boolValue
#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) || os(visionOS)

#if os(macOS)
options.enableUncaughtNSExceptionReporting = true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was only set for macOS-SwiftUI but not macOS-Swift

#endif // os(macOS)

// disable during benchmarks because we run CPU for 15 seconds at full throttle which can trigger ANRs
options.enableAppHangTracking = !isBenchmarking && !SentrySDKOverrides.Performance.disableANRTracking.boolValue

// UI tests generate false OOMs
options.enableWatchdogTerminationTracking = !isUITest && !isBenchmarking && !SentrySDKOverrides.Performance.disableWatchdogTracking.boolValue

options.enableAutoPerformanceTracing = !isBenchmarking && !SentrySDKOverrides.Performance.disablePerformanceTracing.boolValue
options.enablePreWarmedAppStartTracing = !isBenchmarking && !SentrySDKOverrides.Performance.disablePrewarmedAppStartTracing.boolValue
options.enableTracing = !isBenchmarking && !SentrySDKOverrides.Tracing.disableTracing.boolValue

options.enableFileIOTracing = !SentrySDKOverrides.Performance.disableFileIOTracing.boolValue
options.enableAutoBreadcrumbTracking = !SentrySDKOverrides.Other.disableBreadcrumbs.boolValue
options.enableUIViewControllerTracing = !SentrySDKOverrides.Performance.disableUIVCTracing.boolValue
options.enableNetworkTracking = !SentrySDKOverrides.Performance.disableNetworkTracing.boolValue
options.enableCoreDataTracing = !SentrySDKOverrides.Performance.disableCoreDataTracing.boolValue
options.enableNetworkBreadcrumbs = !SentrySDKOverrides.Other.disableNetworkBreadcrumbs.boolValue
options.enableSwizzling = !SentrySDKOverrides.Other.disableSwizzling.boolValue
options.enableCrashHandler = !SentrySDKOverrides.Other.disableCrashHandling.boolValue
options.enablePersistingTracesWhenCrashing = true
options.attachScreenshot = !SentrySDKOverrides.Other.disableAttachScreenshot.boolValue
options.attachViewHierarchy = !SentrySDKOverrides.Other.disableAttachViewHierarchy.boolValue
options.enableTimeToFullDisplayTracing = !SentrySDKOverrides.Performance.disableTimeToFullDisplayTracing.boolValue
options.enablePerformanceV2 = !SentrySDKOverrides.Performance.disablePerformanceV2.boolValue
options.enableAppHangTrackingV2 = !SentrySDKOverrides.Performance.disableAppHangTrackingV2.boolValue
options.failedRequestStatusCodes = [ HttpStatusCodeRange(min: 400, max: 599) ]

#if targetEnvironment(simulator)
Expand All @@ -107,13 +129,13 @@ public struct SentrySDKWrapper {
}

options.initialScope = configureInitialScope(scope:)

#if os(iOS)
options.configureUserFeedback = configureFeedback(config:)
#endif // os(iOS)

// Experimental features
options.experimental.enableFileManagerSwizzling = !SentrySDKOverrides.Other.disableFileManagerSwizzling.boolValue
options.sessionReplay.enableExperimentalViewRenderer = true
// Disable the fast view renderering, because we noticed parts (like the tab bar) are not rendered correctly
options.sessionReplay.enableFastViewRendering = false
}

func configureInitialScope(scope: Scope) -> Scope {
Expand Down Expand Up @@ -166,6 +188,7 @@ public struct SentrySDKWrapper {
}

// MARK: User feedback configuration
#if os(iOS)
extension SentrySDKWrapper {
var layoutOffset: UIOffset { UIOffset(horizontal: 25, vertical: 75) }

Expand Down Expand Up @@ -261,11 +284,13 @@ extension SentrySDKWrapper {
updateHookMarkers(forEvent: "onFormClose")
}
config.onSubmitSuccess = { info in
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) || os(visionOS)
let name = info["name"] ?? "$shakespearean_insult_name"
let alert = UIAlertController(title: "Thanks?", message: "We have enough jank of our own, we really didn't need yours too, \(name).", preferredStyle: .alert)
alert.addAction(.init(title: "Deal with it 🕶️", style: .default))
UIApplication.shared.delegate?.window??.rootViewController?.present(alert, animated: true)

#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) || os(visionOS)

// if there's a screenshot's Data in this dictionary, JSONSerialization crashes _even though_ there's a `try?`, so we'll write the base64 encoding of it
var infoToWriteToFile = info
if let attachments = info["attachments"] as? [Any], let screenshot = attachments.first as? Data {
Expand All @@ -276,9 +301,12 @@ extension SentrySDKWrapper {
updateHookMarkers(forEvent: "onSubmitSuccess", with: jsonData.base64EncodedString())
}
config.onSubmitError = { error in
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) || os(visionOS)
let alert = UIAlertController(title: "D'oh", message: "You tried to report jank, and encountered more jank. The jank has you now: \(error).", preferredStyle: .alert)
alert.addAction(.init(title: "Derp", style: .default))
UIApplication.shared.delegate?.window??.rootViewController?.present(alert, animated: true)
#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) || os(visionOS)

let nserror = error as NSError
let missingFieldsSorted = (nserror.userInfo["missing_fields"] as? [String])?.sorted().joined(separator: ";") ?? ""
updateHookMarkers(forEvent: "onSubmitError", with: "\(nserror.domain);\(nserror.code);\(nserror.localizedDescription);\(missingFieldsSorted)")
Expand Down Expand Up @@ -348,6 +376,7 @@ extension SentrySDKWrapper {
}
}
}
#endif // os(iOS)

// MARK: Convenience access to SDK configuration via launch arg / environment variable
extension SentrySDKWrapper {
Expand Down Expand Up @@ -384,6 +413,7 @@ extension SentrySDKWrapper {
}

// MARK: Profiling configuration
#if !os(tvOS) && !os(watchOS) && !os(visionOS)
extension SentrySDKWrapper {
func configureProfiling(_ options: Options) {
if let sampleRate = SentrySDKOverrides.Profiling.sampleRate.floatValue {
Expand All @@ -405,5 +435,6 @@ extension SentrySDKWrapper {
}
}
}
#endif // !os(tvOS) && !os(watchOS) && !os(visionOS)

// swiftlint:enable file_length function_body_length
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
842D54862DA712C200D3528B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
ARCHS = (
"$(ARCHS_STANDARD)",
arm64e,
Expand All @@ -273,18 +274,23 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 97JCY7859U;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MACOSX_DEPLOYMENT_TARGET = 10.15;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "xrsimulator xros watchsimulator watchos macosx iphonesimulator iphoneos driverkit appletvsimulator appletvos";
SUPPORTS_MACCATALYST = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 13.0;
};
name = Debug;
};
842D54872DA712C200D3528B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
ARCHS = (
"$(ARCHS_STANDARD)",
arm64e,
Expand All @@ -293,11 +299,15 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 97JCY7859U;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MACOSX_DEPLOYMENT_TARGET = 10.15;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "xrsimulator xros watchsimulator watchos macosx iphonesimulator iphoneos driverkit appletvsimulator appletvos";
SUPPORTS_MACCATALYST = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 13.0;
};
name = Release;
};
Expand Down
Loading
Loading