From 4e65769409a343ffd341522b3575a7d2df0baa36 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Wed, 6 Nov 2024 09:25:04 +0100 Subject: [PATCH 1/2] impr: Add extra logs for UIViewControllerSwizzling Add more log messages for potential troubleshooting for swizzling UIViewControllers. --- CHANGELOG.md | 1 + Sources/Sentry/SentrySubClassFinder.m | 10 +++++----- Sources/Sentry/SentryUIViewControllerSwizzling.m | 14 ++++++++++++-- .../Performance/SwizzleClassNameExclude.swift | 1 + 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f984d85e9d..5a9adc60f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Expose `SentrySessionReplayIntegration-Hybrid.h` as `private` (#4486) - Add `maskedViewClasses` and `unmaskedViewClasses` to SentryReplayOptions init via dict (#4492) - Add `quality` to SentryReplayOptions init via dict (#4495) +- Add extra logs for UIViewControllerSwizzling (#4511) ### Fixes diff --git a/Sources/Sentry/SentrySubClassFinder.m b/Sources/Sentry/SentrySubClassFinder.m index b730f01f68..84bea71325 100644 --- a/Sources/Sentry/SentrySubClassFinder.m +++ b/Sources/Sentry/SentrySubClassFinder.m @@ -36,6 +36,8 @@ - (instancetype)initWithDispatchQueue:(SentryDispatchQueueWrapper *)dispatchQueu - (void)actOnSubclassesOfViewControllerInImage:(NSString *)imageName block:(void (^)(Class))block; { [self.dispatchQueue dispatchAsyncWithBlock:^{ + SENTRY_LOG_DEBUG(@"ActOnSubclassesOfViewControllerInImage: %@", imageName); + Class viewControllerClass = [UIViewController class]; if (viewControllerClass == nil) { SENTRY_LOG_DEBUG(@"UIViewController class not found."); @@ -85,11 +87,9 @@ - (void)actOnSubclassesOfViewControllerInImage:(NSString *)imageName block:(void block(NSClassFromString(className)); } - [SentryLog - logWithMessage:[NSString stringWithFormat:@"The following UIViewControllers will " - @"generate automatic transactions: %@", - [classesToSwizzle componentsJoinedByString:@", "]] - andLevel:kSentryLevelDebug]; + SENTRY_LOG_DEBUG( + @"The following UIViewControllers will generate automatic transactions: %@", + [classesToSwizzle componentsJoinedByString:@", "]); }]; }]; } diff --git a/Sources/Sentry/SentryUIViewControllerSwizzling.m b/Sources/Sentry/SentryUIViewControllerSwizzling.m index 456dd933e1..784b32a27d 100644 --- a/Sources/Sentry/SentryUIViewControllerSwizzling.m +++ b/Sources/Sentry/SentryUIViewControllerSwizzling.m @@ -291,16 +291,24 @@ - (void)swizzleRootViewControllerAndDescendant:(UIViewController *)rootViewContr NSArray *allViewControllers = [SentryViewController descendantsOfViewController:rootViewController]; + SENTRY_LOG_DEBUG(@"Found %lu descendants for RootViewController %@", allViewControllers.count, + rootViewController.description); + for (UIViewController *viewController in allViewControllers) { Class viewControllerClass = [viewController class]; if (viewControllerClass != nil) { - SENTRY_LOG_DEBUG(@"UIViewControllerSwizzling Calling swizzleRootViewController."); + SENTRY_LOG_DEBUG( + @"Calling swizzleRootViewController for %@", viewController.description); + [self swizzleViewControllerSubClass:viewControllerClass]; // We can't get the image name with the app delegate class for some apps. Therefore, we // use the rootViewController and its subclasses as a fallback. The following method // ensures we don't swizzle ViewControllers of UIKit. [self swizzleUIViewControllersOfClassesInImageOf:viewControllerClass]; + } else { + SENTRY_LOG_WARN(@"ViewControllerClass was nil for UIViewController: %@", + viewController.description); } } } @@ -325,8 +333,10 @@ - (void)swizzleUIViewController - (void)swizzleViewControllerSubClass:(Class)class { - if (![self shouldSwizzleViewController:class]) + if (![self shouldSwizzleViewController:class]) { + SENTRY_LOG_DEBUG(@"Skipping swizzling of class: %@", class); return; + } // This are the five main functions related to UI creation in a view controller. // We are swizzling it to track anything that happens inside one of this functions. diff --git a/Sources/Swift/Integrations/Performance/SwizzleClassNameExclude.swift b/Sources/Swift/Integrations/Performance/SwizzleClassNameExclude.swift index 9b60ae87ff..ca9ef1eb4d 100644 --- a/Sources/Swift/Integrations/Performance/SwizzleClassNameExclude.swift +++ b/Sources/Swift/Integrations/Performance/SwizzleClassNameExclude.swift @@ -5,6 +5,7 @@ class SentrySwizzleClassNameExclude: NSObject { static func shouldExcludeClass(className: String, swizzleClassNameExcludes: Set) -> Bool { for exclude in swizzleClassNameExcludes { if className.contains(exclude) { + SentryLog.debug("Excluding class \(className) from swizzling cause it matches the exclude pattern: \(exclude).") return true } } From 323291455d70ca8251d5b0917273991ee6b00bf6 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Wed, 6 Nov 2024 15:16:04 +0100 Subject: [PATCH 2/2] fix changelog --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4eb1c9e1b0..4163298a63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Improvements + +- Add extra logs for UIViewControllerSwizzling (#4511) + ## 8.40.0 ## Feature @@ -17,7 +23,6 @@ - Expose `SentrySessionReplayIntegration-Hybrid.h` as `private` (#4486) - Add `maskedViewClasses` and `unmaskedViewClasses` to SentryReplayOptions init via dict (#4492) - Add `quality` to SentryReplayOptions init via dict (#4495) -- Add extra logs for UIViewControllerSwizzling (#4511) ### Fixes