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 experimental flag to disable swizzling of NSData #4859

Merged
merged 13 commits into from
Feb 21, 2025

Conversation

philprime
Copy link
Contributor

This is a derived PR from #4605

As we want to allow users to choose between automatic instrumentation and manual file IO tracing, the newly introduced experimental flag allows disabling swizzling of NSData.

I chose to keep the current behavior of NSData swizzling being enabled by default when swizzling is enabled, and offer an option to disable it instead. This is a different approach than the experimental flag to enable swizzling of NSFileManager.

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/SentryNSDataSwizzling.m
  • Sources/Sentry/SentryNSFileManagerSwizzling.m

Copy link

github-actions bot commented Feb 18, 2025

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

Generated by 🚫 dangerJS against 3ffa255

@philprime philprime changed the base branch from philprime/file-io-tracking-fix to main February 18, 2025 10:07
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/SentryNSDataSwizzling.m
  • Sources/Sentry/SentryNSFileManagerSwizzling.m

Copy link

github-actions bot commented Feb 18, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1225.14 ms 1242.04 ms 16.90 ms
Size 22.31 KiB 821.66 KiB 799.35 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
2719ce6 1211.75 ms 1237.16 ms 25.41 ms
db31083 1227.69 ms 1243.56 ms 15.87 ms
e758449 1243.41 ms 1246.71 ms 3.31 ms
b18a037 1221.61 ms 1251.53 ms 29.92 ms
289c0b8 1245.63 ms 1253.76 ms 8.13 ms
7b022df 1220.53 ms 1227.56 ms 7.03 ms
27f970b 1234.21 ms 1243.98 ms 9.77 ms
dde49e2 1214.80 ms 1240.23 ms 25.43 ms
5f8ee7a 1249.48 ms 1252.20 ms 2.72 ms
e0291c9 1242.98 ms 1253.08 ms 10.10 ms

App size

Revision Plain With Sentry Diff
2719ce6 20.76 KiB 435.13 KiB 414.37 KiB
db31083 22.85 KiB 407.63 KiB 384.78 KiB
e758449 22.85 KiB 407.62 KiB 384.77 KiB
b18a037 21.58 KiB 706.71 KiB 685.12 KiB
289c0b8 22.85 KiB 407.67 KiB 384.82 KiB
7b022df 22.85 KiB 412.95 KiB 390.10 KiB
27f970b 21.58 KiB 706.97 KiB 685.39 KiB
dde49e2 21.58 KiB 706.70 KiB 685.12 KiB
5f8ee7a 22.85 KiB 411.93 KiB 389.08 KiB
e0291c9 22.85 KiB 413.50 KiB 390.65 KiB

Previous results on branch: philprime/file-io-swizzling

Startup times

Revision Plain With Sentry Diff
c4a3811 1234.71 ms 1253.65 ms 18.93 ms
a23a13d 1217.54 ms 1244.06 ms 26.52 ms
b7515cb 1230.78 ms 1246.98 ms 16.20 ms
1edf2c4 1238.43 ms 1250.00 ms 11.57 ms

App size

Revision Plain With Sentry Diff
c4a3811 22.31 KiB 821.15 KiB 798.83 KiB
a23a13d 22.31 KiB 821.26 KiB 798.94 KiB
b7515cb 22.31 KiB 821.26 KiB 798.94 KiB
1edf2c4 22.32 KiB 820.26 KiB 797.94 KiB

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/SentryNSDataSwizzling.m
  • Sources/Sentry/SentryNSFileManagerSwizzling.m

Copy link

codecov bot commented Feb 18, 2025

Codecov Report

Attention: Patch coverage is 96.55172% with 2 lines in your changes missing coverage. Please review.

Project coverage is 92.155%. Comparing base (2181106) to head (3ffa255).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ance/IO/SentryFileIOTrackingIntegrationTests.swift 94.871% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #4859       +/-   ##
=============================================
- Coverage   92.185%   92.155%   -0.031%     
=============================================
  Files          659       658        -1     
  Lines        77432     77336       -96     
  Branches     27243     27097      -146     
=============================================
- Hits         71381     71269      -112     
- Misses        5957      5975       +18     
+ Partials        94        92        -2     
Files with missing lines Coverage Δ
Sources/Sentry/SentryFileIOTrackingIntegration.m 100.000% <100.000%> (ø)
Sources/Sentry/SentryNSDataSwizzling.m 100.000% <100.000%> (ø)
Sources/Sentry/SentryNSFileManagerSwizzling.m 56.896% <100.000%> (+4.973%) ⬆️
Sources/Swift/SentryExperimentalOptions.swift 50.000% <100.000%> (+16.666%) ⬆️
...ance/IO/SentryFileIOTrackingIntegrationTests.swift 91.699% <94.871%> (+0.536%) ⬆️

