-
-
Notifications
You must be signed in to change notification settings - Fork 348
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
armcknight
wants to merge
9
commits into
armcknight/test/share-sdk-wrapper
Choose a base branch
from
armcknight/test/shared-sdk-wrapper-other-platforms
base: armcknight/test/share-sdk-wrapper
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
00555ea
wip integrating into macOS-Swift
armcknight 8614247
more wip
armcknight d8987cc
finish integrating macOS-Swift
armcknight e9b8441
integrate into macOS-SwiftUI
armcknight 9b54e0b
integrate into tvOS apps
armcknight 4933865
integrate into visionOS-Swift
armcknight 5b99de1
Merge branch 'armcknight/test/share-sdk-wrapper' into armcknight/test…
armcknight dca1763
Merge branch 'armcknight/test/share-sdk-wrapper' into armcknight/test…
armcknight dbdd064
Merge branch 'armcknight/test/share-sdk-wrapper' into armcknight/test…
armcknight File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
@@ -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, | ||
|
@@ -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 { | ||
|
@@ -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 | ||
} | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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 { | ||
|
@@ -166,6 +188,7 @@ public struct SentrySDKWrapper { | |
} | ||
|
||
// MARK: User feedback configuration | ||
#if os(iOS) | ||
extension SentrySDKWrapper { | ||
var layoutOffset: UIOffset { UIOffset(horizontal: 25, vertical: 75) } | ||
|
||
|
@@ -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 { | ||
|
@@ -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)") | ||
|
@@ -348,6 +376,7 @@ extension SentrySDKWrapper { | |
} | ||
} | ||
} | ||
#endif // os(iOS) | ||
|
||
// MARK: Convenience access to SDK configuration via launch arg / environment variable | ||
extension SentrySDKWrapper { | ||
|
@@ -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 { | ||
|
@@ -405,5 +435,6 @@ extension SentrySDKWrapper { | |
} | ||
} | ||
} | ||
#endif // !os(tvOS) && !os(watchOS) && !os(visionOS) | ||
|
||
// swiftlint:enable file_length function_body_length |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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