-
-
Notifications
You must be signed in to change notification settings - Fork 341
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 extension for FileManager to track file I/O operations with Sentry #4863
base: main
Are you sure you want to change the base?
Conversation
|
0db92ad
to
4182d91
Compare
🚨 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:
|
d10e11b
to
d3e66be
Compare
🚨 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:
|
2 similar comments
🚨 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:
|
🚨 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:
|
9bb9c45
to
95d1308
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4863 +/- ##
=============================================
+ Coverage 92.175% 92.338% +0.163%
=============================================
Files 659 662 +3
Lines 77491 78435 +944
Branches 27260 28458 +1198
=============================================
+ Hits 71428 72426 +998
+ Misses 5968 5913 -55
- Partials 95 96 +1
... and 24 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great; with a few improvements, this will be an excellent feature.
let tempDir = URL(fileURLWithPath: NSTemporaryDirectory()) | ||
.appendingPathComponent("test-\(testName.hashValue.description)") | ||
try! FileManager.default | ||
.createDirectory(at: tempDir, withIntermediateDirectories: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m
: Same as #4862 (comment).
private class Fixture { | ||
|
||
let data = "SOME DATA".data(using: .utf8)! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m
: Same as #4862 (comment).
contents: data, | ||
attributes: attr, | ||
origin: SentryTraceOrigin.manualFileData) { path, data, attr in | ||
self.createFile(atPath: path, contents: data, attributes: attr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m
: It would be great to have a test that fails when doing this because then we could seriously break users.
self.createFile(atPath: path, contents: data, attributes: attr) | |
self.createFile(atPath: path, contents: data, attributes: nil) |
XCTAssertEqual(span.data["file.path"] as? String, fixture.filePathToCreate) | ||
XCTAssertNil(span.data["file.size"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m
: Same as #4862 (comment)
guard let span = self.span(forPath: url.path, origin: origin, operation: SentrySpanOperation.fileRead) else { | ||
return try method(url, options) | ||
} | ||
defer { | ||
span.finish() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m
: Same as #4862 (comment) and this applies to all methods here.
/// - dstPath: The path at which to place the copy of `srcPath`. | ||
/// This path must include the name of the file or directory in its new location. | ||
/// - Note: See ``FileManager.copyItem(atPath:toPath:)`` for more information. | ||
func copyItemWithSentryTracing(at srcPath: String, to dstPath: String) throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
h
: This doesn't fully align with the naming of the FileManager API, if I'm not mistaken.
func copyItemWithSentryTracing(at srcPath: String, to dstPath: String) throws { | |
func copyItemWithSentryTracing(atPath srcPath: String, toPath dstPath: String) throws { |
/// - dstPath: The new path for the item in `srcPath`. | ||
/// This path must include the name of the file or directory in its new location. | ||
/// - Note: See ``FileManager.moveItem(atPath:toPath:)`` for more information. | ||
func moveItemWithSentryTracing(at srcPath: String, to dstPath: String) throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
h
: Again please align with the FileManager naming
func moveItemWithSentryTracing(at srcPath: String, to dstPath: String) throws { | |
func moveItemWithSentryTracing(atPath srcPath: String, toPath dstPath: String) throws { |
import SentryTestUtils | ||
import XCTest | ||
|
||
class FileManagerSentryTracingIntegrationTests: XCTestCase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
h
: These tests are quite extensive. It would be great to add some more to validate that the FileManager operations work correctly when the SDK isn't started.
This PR is derived from #4605
It introduces an extension to FileManager with these methods:
createFileWithSentryTracing(atPath:contents:attributes:)
mapped tocreateFile(atPath:contents:attributes:)
removeItemWithSentryTracing(at:)
mapped toremoveItem(at:)
removeItemWithSentryTracing(atPath:)
mapped toremoveItem(atPath:)
copyItemWithSentryTracing(at:to:)
mapped tocopyItem(at:to:)
copyItemWithSentryTracing(atPath:toPath:)
mapped tocopyItem(atPath:toPath)
moveItemWithSentryTracing(at:to:)
mapped tomoveItem(at:to:)
moveItemWithSentryTracing(atPath:toPath:)
mapped tomoveItem(atPath:toPath:)
Blocked by: