22#import " PrivateSentrySDKOnly.h"
33#import " SentryANRTrackingIntegration.h"
44#import " SentryAppStartMeasurement.h"
5+ #import " SentryAutoBreadcrumbTrackingIntegration.h"
6+ #import " SentryAutoSessionTrackingIntegration.h"
57#import " SentryBreadcrumb.h"
68#import " SentryClient+Private.h"
9+ #import " SentryCoreDataTrackingIntegration.h"
710#import " SentryCrash.h"
11+ #import " SentryCrashIntegration.h"
12+ #import " SentryFileIOTrackingIntegration.h"
813#import " SentryHub+Private.h"
914#import " SentryInternalDefines.h"
1015#import " SentryLogC.h"
1116#import " SentryMeta.h"
17+ #import " SentryNetworkTrackingIntegration.h"
1218#import " SentryOptions+Private.h"
1319#import " SentryOptionsInternal.h"
1420#import " SentryProfilingConditionals.h"
1723#import " SentrySamplingContext.h"
1824#import " SentryScope.h"
1925#import " SentrySerialization.h"
26+ #import " SentrySessionReplayIntegration.h"
2027#import " SentrySwift.h"
28+ #import " SentrySwiftAsyncIntegration.h"
2129#import " SentryTransactionContext.h"
2230#import " SentryUseNSExceptionCallstackWrapper.h"
2331#import " SentryUserFeedbackIntegration.h"
2432
33+ #if SENTRY_HAS_UIKIT
34+ # import " SentryAppStartTrackingIntegration.h"
35+ # import " SentryFramesTrackingIntegration.h"
36+ # import " SentryPerformanceTrackingIntegration.h"
37+ # import " SentryScreenshotIntegration.h"
38+ # import " SentryUIEventTrackingIntegration.h"
39+ # import " SentryUserFeedbackIntegration.h"
40+ # import " SentryViewHierarchyIntegration.h"
41+ # import " SentryWatchdogTerminationTrackingIntegration.h"
42+ #endif // SENTRY_HAS_UIKIT
43+
44+ #if SENTRY_HAS_METRIC_KIT
45+ # import " SentryMetricKitIntegration.h"
46+ #endif // SENTRY_HAS_METRIC_KIT
47+
2548#if TARGET_OS_OSX
2649# import " SentryCrashExceptionApplication.h"
2750#endif // TARGET_OS_MAC
@@ -520,6 +543,41 @@ + (void)endSession
520543 [SentrySDKInternal.currentHub endSession ];
521544}
522545
546+ + (NSArray <Class> *)defaultIntegrationClasses
547+ {
548+ // The order of integrations here is important.
549+ // SentryCrashIntegration needs to be initialized before SentryAutoSessionTrackingIntegration.
550+ // And SentrySessionReplayIntegration before SentryCrashIntegration.
551+ NSMutableArray <Class > *defaultIntegrations = [NSMutableArray <Class > arrayWithObjects:
552+ #if SENTRY_TARGET_REPLAY_SUPPORTED
553+ [SentrySessionReplayIntegration class ],
554+ #endif // SENTRY_TARGET_REPLAY_SUPPORTED
555+ [SentryCrashIntegration class ],
556+ #if SENTRY_HAS_UIKIT
557+ [SentryAppStartTrackingIntegration class ], [SentryFramesTrackingIntegration class ],
558+ [SentryPerformanceTrackingIntegration class ], [SentryUIEventTrackingIntegration class ],
559+ [SentryViewHierarchyIntegration class ],
560+ [SentryWatchdogTerminationTrackingIntegration class ],
561+ #endif // SENTRY_HAS_UIKIT
562+ #if SENTRY_TARGET_REPLAY_SUPPORTED
563+ [SentryScreenshotIntegration class ],
564+ #endif // SENTRY_TARGET_REPLAY_SUPPORTED
565+ [SentryANRTrackingIntegration class ], [SentryAutoBreadcrumbTrackingIntegration class ],
566+ [SentryAutoSessionTrackingIntegration class ], [SentryCoreDataTrackingIntegration class ],
567+ [SentryFileIOTrackingIntegration class ], [SentryNetworkTrackingIntegration class ],
568+ [SentrySwiftAsyncIntegration class ], nil ];
569+
570+ #if TARGET_OS_IOS && SENTRY_HAS_UIKIT
571+ [defaultIntegrations addObject: [SentryUserFeedbackIntegration class ]];
572+ #endif // TARGET_OS_IOS && SENTRY_HAS_UIKIT
573+
574+ #if SENTRY_HAS_METRIC_KIT
575+ [defaultIntegrations addObject: [SentryMetricKitIntegration class ]];
576+ #endif // SENTRY_HAS_METRIC_KIT
577+
578+ return defaultIntegrations;
579+ }
580+
523581/* *
524582 * Install integrations and keeps ref in @c SentryHub.integrations
525583 */
@@ -530,48 +588,24 @@ + (void)installIntegrations
530588 return ;
531589 }
532590 SentryOptions *options = [SentrySDKInternal.currentHub getClient ].options ;
533- NSMutableArray <NSString *> *integrationNames = [SentryOptions defaultIntegrations ].mutableCopy ;
534-
535- NSArray <Class > *defaultIntegrations = SentryOptionsInternal.defaultIntegrationClasses ;
536-
537- // Since 8.22.0, we use a precompiled XCFramework for SPM, which can lead to Sentry's
538- // definition getting duplicated in the app with a warning “SentrySDK is defined in both
539- // ModuleA and ModuleB”. This doesn't happen when users use Sentry-Dynamic and
540- // when compiling Sentry from source via SPM. Due to the duplication, some users didn't
541- // see any crashes reported to Sentry cause the SentryCrashReportSink couldn't find
542- // a hub bound to the SentrySDK, and it dropped the crash events. This problem
543- // is fixed now by using a dictionary that links the classes with their names
544- // so we can quickly check whether that class is in the option integrations collection.
545- // We cannot load the class itself with NSClassFromString because doing so may load a class
546- // that was duplicated in another module, leading to undefined behavior.
547- NSMutableDictionary <NSString *, Class > *integrationDictionary =
548- [[NSMutableDictionary alloc ] init ];
549-
550- for (Class integrationClass in defaultIntegrations) {
551- integrationDictionary[NSStringFromClass (integrationClass)] = integrationClass;
552- }
553591
554- for (NSString *integrationName in integrationNames) {
555- Class integrationClass
556- = integrationDictionary[integrationName] ?: NSClassFromString (integrationName);
557- if (nil == integrationClass) {
558- SENTRY_LOG_ERROR (@" [SentryHub doInstallIntegrations] "
559- @" couldn't find \" %@ \" -> skipping." ,
560- integrationName);
561- continue ;
562- } else if ([SentrySDKInternal.currentHub isIntegrationInstalled: integrationClass]) {
592+ NSArray <Class > *integrationClasses = [SentrySDKInternal defaultIntegrationClasses ];
593+
594+ for (Class integrationClass in integrationClasses) {
595+ if ([SentrySDKInternal.currentHub isIntegrationInstalled: integrationClass]) {
563596 SENTRY_LOG_ERROR (
564597 @" [SentryHub doInstallIntegrations] already installed \" %@ \" -> skipping." ,
565- integrationName );
598+ NSStringFromClass (integrationClass) );
566599 continue ;
567600 }
601+
568602 id <SentryIntegrationProtocol> integrationInstance = [[integrationClass alloc ] init ];
569603 BOOL shouldInstall = [integrationInstance installWithOptions: options];
570-
571604 if (shouldInstall) {
572- SENTRY_LOG_DEBUG (@" Integration installed: %@ " , integrationName);
573- [SentrySDKInternal.currentHub addInstalledIntegration: integrationInstance
574- name: integrationName];
605+ SENTRY_LOG_DEBUG (@" Integration installed: %@ " , NSStringFromClass (integrationClass));
606+ [SentrySDKInternal.currentHub
607+ addInstalledIntegration: integrationInstance
608+ name: NSStringFromClass (integrationClass)];
575609 }
576610 }
577611}
0 commit comments