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

fix: Callback issue for auto performance #1275

Merged
merged 1 commit into from
Aug 19, 2021

Conversation

philipphofmann
Copy link
Member

📜 Description

The auto performance instrumentation was sometimes not calling the original
method of the swizzled UIViewController, which lead to crashes. This is fixed now,
by always calling the callback for every swizzled method.

💡 Motivation and Context

A customer reported getting crashes from Sentry when upgrading to 7.2.0, which they didn't have in 7.1.4.

💚 How did you test it?

Unit tests.

📝 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • Review from the native team if needed
  • No breaking changes

🔮 Next steps

The auto performance instrumentation was sometimes not calling the original
method of the swizzled UIViewController, which lead to crashes. This is fixed now,
by always calling the callback for every swizzled method.
Comment on lines +42 to +68
[self limitOverride:@"loadView"
target:controller
callbackToOrigin:callbackToOrigin
block:^{
SentrySpanId *spanId = objc_getAssociatedObject(
controller, &SENTRY_UI_PERFORMANCE_TRACKER_SPAN_ID);

// If the user manually call loadView outside the lifecycle
// we don't start a new transaction and override the previous id stored.
if (spanId == nil) {
NSString *name = [SentryUIViewControllerSanitizer
sanitizeViewControllerName:controller];
spanId = [self.tracker
startSpanWithName:name
operation:SENTRY_VIEWCONTROLLER_RENDERING_OPERATION];

// use the target itself to store the spanId to avoid using a global
// mapper.
objc_setAssociatedObject(controller,
&SENTRY_UI_PERFORMANCE_TRACKER_SPAN_ID, spanId,
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

[self measurePerformance:@"loadView"
target:controller
callbackToOrigin:callbackToOrigin];
}];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't change anything in this big block and the other blocks below. I just renamed the parameter. Scroll down until my next comment for the actual change in this file.

@@ -228,7 +237,9 @@ - (void)viewControllerViewDidLayoutSubViews:(UIViewController *)controller
*/
- (void)limitOverride:(NSString *)description
target:(UIViewController *)viewController
callbackToOrigin:(void (^)(void))callbackToOrigin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You made it, here are the real changes in this file.

Copy link
Contributor

@marandaneto marandaneto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@codecov-commenter
Copy link

Codecov Report

Merging #1275 (b6007f1) into master (562ebc8) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1275      +/-   ##
==========================================
+ Coverage   95.62%   95.64%   +0.02%     
==========================================
  Files         150      150              
  Lines        5349     5354       +5     
==========================================
+ Hits         5115     5121       +6     
+ Misses        234      233       -1     
Impacted Files Coverage Δ
Sources/Sentry/SentryPerformanceTracker.m 100.00% <100.00%> (+1.51%) ⬆️
.../Sentry/SentryUIViewControllerPerformanceTracker.m 99.13% <100.00%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 562ebc8...b6007f1. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants