Skip to content

Commit 89cf21e

Browse files
itaybreclaude
andauthored
Convert SentryCrashIntegration to Swift (#7187)
* ref: Migrate SentryWatchdogTerminationLogic and SentryWatchdogTerminationTracker to Swift Migrate the Logic and Tracker classes from Objective-C to Swift while keeping the Integration in Objective-C for now. The Swift classes are marked with @objc and @_spi(Private) to maintain compatibility with the existing Objective-C Integration. Changes: - Add SentryWatchdogTerminationLogic.swift with @objc support - Add SentryWatchdogTerminationTracker.swift with @objc support - Remove old Objective-C implementations - Update imports in Integration and other files to use Swift versions - Update test data to reference Swift class properties - Update bridging header to remove obsolete imports * Fix missing imports * Fix build on macOS * ref: Migrate SentryWatchdogTerminationTrackingIntegration to Swift Migrate the Integration class from Objective-C to Swift, building on top of the previously migrated Logic and Tracker Swift classes. The Swift Integration uses a protocol-based dependency injection pattern for better testability. Changes: - Add SentryWatchdogTerminationTrackingIntegration.swift with generics - Remove old Objective-C Integration implementation - Update Integrations.swift to register the Swift integration - Update SentrySDKInternal.m to remove ObjC registration - Update Integration tests to work with new Swift implementation * ref: Update SentryScope observer API for Swift compatibility Update the scope observer API to be more Swift-friendly. Rename addObserver to addScopeObserver and make it accept Any type with runtime validation, allowing Swift-defined protocols to work properly with Objective-C. Changes: - Rename addObserver: to addScopeObserver: in SentryScope - Update addScopeObserver to accept Any with runtime protocol checking - Remove addObserver from SentryScope+Private.h header - Add addScopeObserver to SentryScope+PrivateSwift.h - Update SentryCrashIntegration to use new API - Update tests to cast observer to Any when needed - Update Xcode project to include Integration Swift file * Fix tests * Break down `WatchdogTerminationTrackingProvider` * Add tests for `SentryWatchdogTerminationLogic` * Add SentryWatchdogTerminationLogicTests to project configuration * Rename SentryWatchdogTerminationTracker constants * Refactor SentryWatchdogTerminationTracker to remove nesting * Extract WatchdogTermination contansts * Remove conditional compilation for iOS-specific tests in SentryClientTests, SentryMetricKitEventTests, and TestData. This simplifies the test files by eliminating unnecessary preprocessor directives. * Convert SentryCrashIntegration from Objective-C to Swift - Create SentryCrashIntegration.swift with SwiftIntegration protocol - Implement dependency injection via CrashIntegrationProvider - Handle C callback for crash-time transaction saving - Remove old Objective-C files (SentryCrashIntegration.m/h) - Update SentrySDKInternal.m to remove ObjC integration reference - Register integration in Swift integration installer - Expose required ObjC headers in SentryPrivate.h - Update all tests to use new Swift initialization API - Add MIGRATION_NOTES.md documenting remaining work Note: Requires SentryWatchdogTerminationLogic, SentryCrashIntegrationSessionHandler, and SentryCrashScopeObserver to be properly bridged to Swift or migrated. Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com> * Fix build on watchos and macOS * Update conditional compilation to include visionOS support in SentryWatchdogTerminationTrackingIntegration.swift * Add SentryWatchdogTerminationTrackingIntegration to Integrations.swift * Fix compilation issues after merging watchdog branch - Remove SentryCrashIntegration.h import from SentryClient.m - Remove SentryCrashIntegration headers from SentryTests-Bridging-Header.h - Remove SentryWatchdogTerminationLogic.h from SentryPrivate.h (now in Swift) - Fix Scope casting to access private ObjC methods Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com> * Remove duplicate AppStateManagerProvider protocol The protocol is already defined in SentryDependencyContainer.swift from the watchdog termination branch merge. Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com> * ref: Renames `SentrySpan` class to `SentrySpanInternal` * chore: Add temporary macro for Swift migration tracking in SentryDefines.h * Add Objective-C id usage linter * Remove excluded folder and fix SentryScope.h * Rewrite script in ruby * Improve script * Refactor violation reporting in check-objc-id-usage.rb to allow for quiet mode * Refactor SentryCrashIntegration and migrate to Swift. Removed Objective-C implementation of SentryCrashInstallationReporter and SentryCrashIntegrationSessionHandler, replacing them with Swift counterparts. Updated project file references accordingly. * Undo unnecessary changes * Fix tests * Undo change * Cleanup * Remove unnecessary uninstall * Improve SentruCrashIntegrationTests * Fix build in SPM * Conditional import of "SentryUncaughtNSExceptions.h" for macOS target in SentryPrivate.h * Run generate API * Fix UIKit linking * Add some comments regarding why use a singleton * Refactor SentryCrashIntegration to use NSRecursiveLock for thread safety and improve installation token handling. Update crash handler initialization logic and enhance comments for clarity. * Update Sources/Sentry/include/SentryPrivate.h * Add debug logging for transaction handling and crash handler initialization in SentryCrashIntegration * Refactor SentryCrashIntegration to eliminate singleton use * Move builder methods to the dependency container * Refactor SentryCrashIntegration to remove dispatch queue wrapper dependency and simplify installation handling. Update tests to reflect changes in mock dependencies. * Fix test for macOS --------- Co-authored-by: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
1 parent 5fa5c47 commit 89cf21e

29 files changed

+696
-688
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 29 additions & 35 deletions
Large diffs are not rendered by default.

Sources/Sentry/SentryClient.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#import "SentryAttachment.h"
44
#import "SentryClient+Private.h"
55
#import "SentryCrashDefaultMachineContextWrapper.h"
6-
#import "SentryCrashIntegration.h"
76
#import "SentryCrashStackEntryMapper.h"
87
#import "SentryDefaultThreadInspector.h"
98
#import "SentryDeviceContextKeys.h"

Sources/Sentry/SentryCrashInstallationReporter.m

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

Sources/Sentry/SentryCrashIntegration.m

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

0 commit comments

Comments
 (0)