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

swizzleClassNameExcludes is ignored for loadView #4386

Closed
philipphofmann opened this issue Oct 1, 2024 · 0 comments · Fixed by #4405
Closed

swizzleClassNameExcludes is ignored for loadView #4386

philipphofmann opened this issue Oct 1, 2024 · 0 comments · Fixed by #4405

Comments

@philipphofmann
Copy link
Member

Description

We swizzle the loadView method of the UIViewControllernot the individual view controllers because of some edge cases with nib files.

/**
* We need to swizzle @c -[UIViewController @c loadView] because we can't do it for controllers that
* use Nib files (see @c swizzleLoadView for more information).
* @c SentryUIViewControllerPerformanceTracker makes sure we don't get two spans
* if the @c -[loadView] of an actual @c UIViewController is swizzled.
*/
- (void)swizzleUIViewController
{
SEL selector = NSSelectorFromString(@"loadView");
SentrySwizzleInstanceMethod(UIViewController.class, selector, SentrySWReturnType(void),
SentrySWArguments(), SentrySWReplacement({
[SentryUIViewControllerPerformanceTracker.shared
viewControllerLoadView:self
callbackToOrigin:^{ SentrySWCallOriginal(); }];
}),
SentrySwizzleModeOncePerClassAndSuperclasses, (void *)selector);
}

So the SentryUIViewControllerPerformanceTracker.viewControllerLoadView checks the inAppLogic, but doesn't check the swizzleClassNameExcludes.

- (void)viewControllerLoadView:(UIViewController *)controller
callbackToOrigin:(void (^)(void))callbackToOrigin
{
if (![self.inAppLogic isClassInApp:[controller class]]) {
SENTRY_LOG_DEBUG(
@"Won't track view controller that is not part of the app bundle: %@.", controller);
callbackToOrigin();
return;
}

So when adding a UIViewController to the swizzleClassNameExcludes it doesn't work. We should also check the swizzleClassNameExcludes in the SentryUIViewControllerPerformanceTracker.viewControllerLoadView.

@philipphofmann philipphofmann self-assigned this Oct 7, 2024
philipphofmann added a commit that referenced this issue Oct 7, 2024
Skip creating transactions for UIViewControllers ignored for swizzling
via the option swizzleClassNameExclude. Due to some edge cases with nib
files, the SDK doesn't swizzle the loadView method of the
UIViewController subclasses, but instead, it swizzles the
UIViewController.loadView method directly. Although the SDK doesn't
swizzle the classes specified in swizzleClassNameExclude, it created
transactions. Now, this is fixed.

Fixes GH-4386
philipphofmann added a commit that referenced this issue Oct 7, 2024
Skip creating transactions for UIViewControllers ignored for swizzling
via the option swizzleClassNameExclude. Due to some edge cases with nib
files, the SDK doesn't swizzle the loadView method of the
UIViewController subclasses, but instead, it swizzles the
UIViewController.loadView method directly. Although the SDK doesn't
swizzle the classes specified in swizzleClassNameExclude, it created
transactions. Now, this is fixed.

Fixes GH-4386
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant