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

Open
wants to merge 43 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

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 98.73016% with 8 lines in your changes missing coverage. Please review.

Project coverage is 91.456%. Comparing base (d3ec39a) to head (f12b0c3).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ance/IO/SentryFileIOTrackingIntegrationTests.swift 98.104% 4 Missing ⚠️
...formance/IO/SentryFileIOTracker+SwiftHelpers.swift 93.103% 2 Missing ⚠️
Sources/Sentry/SentryFileIOTracker.m 96.666% 0 Missing and 1 partial ⚠️
...ions/Performance/IO/SentryFileIOTrackerTests.swift 99.090% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #4605       +/-   ##
=============================================
+ Coverage   91.372%   91.456%   +0.083%     
=============================================
  Files          626       630        +4     
  Lines        74411     75072      +661     
  Branches     26679     27003      +324     
=============================================
+ Hits         67991     68658      +667     
+ Misses        6322      6316        -6     
  Partials        98        98               
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%> (ø)
...tegrations/Performance/IO/Data+SentryTracing.swift 100.000% <100.000%> (ø)
...ormance/IO/DataSentryTracingIntegrationTests.swift 100.000% <100.000%> (ø)
Sources/Sentry/SentryFileIOTracker.m 95.930% <96.666%> (+0.446%) ⬆️
...ions/Performance/IO/SentryFileIOTrackerTests.swift 99.502% <99.090%> (+0.101%) ⬆️
...formance/IO/SentryFileIOTracker+SwiftHelpers.swift 93.103% <93.103%> (ø)
...ance/IO/SentryFileIOTrackingIntegrationTests.swift 95.502% <98.104%> (+2.479%) ⬆️

... and 24 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 d3ec39a...f12b0c3. 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
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 didn't give this a full pass yet cause I found one potential major issue that could require some significant changes to the PR, which could make plenty of comments obsolete.

Sources/Sentry/SentryFileIOTracker.m Outdated Show resolved Hide resolved
Sources/Sentry/SentryFileIOTracker.m Outdated Show resolved Hide resolved
Sources/Sentry/SentryFileIOTracker.m Show resolved Hide resolved
Sources/Sentry/include/SentryTraceOrigins.h Outdated Show resolved Hide resolved
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 draft January 22, 2025 13:59
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 January 23, 2025 14:31
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've now retried the failing workflow 7 times and keeps failing at different places, but they seem unrelated to my changes (i.e. ANR or timeouts).

@philipphofmann @brustolin would appreciate your assistance in debugging the CI failures.

@philipphofmann
Copy link
Member

About CI failures: We see timeouts failing all the time for GH actions. When running those tests locally, they are usually rock solid. This is giving us headaches already for years. The weird thing often is that sometimes we don't see these failures for a while and then they come back even when we don't change the code or the tests. I think we could consider defining a constant for test expectations timeouts which we set to 10 or 30 seconds just for CI. If you have a better idea please let me know. Another idea is to simply disable all the flaky tests, because it's better to have fewer tests we can trust than flaky tests.

@philprime
Copy link
Contributor Author

So @philipphofmann should we keep this PR open until we have stabilized CI?

Open PRs could be useful to test CI improvements, but it also keeps us from merging this.

@philipphofmann
Copy link
Member

philipphofmann commented Jan 27, 2025

So @philipphofmann should we keep this PR open until we have stabilized CI?

Open PRs could be useful to test CI improvements, but it also keeps us from merging this.

Flaky CI shouldn't stop us from merging this PR. We should address these issues separately. But if the CI continuously flakes, maybe it's some changes of this PR and not CI itself.

@philprime philprime enabled auto-merge (squash) January 28, 2025 08:13
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.

After we decide on the deduplication logic on spans, I will give this another review cause this can have a significant impact on the PR.

Comment on lines +16 to +17
// Using the bridging of `Data` to `NSData` caused issues on older versions of macOS.
// Therefore we do not use the `measureNSData` method.
Copy link
Member

Choose a reason for hiding this comment

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

m: It would be valuable to clarify which issues in the comment.

let tracker = SentryFileIOTracker.sharedInstance()
// Using the bridging of `Data` to `NSData` caused issues on older versions of macOS.
// Therefore we do not use the `measureNSData` method.
if #available(iOS 18, macOS 15, tvOS 18, *) {
Copy link
Member

Choose a reason for hiding this comment

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

h: I'm unsure about this approach. It still could occur that some OS versions switch back to bridging NSData, and then users would get duplicated spans. This also has the downside that people can't use this on older iOS versions when they, for example, disable swizzling. Instead, it would be great if we could implement some deduplication logic for duplicated spans. I still need to figure out how we can do this properly, and will get back to you.

Copy link
Member

Choose a reason for hiding this comment

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

We agreed in Slack to skip a deduplication logic because it's complicated to get it right, it's a lot of work, and most people won't need it. Instead, we should allow the use of manual API before iOS 18. If users want file IO spans, they need to use the manual API anyway, and they can turn off auto file IO instrumentation in general. With this, they avoid having duplicates before iOS 18. We need to mention that people should consider turning off auto file IO instrumentation when using the manual API.

@philprime philprime disabled auto-merge January 29, 2025 15:26
@@ -52,6 +52,10 @@
- Convert constants SentrySpanOperation to Swift (#4718)
- Convert constants SentryTraceOrigins to Swift (#4717)

### Features

- Add manual file IO tracking methods for Swift.Data (#4605)
Copy link

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.44.0.
    Consider moving the entry to the ## Unreleased section, please.

Copy link

github-actions bot commented Feb 6, 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/SentryNSDataSwizzling.m
  • Sources/Sentry/SentryNSFileManagerSwizzling.m

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

Successfully merging this pull request may close these issues.

File IO integration not working for iOS 18
4 participants