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

feat: add method unswizzling #4647

Merged
merged 12 commits into from
Jan 8, 2025
Merged

feat: add method unswizzling #4647

merged 12 commits into from
Jan 8, 2025

Conversation

philprime
Copy link
Contributor

@philprime philprime commented Dec 19, 2024

📜 Description

I adapted the method swizzling helper to keep a reference to the original implementation, so that the unswizzle methods can revert swizzling.

💡 Motivation and Context

We are introducing a new experimental flag in #4634 to conditionally swizzle Objective-C methods. Therefore some unit tests (e.g testFoo) swizzle methods, while others (e.g. testBar) do not. If we do not offer a functionality to unswizzle methods, they are leaking isolation, i.e. testFoo runs before testBar therefore methods are swizzled, even tough we don't want that.

This is required for #4634 to pass tests.

💚 How did you test it?

I added a unit test to test the unswizzling.

📝 Checklist

You have to check all boxes before merging:

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

  • Change unswizzling to be wrapped by #if TEST to not be used in production

Copy link

🚨 Detected changes in high risk code 🚨

High-risk code can easily blow up and is hard to test. We had severe bugs in the past. Be extra careful when changing these files, and have an extra careful look at these:

  • Sources/Sentry/SentrySwizzle.m

Copy link

github-actions bot commented Dec 19, 2024

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against afb35fb

Copy link

🚨 Detected changes in high risk code 🚨

High-risk code can easily blow up and is hard to test. We had severe bugs in the past. Be extra careful when changing these files, and have an extra careful look at these:

  • Sources/Sentry/SentrySwizzle.m

@philprime philprime marked this pull request as ready for review December 19, 2024 09:59
@philprime philprime self-assigned this Dec 19, 2024
Copy link

codecov bot commented Dec 19, 2024

Codecov Report

Attention: Patch coverage is 90.07092% with 14 lines in your changes missing coverage. Please review.

Project coverage is 91.232%. Comparing base (f69e4da) to head (afb35fb).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
Sources/Sentry/SentrySwizzle.m 84.615% 14 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #4647       +/-   ##
=============================================
+ Coverage   91.140%   91.232%   +0.091%     
=============================================
  Files          621       622        +1     
  Lines        71497     71791      +294     
  Branches     25311     26147      +836     
=============================================
+ Hits         65163     65497      +334     
+ Misses        6239      6194       -45     
- Partials        95       100        +5     
Files with missing lines Coverage Δ
...ources/Sentry/include/HybridPublic/SentrySwizzle.h 97.142% <ø> (ø)
Tests/SentryTests/Helper/SentrySwizzleTests.m 93.442% <100.000%> (+1.690%) ⬆️
Sources/Sentry/SentrySwizzle.m 90.607% <84.615%> (-4.074%) ⬇️

... and 50 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

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

Copy link

github-actions bot commented Dec 19, 2024

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1228.39 ms 1242.94 ms 14.55 ms
Size 22.31 KiB 766.26 KiB 743.95 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
fcde045 1260.71 ms 1275.00 ms 14.29 ms
b16d18c 1245.60 ms 1250.94 ms 5.34 ms
51ffd8c 1194.60 ms 1215.70 ms 21.10 ms
a9dece3 1224.96 ms 1245.27 ms 20.31 ms
27f970b 1223.48 ms 1239.51 ms 16.03 ms
7bb0873 1226.18 ms 1247.30 ms 21.12 ms
4bdf3dc 1232.56 ms 1252.81 ms 20.25 ms
8aba9c4 1236.94 ms 1248.29 ms 11.35 ms
1734d1b 1200.15 ms 1214.06 ms 13.92 ms
e9fa2b0 1226.22 ms 1248.47 ms 22.24 ms

App size

Revision Plain With Sentry Diff
fcde045 20.76 KiB 435.26 KiB 414.50 KiB
b16d18c 20.76 KiB 437.12 KiB 416.36 KiB
51ffd8c 21.58 KiB 418.70 KiB 397.11 KiB
a9dece3 21.58 KiB 546.20 KiB 524.62 KiB
27f970b 21.58 KiB 706.97 KiB 685.39 KiB
7bb0873 22.85 KiB 407.09 KiB 384.24 KiB
4bdf3dc 20.76 KiB 434.94 KiB 414.18 KiB
8aba9c4 21.58 KiB 544.72 KiB 523.14 KiB
1734d1b 21.58 KiB 418.82 KiB 397.23 KiB
e9fa2b0 21.58 KiB 629.61 KiB 608.03 KiB

