Skip to content
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

impr: Add extra logs for UIViewControllerSwizzling #4511

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions Sources/Sentry/SentrySubClassFinder.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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:@", "]);
}];
}];
}
Expand Down
14 changes: 12 additions & 2 deletions Sources/Sentry/SentryUIViewControllerSwizzling.m
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,24 @@
NSArray<UIViewController *> *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);

Check warning on line 311 in Sources/Sentry/SentryUIViewControllerSwizzling.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryUIViewControllerSwizzling.m#L311

Added line #L311 was not covered by tests
}
}
}
Expand All @@ -325,8 +333,10 @@

- (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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class SentrySwizzleClassNameExclude: NSObject {
static func shouldExcludeClass(className: String, swizzleClassNameExcludes: Set<String>) -> 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
}
}
Expand Down
Loading