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 manual file IO tracking for Swift.Data and Swift.FileManager #4605

Open
wants to merge 53 commits into
base: main
Choose a base branch
from

Conversation

philprime
Copy link
Contributor

@philprime philprime commented Dec 6, 2024

Open Sub Tasks:

  • Decide if refactoring SentryNSDataTracker to SentryFileIOTracker
  • Decide if iOS/macOS availability check is necessary
  • Remove changes in GitHub Actions before merging, as the changes are in chore: Bump OS versions for unit tests #4542 instead
  • Fix unit tests in SentryFileIOTrackingIntegrationTests.swift

Out-of-scope for this PR:

  • Add checks to detect cascading spans created by swizzled methods calling other swizzled methods

Closes #4546

Separated into multiple PRs:

Copy link

github-actions bot commented Dec 6, 2024

🚨 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/SentryNSFileManagerSwizzling.m

@philprime
Copy link
Contributor Author

We could consider to refactor the class SentryNSDataTracker to a broader name like SentryFileIOTracker as we are adding methods not directly related to NSData

@philprime philprime changed the title fix(tests): add swizzling for NSFileManager DRAFT: fix(tests): add swizzling for NSFileManager Dec 6, 2024
Copy link

github-actions bot commented Dec 6, 2024

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1217.84 ms 1248.98 ms 31.14 ms
Size 22.31 KiB 782.39 KiB 760.07 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
db533ee 1228.96 ms 1248.23 ms 19.28 ms
8f397a7 1251.82 ms 1268.34 ms 16.52 ms
e324230 1254.92 ms 1262.92 ms 8.00 ms
7ca0491 1217.83 ms 1239.36 ms 21.53 ms
7cd187e 1196.51 ms 1226.04 ms 29.53 ms
eb41178 1228.06 ms 1248.37 ms 20.31 ms
7f14650 1249.73 ms 1269.88 ms 20.14 ms
1734d1b 1200.15 ms 1214.06 ms 13.92 ms
d9280ee 1208.27 ms 1229.51 ms 21.24 ms
1db04d8 1250.20 ms 1258.12 ms 7.92 ms

App size

Revision Plain With Sentry Diff
db533ee 21.58 KiB 547.02 KiB 525.44 KiB
8f397a7 20.76 KiB 420.55 KiB 399.79 KiB
e324230 22.85 KiB 408.88 KiB 386.03 KiB
7ca0491 21.90 KiB 708.33 KiB 686.43 KiB
7cd187e 20.76 KiB 401.66 KiB 380.90 KiB
eb41178 21.58 KiB 544.86 KiB 523.28 KiB
7f14650 22.84 KiB 402.63 KiB 379.79 KiB
1734d1b 21.58 KiB 418.82 KiB 397.23 KiB
d9280ee 21.58 KiB 669.82 KiB 648.23 KiB
1db04d8 20.76 KiB 435.50 KiB 414.74 KiB

Previous results on branch: philprime/file-io-tracking-fix

Startup times

Revision Plain With Sentry Diff
ef871ac 1207.49 ms 1231.92 ms 24.43 ms
ec1acc1 1237.65 ms 1250.54 ms 12.90 ms
e9ec0cb 1221.08 ms 1242.90 ms 21.81 ms
3588c99 1242.96 ms 1264.22 ms 21.27 ms
8b628ff 1213.15 ms 1239.17 ms 26.01 ms
1f201e0 1231.24 ms 1254.83 ms 23.59 ms
6a01c37 1229.94 ms 1243.82 ms 13.88 ms
e0cf4f9 1218.80 ms 1229.96 ms 11.16 ms
e7b3309 1233.23 ms 1251.71 ms 18.47 ms
85eb414 1232.55 ms 1255.69 ms 23.14 ms

App size

Revision Plain With Sentry Diff
ef871ac 22.31 KiB 776.76 KiB 754.44 KiB
ec1acc1 22.31 KiB 770.06 KiB 747.75 KiB
e9ec0cb 22.31 KiB 770.73 KiB 748.42 KiB
3588c99 22.31 KiB 778.24 KiB 755.93 KiB
8b628ff 22.30 KiB 751.72 KiB 729.42 KiB
1f201e0 22.30 KiB 751.69 KiB 729.39 KiB
6a01c37 22.31 KiB 778.67 KiB 756.36 KiB
e0cf4f9 22.31 KiB 773.79 KiB 751.48 KiB
e7b3309 22.31 KiB 779.13 KiB 756.82 KiB
85eb414 22.31 KiB 772.94 KiB 750.62 KiB

Copy link

github-actions bot commented Dec 6, 2024

🚨 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/SentryNSFileManagerSwizzling.m

@philprime philprime changed the title DRAFT: fix(tests): add swizzling for NSFileManager DRAFT: fix: add swizzling for NSFileManager Dec 6, 2024
@brustolin
Copy link
Contributor

