sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

Refactor integration entry points in Swift

Open philprime opened this issue 1 month ago • 2 comments

Description

At this point every integration has an Objective-C entrypoint, e.g. SentryCrashIntegration.m or SentryANRTrackingIntegration.m. They are initialized from the - SentrySDKInternal#installIntegrations using dynamic calling of the initializer (without parameters).

We should rewrite the integrations in Swift, using constructor-based dependency injection to remove the usage of + SentryDependencyContaine#shareInstance.

Potential approach could be introducing factories for each integration, accepting the entire dependency container as the input, allowing us to keep using a generic SentryIntegrationProtocol with an install method.

philprime avatar Nov 20 '25 15:11 philprime

COCOA-982

linear[bot] avatar Nov 20 '25 15:11 linear[bot]

I'd suggest something roughly like this:

protocol SentryIntegration {

typealias DependencyProvider

func start(with options: Options)
}

protocol ProcessInfoProviding {
  var processInfo: ProcessInfo { get }
}
final class MyIntegration<DependencyProvider: ProcessInfoProviding>  {
  func start(with options: Options) {
    let processInfo = DependencyProvider.processInfo
  }
}
final class SentryDependencyContainer: ProcessInfoProviding {
 ...
}
MyIntegration<SentryDependencyContainer>.start(with: options)

noahsmartin avatar Nov 20 '25 15:11 noahsmartin