... and 37 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 2181106...3ffa255. Read the comment docs.

Copy link
Member

@armcknight armcknight left a comment

Choose a reason for hiding this comment

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

I think we might have to modify the check in SentryBaseIntegration.shouldBeEnabledWithOptions:

if ((integrationOptions & kIntegrationOptionEnableFileIOTracing)
&& !options.enableFileIOTracing) {
[self logWithOptionName:@"enableFileIOTracing"];
return NO;

(Side note on that FYI: I think our process for checking whether an integration should be enabled is really convoluted, going back and forth between superclass and subclass, with the enum values. I have several local branches that simplify it and put it just into the subclasses, but that work stalled due to other priorities.)

Also, it seems wrong that we are able to change the logic in the swizzling wrappers without requiring changes in tests. WDYT @philipphofmann ?

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.

We need to algin the new option with the other options.

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/SentryNSDataSwizzling.m
  • Sources/Sentry/SentryNSFileManagerSwizzling.m

@philprime
Copy link
Contributor Author

I would like to propose that we enable swizzling the NSFileManager by default.

@philprime
Copy link
Contributor Author

@philipphofmann to pick up your comment and re-iterate everything that happened in #4605:

h: I just saw that I approved the PR for adding the option enableFileManagerSwizzling in GH-4634. As our other options related to auto-tracing don't contain swizzling, I suggest renaming disableDataSwizzling to enableDataTracing and enableFileManagerSwizzling to enableFileManagerTracing. As enableFileManagerSwizzling is experimental I think we don't need to deprecate it. We can simply rename it with pointing it out in the changelog.

I believe that we need to decide on the actual purpose of these flags, because they are getting mixed up right now.

In the currently released version we have these options:

  • enableSwizzling to enable swizzling
  • isTracingEnabled to enable tracing
  • enableAutoPerformanceTracing to enable auto performance tracing
  • enableFileIOTracing to enable file IO tracing

As the File IO integration only swizzled NSData before, these options are sufficient. Then we introduced swizzling of NSFileManager, but because swizzling can be dangerous it had to be enabled using enableFileManagerSwizzling (opt-in). A user could now enable swizzling of the file-manager to have both, but can also disable the entire integration by setting enableSwizzling to false.

As the file IO tracking integration only worked with swizzling this was fine.
Now we want to introduce manual file IO tracking in #4862 and #4863, which are also part of this integration.

The manual tracking does not use swizzling, therefore it should also work when enableSwizzling is set to false → that's why we remove it from the integration options, as these only include required options.

Now we are in a situation where swizzling is enabled and people use manual tracking which can cause conflicts. Therefore we need to allow them to keep enableSwizzling set to true because it is used by other integrations, but allow to explicitly disable swizzling for NSData and NSFileManager, that's what the two newly introduced options are for.

That's why I believe we should keep the naming at enableFileManagerSwizzling and enableDataSwizzling rather than enableFileManagerTracing or enableDataTracing, because that would also imply that you enable tracing in the manual methods in #4862 and #4863, which is not the case!

I don't see a point in introducing flags for the enabling the methods in #4862 or #4863, at least not in this PR right here.

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/SentryNSDataSwizzling.m
  • Sources/Sentry/SentryNSFileManagerSwizzling.m

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/SentryNSDataSwizzling.m
  • Sources/Sentry/SentryNSFileManagerSwizzling.m

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/SentryNSDataSwizzling.m
  • Sources/Sentry/SentryNSFileManagerSwizzling.m

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/SentryNSDataSwizzling.m
  • Sources/Sentry/SentryNSFileManagerSwizzling.m

@philprime philprime changed the title feat: Add experimental flag to disable swizzling of NSData feat: Add experimental flag to disable swizzling of NSData and NSFileManager Feb 20, 2025
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/SentryNSDataSwizzling.m
  • Sources/Sentry/SentryNSFileManagerSwizzling.m

@philprime philprime changed the title feat: Add experimental flag to disable swizzling of NSData and NSFileManager feat: Add experimental flag to disable swizzling of NSData Feb 20, 2025
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'm a bit confused why we turn on the fileManagerSwizzling by default.

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/SentryNSDataSwizzling.m
  • Sources/Sentry/SentryNSFileManagerSwizzling.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, when fixing the changelog.

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/SentryNSDataSwizzling.m
  • Sources/Sentry/SentryNSFileManagerSwizzling.m

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/SentryNSDataSwizzling.m
  • Sources/Sentry/SentryNSFileManagerSwizzling.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

@philprime philprime merged commit 25f4e43 into main Feb 21, 2025
71 of 74 checks passed
@philprime philprime deleted the philprime/file-io-swizzling branch February 21, 2025 13:08
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 this pull request may close these issues.

3 participants