Thanks for this investigation.

Since you enable testing for iOS 18.2, we have other I/O tests failing. We could solve them in a different PR that will merge to this one, or disable those tests before merging this to Main.

Copy link

github-actions bot commented Dec 6, 2024

🚨 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/SentryNSFileManagerSwizzling.m

Copy link

codecov bot commented Dec 6, 2024

Codecov Report

Attention: Patch coverage is 99.55668% with 7 lines in your changes missing coverage. Please review.

Project coverage is 92.395%. Comparing base (43a41b3) to head (e4be2f7).

Files with missing lines Patch % Lines
...ance/IO/SentryFileIOTrackingIntegrationTests.swift 98.104% 4 Missing ⚠️
Sources/Sentry/SentryFileIOTracker.m 97.674% 0 Missing and 1 partial ⚠️
...ormance/IO/DataSentryTracingIntegrationTests.swift 99.500% 1 Missing ⚠️
...ions/Performance/IO/SentryFileIOTrackerTests.swift 99.090% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #4605       +/-   ##
=============================================
+ Coverage   92.164%   92.395%   +0.231%     
=============================================
  Files          658       664        +6     
  Lines        77222     78688     +1466     
  Branches     27170     28579     +1409     
=============================================
+ Hits         71171     72704     +1533     
+ Misses        5957      5887       -70     
- Partials        94        97        +3     
Files with missing lines Coverage Δ
Sources/Sentry/SentryDependencyContainer.m 96.835% <100.000%> (+0.124%) ⬆️
Sources/Sentry/SentryFileIOTrackingIntegration.m 100.000% <100.000%> (ø)
Sources/Sentry/SentryNSDataSwizzling.m 100.000% <100.000%> (ø)
Sources/Sentry/SentryNSFileManagerSwizzling.m 100.000% <100.000%> (+47.058%) ⬆️
...tegrations/Performance/IO/Data+SentryTracing.swift 100.000% <100.000%> (ø)
...ons/Performance/IO/FileManager+SentryTracing.swift 100.000% <100.000%> (ø)
...formance/IO/SentryFileIOTracker+SwiftHelpers.swift 100.000% <100.000%> (ø)
Sources/Swift/SentryExperimentalOptions.swift 50.000% <100.000%> (+16.666%) ⬆️
...rmance/IO/FileManagerTracingIntegrationTests.swift 100.000% <100.000%> (ø)
.../SentryTests/Transactions/SentrySpanKeyTests.swift 100.000% <100.000%> (ø)
... and 6 more

... and 30 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 43a41b3...e4be2f7. Read the comment docs.

Copy link

github-actions bot commented Dec 6, 2024

🚨 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/SentryNSFileManagerSwizzling.m

@philprime philprime marked this pull request as draft December 12, 2024 09:49
@philprime philprime changed the title DRAFT: fix: add swizzling for NSFileManager fix: Fix FileIO tracking for macOS 15 and iOS 18 Dec 12, 2024
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 fix: Fix FileIO tracking for macOS 15 and iOS 18 fix: Fix FileIO tracking for macOS 15, iOS 18 and tvOS 18 Dec 13, 2024
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

github-actions bot commented Feb 13, 2025

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

Generated by 🚫 dangerJS against e4be2f7

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 removed the request for review from brustolin February 13, 2025 11:28
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 marked this pull request as ready for review February 13, 2025 15:46
@philprime
Copy link
Contributor Author

philprime commented Feb 13, 2025

@philipphofmann I added an experimental option to disable swizzling for NSData and added manual methods for Data and FileManager. I believe this PR is now ready for review.

While working on it, I added additional methods for copy, move and delete of files. We can also move that into another PR if worth the extra effort.

@philprime
Copy link
Contributor Author

We've decided in Slack that this PR is rather large and should be split into multiple ones (as far as possible).

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

@@ -7,6 +7,7 @@
- Add `showMaskPreview` to `SentrySDK.replay` api to debug replay masking (#4761)
- Session replay masking preview for SwiftUI (#4737)
- HTTP Breadcrumb level based on response status code (#4779) 4xx is warning, 5xx is error.
- Add manual file IO tracking methods for Swift.Data and Swift.FileManager (#4605)

Choose a reason for hiding this comment

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

  • 🚫 The changelog entry seems to be part of an already released section ## 8.45.0.
    Consider moving the entry to the ## Unreleased section, please.

@philipphofmann
Copy link
Member

@philprime does it still make sense to keep this PR open? Can't we close this?

@philprime
Copy link
Contributor Author

I want this to stay open so I can verify after everything is merged that I did not miss anything

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

Successfully merging this pull request may close these issues.

File IO integration not working for iOS 18
4 participants