Previous results on branch: philprime/unswizzling

Startup times

Revision Plain With Sentry Diff
a9a5b1c 1234.60 ms 1254.16 ms 19.56 ms
1f239e8 1233.94 ms 1253.76 ms 19.82 ms
4c753cb 1218.83 ms 1236.60 ms 17.77 ms

App size

Revision Plain With Sentry Diff
a9a5b1c 22.32 KiB 761.25 KiB 738.94 KiB
1f239e8 22.30 KiB 760.63 KiB 738.32 KiB
4c753cb 22.31 KiB 766.22 KiB 743.91 KiB

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

FYI, we already tried that in the past and it always blew up the tests. We instead chose a different approach: We don't unswizzle, but we make sure the operations are NoOps when closing the SDK. I mean we can try again, but we need some good reasons. What drove you to open this PR?

@philprime
Copy link
Contributor Author

@philipphofmann in #4634 I added unit tests initializing the SentrySDK with an experimental feature flag enabled or disabled. If the SentrySDK is enabled, and swizzling happens, the swizzling remains even after closing and re-enabling the SentrySDK without swizzling.

We could also change this PR to only unswizzle in unit tests, i.e. using #if TEST

@brustolin
Copy link
Contributor

We could also change this PR to only unswizzle in unit tests, i.e. using #if TEST

I agree with this!!

Copy link

🚨 Detected changes in high risk code 🚨

High-risk code can easily blow up and is hard to test. We had severe bugs in the past. Be extra careful when changing these files, and have an extra careful look at these:

  • Sources/Sentry/SentrySwizzle.m

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

I added a few comments. I'm fine to give this a shot for the tests, but definitely not in production cause swizzling can have drastic unwanted side effects.

Sources/Sentry/SentrySwizzle.m Show resolved Hide resolved
Sources/Sentry/SentrySwizzle.m Outdated Show resolved Hide resolved
Sources/Sentry/SentrySwizzle.m Outdated Show resolved Hide resolved
Sources/Sentry/SentrySwizzle.m Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Jan 7, 2025

🚨 Detected changes in high risk code 🚨

High-risk code can easily blow up and is hard to test. We had severe bugs in the past. Be extra careful when changing these files, and have an extra careful look at these:

  • Sources/Sentry/SentrySwizzle.m

1 similar comment
Copy link

github-actions bot commented Jan 7, 2025

🚨 Detected changes in high risk code 🚨

High-risk code can easily blow up and is hard to test. We had severe bugs in the past. Be extra careful when changing these files, and have an extra careful look at these:

  • Sources/Sentry/SentrySwizzle.m

Copy link

github-actions bot commented Jan 7, 2025

🚨 Detected changes in high risk code 🚨

High-risk code can easily blow up and is hard to test. We had severe bugs in the past. Be extra careful when changing these files, and have an extra careful look at these:

  • Sources/Sentry/SentrySwizzle.m

Copy link

github-actions bot commented Jan 7, 2025

🚨 Detected changes in high risk code 🚨

High-risk code can easily blow up and is hard to test. We had severe bugs in the past. Be extra careful when changing these files, and have an extra careful look at these:

  • Sources/Sentry/SentrySwizzle.m

Copy link

github-actions bot commented Jan 7, 2025

🚨 Detected changes in high risk code 🚨

High-risk code can easily blow up and is hard to test. We had severe bugs in the past. Be extra careful when changing these files, and have an extra careful look at these:

  • Sources/Sentry/SentrySwizzle.m

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

CHANGELOG.md Outdated Show resolved Hide resolved
Sources/Sentry/SentrySwizzle.m Show resolved Hide resolved
Sources/Sentry/include/HybridPublic/SentrySwizzle.h Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Jan 8, 2025

🚨 Detected changes in high risk code 🚨

High-risk code can easily blow up and is hard to test. We had severe bugs in the past. Be extra careful when changing these files, and have an extra careful look at these:

  • Sources/Sentry/SentrySwizzle.m

@philprime
Copy link
Contributor Author

FYI @philipphofmann I had to remove an NSCAssert from the swizzle method, because it is actually valid to call it with key set to NULL. Does not change the implementation, only affects logging.

@philprime philprime merged commit 036579d into main Jan 8, 2025
69 of 70 checks passed
@philprime philprime deleted the philprime/unswizzling branch January 8, 2025 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants