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: Fix FileIO tracking for macOS 15 and iOS 18 #4605

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

philprime
Copy link
Contributor

@philprime philprime commented Dec 6, 2024

Closes #4546

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

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

github-actions bot commented Dec 6, 2024

Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

- Fix FileIO tracking for macOS 15 and iOS 18 ([#4605](https://github.com/getsentry/sentry-cocoa/pull/4605))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description.

Generated by 🚫 dangerJS against 74dd90c

@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 1233.23 ms 1251.71 ms 18.47 ms
Size 22.31 KiB 779.13 KiB 756.82 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
3a6495e 1227.61 ms 1239.22 ms 11.60 ms
869ab7e 1230.36 ms 1255.49 ms 25.13 ms
5f6f658 1221.08 ms 1241.84 ms 20.76 ms
be4734f 1216.47 ms 1237.47 ms 21.00 ms
742d4b6 1230.41 ms 1247.23 ms 16.83 ms
89491ad 1222.12 ms 1231.96 ms 9.83 ms
ef284b2 1211.76 ms 1229.69 ms 17.93 ms
d77a671 1236.63 ms 1250.66 ms 14.03 ms
a2af9fa 1236.29 ms 1251.67 ms 15.38 ms
533859f 1211.33 ms 1228.76 ms 17.43 ms

App size

Revision Plain With Sentry Diff
3a6495e 21.58 KiB 422.66 KiB 401.08 KiB
869ab7e 20.76 KiB 432.88 KiB 412.11 KiB
5f6f658 21.58 KiB 699.25 KiB 677.67 KiB
be4734f 22.30 KiB 749.84 KiB 727.54 KiB
742d4b6 21.58 KiB 546.20 KiB 524.62 KiB
89491ad 21.58 KiB 417.89 KiB 396.30 KiB
ef284b2 20.76 KiB 401.36 KiB 380.60 KiB
d77a671 21.58 KiB 540.04 KiB 518.46 KiB
a2af9fa 20.76 KiB 432.88 KiB 412.11 KiB
533859f 22.85 KiB 408.84 KiB 385.99 KiB

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

Startup times

Revision Plain With Sentry Diff
80a6dda 1239.90 ms 1252.33 ms 12.43 ms
1f201e0 1231.24 ms 1254.83 ms 23.59 ms
8b628ff 1213.15 ms 1239.17 ms 26.01 ms

App size

Revision Plain With Sentry Diff
80a6dda 22.30 KiB 751.72 KiB 729.42 KiB
1f201e0 22.30 KiB 751.69 KiB 729.39 KiB
8b628ff 22.30 KiB 751.72 KiB 729.42 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 28.16901% with 255 lines in your changes missing coverage. Please review.

Project coverage is 90.562%. Comparing base (b34716f) to head (74dd90c).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
Sources/Swift/Helper/SentryDataWrapper.swift 0.000% 199 Missing ⚠️
...ance/IO/SentryFileIOTrackingIntegrationTests.swift 58.823% 35 Missing ⚠️
Sources/Sentry/SentryNSFileManagerSwizzling.m 50.000% 20 Missing ⚠️
Sources/Sentry/SentryFileIOTracker.m 87.500% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #4605       +/-   ##
=============================================
- Coverage   91.018%   90.562%   -0.457%     
=============================================
  Files          617       619        +2     
  Lines        70935     71375      +440     
  Branches     25337     25438      +101     
=============================================
+ Hits         64564     64639       +75     
- Misses        6279      6644      +365     
  Partials        92        92               
Files with missing lines Coverage Δ
Sources/Sentry/SentryFileIOTrackingIntegration.m 100.000% <100.000%> (ø)
Sources/Sentry/SentryNSDataSwizzling.m 100.000% <100.000%> (ø)
...ions/Performance/IO/SentryFileIOTrackerTests.swift 99.378% <100.000%> (ø)
...ance/IO/SentryFileIOTrackingIntegrationObjCTests.m 96.153% <ø> (ø)
Sources/Sentry/SentryFileIOTracker.m 95.483% <87.500%> (ø)
Sources/Sentry/SentryNSFileManagerSwizzling.m 50.000% <50.000%> (ø)
...ance/IO/SentryFileIOTrackingIntegrationTests.swift 80.212% <58.823%> (-12.363%) ⬇️
Sources/Swift/Helper/SentryDataWrapper.swift 0.000% <0.000%> (ø)

... and 17 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 b34716f...74dd90c. 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

Comment on lines +349 to +353
public func write(to url: URL, options: Data.WritingOptions = []) throws {
// TODO: begin file.write via static tracker
try self.data.write(to: url, options: options)
// TODO: end file.write via static tracker
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@philipphofmann @brustolin @armcknight

This is my draft for a wrapper for Swift.Data, as it does not bridge to NSData anymore.

I created a Swift struct that can mostly be used as a direct drop-in replacement for Swift.Data (it's a @frozen struct so I don't think we can "subclass"/swizzle/monkey-patch).
I also considered creating this wrapper as an Objective-C file, if I am not mistaken this would require to use NSData, because AFAIK we can not use the Swift.Data struct from Objective-C classes.

Is this the right approach? Right now I am not sure how to access the hub from here and create the file.read/write spans. If we want to mimic the swizzling in SentryNSDataSwizzling.m, we would need access to the SentryNSDataSwizzling.shared.dataTracker or similar

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.

File IO integration not working for iOS 18
2 participants