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 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f1f5a44
fix(tests): add swizzling for NSFileManager
philprime Dec 6, 2024
b196c30
Update CHANGELOG.MD
philprime Dec 6, 2024
c0bb33d
Add iOS 18 and macOS 15 to GH workflow tests
philprime Dec 6, 2024
bc22ac9
Revert removal of import statement
philprime Dec 6, 2024
effcf8e
fix: add OS availability check to file manager swizzling
philprime Dec 6, 2024
7bf668c
add tvOS 18 and mac catalyst to test workflows
philprime Dec 6, 2024
74dd90c
rename SentryNSDataTracker to SentryFileIOTracker; add SentryDataWrapper
philprime Dec 12, 2024
750052a
Merge remote-tracking branch 'origin/main' into philprime/file-io-tra…
philprime Dec 13, 2024
123871d
revert changes after splitting PR
philprime Dec 13, 2024
e002163
revert changes after splitting PR
philprime Dec 13, 2024
ef74f63
removed deprecated method
philprime Dec 16, 2024
dc8c924
Merge remote-tracking branch 'origin/main' into philprime/file-io-tra…
philprime Dec 16, 2024
11c4806
Remove header
philprime Dec 16, 2024
5dc2ead
add WIP for tracking file.read/file.write spans
philprime Dec 17, 2024
be33890
Merge remote-tracking branch 'origin/main' into philprime/file-io-tra…
philprime Dec 18, 2024
07abf5d
Merge remote-tracking branch 'origin/main' into philprime/file-io-tra…
philprime Dec 18, 2024
7047a61
wip
philprime Dec 18, 2024
036da29
add wip changes to reuse data tracker in Swift
philprime Dec 20, 2024
e6cf6f0
Merge remote-tracking branch 'origin/main' into philprime/file-io-tra…
philprime Jan 9, 2025
c856d5a
Merge remote-tracking branch 'origin/main' into philprime/file-io-tra…
philprime Jan 13, 2025
8a3a012
refactor to type extension
philprime Jan 13, 2025
b03c19a
add trace origin to swift file
philprime Jan 13, 2025
1e4c13e
add file io tracker to dependency container
philprime Jan 13, 2025
335207c
refactor changes
philprime Jan 13, 2025
b790458
wip
philprime Jan 13, 2025
4ff6f4e
revert changes in SentrySpanOperations.h
philprime Jan 13, 2025
4ef283e
add more tests, refactored tests
philprime Jan 13, 2025
f29de60
remove unused imported headers
philprime Jan 13, 2025
7f22a1d
Merge branch 'main' into philprime/file-io-tracking-fix
philprime Jan 13, 2025
89e13c0
add more verbose xcframework build logs
philprime Jan 14, 2025
3828edd
refactor measure methods to Swift
philprime Jan 14, 2025
7143715
Merge remote-tracking branch 'origin/main' into philprime/file-io-tra…
philprime Jan 14, 2025
0c917bb
Merge remote-tracking branch 'origin/main' into philprime/file-io-tra…
philprime Jan 14, 2025
f6954d2
Merge remote-tracking branch 'origin/main' into philprime/file-io-tra…
philprime Jan 16, 2025
444a139
applied feedback
philprime Jan 16, 2025
f1e4816
add defer to finish tracking nsdata
philprime Jan 16, 2025
7595a6a
Merge remote-tracking branch 'origin/main' into philprime/file-io-tra…
philprime Jan 22, 2025
530ca0e
Merge remote-tracking branch 'origin/main' into philprime/file-io-tra…
philprime Jan 23, 2025
185097a
fix changelog
philprime Jan 23, 2025
2ffd120
fix duplicate spans
philprime Jan 23, 2025
0ca0bcb
revert change in sample
philprime Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Use strlcpy to save session replay info path (#4740)

### Features

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

## 8.44.0-beta.1

### Fixes
Expand Down
30 changes: 24 additions & 6 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -787,15 +787,18 @@
A8AFFCD42907E0CA00967CD7 /* SentryRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8AFFCD32907E0CA00967CD7 /* SentryRequestTests.swift */; };
A8F17B2E2901765900990B25 /* SentryRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = A8F17B2D2901765900990B25 /* SentryRequest.m */; };
A8F17B342902870300990B25 /* SentryHttpStatusCodeRange.m in Sources */ = {isa = PBXBuildFile; fileRef = A8F17B332902870300990B25 /* SentryHttpStatusCodeRange.m */; };
D468C0622D3669A200964230 /* SentryFileIOTracker+SwiftHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D468C0612D3669A200964230 /* SentryFileIOTracker+SwiftHelpers.swift */; };
D48724DB2D352597005DE483 /* SentryTraceOrigin.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48724DA2D352591005DE483 /* SentryTraceOrigin.swift */; };
D48724E22D354D16005DE483 /* SentryTraceOriginTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48724E12D354D16005DE483 /* SentryTraceOriginTests.swift */; };
D48E8B8B2D3E79610032E35E /* SentryTraceOrigin.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48E8B8A2D3E79610032E35E /* SentryTraceOrigin.swift */; };
D48724DD2D354939005DE483 /* SentrySpanOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48724DC2D354934005DE483 /* SentrySpanOperation.swift */; };
D48724E02D3549CA005DE483 /* SentrySpanOperationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48724DF2D3549C6005DE483 /* SentrySpanOperationTests.swift */; };
D48724E22D354D16005DE483 /* SentryTraceOriginTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48724E12D354D16005DE483 /* SentryTraceOriginTests.swift */; };
D48E8B8B2D3E79610032E35E /* SentryTraceOrigin.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48E8B8A2D3E79610032E35E /* SentryTraceOrigin.swift */; };
D48E8B9D2D3E82AC0032E35E /* SentrySpanOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48E8B9C2D3E82AC0032E35E /* SentrySpanOperation.swift */; };
D4AF00212D2E92FD00F5F3D7 /* SentryNSFileManagerSwizzling.m in Sources */ = {isa = PBXBuildFile; fileRef = D4AF00202D2E92FD00F5F3D7 /* SentryNSFileManagerSwizzling.m */; };
D4AF00232D2E931000F5F3D7 /* SentryNSFileManagerSwizzling.h in Headers */ = {isa = PBXBuildFile; fileRef = D4AF00222D2E931000F5F3D7 /* SentryNSFileManagerSwizzling.h */; };
D4AF00252D2E93C400F5F3D7 /* SentryNSFileManagerSwizzlingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D4AF00242D2E93C400F5F3D7 /* SentryNSFileManagerSwizzlingTests.m */; };
D4C5F59A2D4249E6002A9BF6 /* DataSentryTracingIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4C5F5992D4249E0002A9BF6 /* DataSentryTracingIntegrationTests.swift */; };
D4EDF9842D0B2A210071E7B3 /* Data+SentryTracing.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4EDF9832D0B2A1D0071E7B3 /* Data+SentryTracing.swift */; };
D4F2B5352D0C69D500649E42 /* SentryCrashCTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4F2B5342D0C69D100649E42 /* SentryCrashCTests.swift */; };
D8019910286B089000C277F0 /* SentryCrashReportSinkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D801990F286B089000C277F0 /* SentryCrashReportSinkTests.swift */; };
D802994E2BA836EF000F0081 /* SentryOnDemandReplay.swift in Sources */ = {isa = PBXBuildFile; fileRef = D802994D2BA836EF000F0081 /* SentryOnDemandReplay.swift */; };
Expand Down Expand Up @@ -1891,15 +1894,18 @@
A8AFFCD32907E0CA00967CD7 /* SentryRequestTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryRequestTests.swift; sourceTree = "<group>"; };
A8F17B2D2901765900990B25 /* SentryRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryRequest.m; sourceTree = "<group>"; };
A8F17B332902870300990B25 /* SentryHttpStatusCodeRange.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryHttpStatusCodeRange.m; sourceTree = "<group>"; };
D468C0612D3669A200964230 /* SentryFileIOTracker+SwiftHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SentryFileIOTracker+SwiftHelpers.swift"; sourceTree = "<group>"; };
D48724DA2D352591005DE483 /* SentryTraceOrigin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryTraceOrigin.swift; sourceTree = "<group>"; };
D48724E12D354D16005DE483 /* SentryTraceOriginTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryTraceOriginTests.swift; sourceTree = "<group>"; };
D48E8B8A2D3E79610032E35E /* SentryTraceOrigin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryTraceOrigin.swift; sourceTree = "<group>"; };
D48724DC2D354934005DE483 /* SentrySpanOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySpanOperation.swift; sourceTree = "<group>"; };
D48724DF2D3549C6005DE483 /* SentrySpanOperationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySpanOperationTests.swift; sourceTree = "<group>"; };
D48724E12D354D16005DE483 /* SentryTraceOriginTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryTraceOriginTests.swift; sourceTree = "<group>"; };
D48E8B8A2D3E79610032E35E /* SentryTraceOrigin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryTraceOrigin.swift; sourceTree = "<group>"; };
D48E8B9C2D3E82AC0032E35E /* SentrySpanOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySpanOperation.swift; sourceTree = "<group>"; };
D4AF00202D2E92FD00F5F3D7 /* SentryNSFileManagerSwizzling.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryNSFileManagerSwizzling.m; sourceTree = "<group>"; };
D4AF00222D2E931000F5F3D7 /* SentryNSFileManagerSwizzling.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryNSFileManagerSwizzling.h; path = include/SentryNSFileManagerSwizzling.h; sourceTree = "<group>"; };
D4AF00242D2E93C400F5F3D7 /* SentryNSFileManagerSwizzlingTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryNSFileManagerSwizzlingTests.m; sourceTree = "<group>"; };
D4C5F5992D4249E0002A9BF6 /* DataSentryTracingIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataSentryTracingIntegrationTests.swift; sourceTree = "<group>"; };
D4EDF9832D0B2A1D0071E7B3 /* Data+SentryTracing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+SentryTracing.swift"; sourceTree = "<group>"; };
D4F2B5342D0C69D100649E42 /* SentryCrashCTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCrashCTests.swift; sourceTree = "<group>"; };
D800942628F82F3A005D3943 /* SwiftDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftDescriptor.swift; sourceTree = "<group>"; };
D801990F286B089000C277F0 /* SentryCrashReportSinkTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCrashReportSinkTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3634,8 +3640,6 @@
8ECC674325C23A1F000E2BF6 /* SentrySpanContext.m */,
622C08D929E554B9002571D4 /* SentrySpanContext+Private.h */,
8E4E7C7325DAAB49006AB9E2 /* SentrySpanProtocol.h */,
7B3B83712833832B0001FDEB /* SentrySpanOperations.h */,
622C08D729E546F4002571D4 /* SentryTraceOrigins.h */,
8E4E7C6C25DAAAFE006AB9E2 /* SentrySpan.h */,
84A789092C0E9F5800FF0803 /* SentrySpan+Private.h */,
8EC3AE7925CA23B600E7591A /* SentrySpan.m */,
Expand Down Expand Up @@ -3678,6 +3682,15 @@
name = Transaction;
sourceTree = "<group>";
};
D468C0602D36699700964230 /* IO */ = {
isa = PBXGroup;
children = (
D4EDF9832D0B2A1D0071E7B3 /* Data+SentryTracing.swift */,
D468C0612D3669A200964230 /* SentryFileIOTracker+SwiftHelpers.swift */,
);
path = IO;
sourceTree = "<group>";
};
D48724D92D35258A005DE483 /* Transactions */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3887,6 +3900,7 @@
D8739CF72BECFF92007D2F66 /* Performance */ = {
isa = PBXGroup;
children = (
D468C0602D36699700964230 /* IO */,
6294287F2CB3BF4E002C454C /* SwizzleClassNameExclude.swift */,
D8739CF82BECFFB5007D2F66 /* SentryTransactionNameSource.swift */,
);
Expand All @@ -3896,6 +3910,7 @@
D875ED09276CC83200422FAC /* IO */ = {
isa = PBXGroup;
children = (
D4C5F5992D4249E0002A9BF6 /* DataSentryTracingIntegrationTests.swift */,
D875ED0A276CC84700422FAC /* SentryFileIOTrackerTests.swift */,
D8CE69BB277E39C700C6EC5C /* SentryFileIOTrackingIntegrationObjCTests.m */,
D885266327739D01001269FC /* SentryFileIOTrackingIntegrationTests.swift */,
Expand Down Expand Up @@ -4873,6 +4888,7 @@
D84D2CC32C29AD120011AF8A /* SentrySessionReplay.swift in Sources */,
849B8F9B2C6E906900148E1F /* SentryUserFeedbackIntegrationDriver.swift in Sources */,
63FE70DF20DA4C1000CDBAE8 /* SentryCrashMonitorType.c in Sources */,
D468C0622D3669A200964230 /* SentryFileIOTracker+SwiftHelpers.swift in Sources */,
7BF9EF7E2722B91F00B5BBEF /* SentryDefaultObjCRuntimeWrapper.m in Sources */,
7BC3936E25B1AB72004F03D3 /* SentryLevelMapper.m in Sources */,
6304360B1EC0595B00C4D3FA /* SentryNSDataUtils.m in Sources */,
Expand All @@ -4892,6 +4908,7 @@
7BB65501253DC1B500887E87 /* SentryUserFeedback.m in Sources */,
7D5C441A237C2E1F00DAB0A3 /* SentrySDK.m in Sources */,
7D65260E237F649E00113EA2 /* SentryScope.m in Sources */,
D4EDF9842D0B2A210071E7B3 /* Data+SentryTracing.swift in Sources */,
84281C472A57905700EE88F2 /* SentrySample.m in Sources */,
84AC61D329F7541E009EEF61 /* SentryDispatchSourceWrapper.m in Sources */,
62A456E52B0370E0003F19A1 /* SentryUIEventTrackerTransactionMode.m in Sources */,
Expand Down Expand Up @@ -5183,6 +5200,7 @@
8E70B0FD25CB72BE002B3155 /* SentrySpanTests.swift in Sources */,
7BBD188F2448469A00427C76 /* HttpDateFormatter.swift in Sources */,
63FE720C20DA66EC00CDBAE8 /* SentryCrashMonitor_Tests.m in Sources */,
D4C5F59A2D4249E6002A9BF6 /* DataSentryTracingIntegrationTests.swift in Sources */,
D855B3EA27D652C700BCED76 /* TestCoreDataStack.swift in Sources */,
D8AE48C12C57B1550092A2A6 /* SentryLevelTests.swift in Sources */,
63FE721820DA66EC00CDBAE8 /* TestThread.m in Sources */,
Expand Down
16 changes: 16 additions & 0 deletions Sources/Sentry/SentryDependencyContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "SentryDispatchQueueWrapper.h"
#import "SentryDisplayLinkWrapper.h"
#import "SentryExtraContextProvider.h"
#import "SentryFileIOTracker.h"
#import "SentryFileManager.h"
#import "SentryInternalCDefines.h"
#import "SentryLog.h"
Expand Down Expand Up @@ -186,6 +187,21 @@ - (SentryThreadInspector *)threadInspector SENTRY_DISABLE_THREAD_SANITIZER(
return _threadInspector;
}

- (SentryFileIOTracker *)fileIOTracker SENTRY_DISABLE_THREAD_SANITIZER(
"double-checked lock produce false alarms")
{
if (_fileIOTracker == nil) {
@synchronized(sentryDependencyContainerLock) {
if (_fileIOTracker == nil) {
_fileIOTracker =
[[SentryFileIOTracker alloc] initWithThreadInspector:[self threadInspector]
processInfoWrapper:[self processInfoWrapper]];
}
}
}
return _fileIOTracker;
}

- (SentryDebugImageProvider *)debugImageProvider
{
@synchronized(sentryDependencyContainerLock) {
Expand Down
79 changes: 61 additions & 18 deletions Sources/Sentry/SentryFileIOTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#import "SentryThreadInspector.h"
#import "SentryTracer.h"

const NSString *SENTRY_TRACKING_COUNTER_KEY = @"SENTRY_TRACKING_COUNTER_KEY";

@interface SentryFileIOTracker ()

@property (nonatomic, assign) BOOL isEnabled;
Expand All @@ -32,6 +30,13 @@ @interface SentryFileIOTracker ()

@implementation SentryFileIOTracker

NSString *const SENTRY_TRACKING_COUNTER_KEY = @"SENTRY_TRACKING_COUNTER_KEY";

+ (instancetype)sharedInstance
{
return SentryDependencyContainer.sharedInstance.fileIOTracker;
}

- (instancetype)initWithThreadInspector:(SentryThreadInspector *)threadInspector
processInfoWrapper:(SentryNSProcessInfoWrapper *)processInfoWrapper
{
Expand Down Expand Up @@ -59,9 +64,10 @@ - (void)disable
- (BOOL)measureNSData:(NSData *)data
writeToFile:(NSString *)path
atomically:(BOOL)useAuxiliaryFile
origin:(NSString *)origin
method:(BOOL (^)(NSString *, BOOL))method
{
id<SentrySpan> span = [self startTrackingWritingNSData:data filePath:path];
id<SentrySpan> span = [self startTrackingWritingNSData:data filePath:path origin:origin];

BOOL result = method(path, useAuxiliaryFile);

Expand All @@ -74,10 +80,11 @@ - (BOOL)measureNSData:(NSData *)data
- (BOOL)measureNSData:(NSData *)data
writeToFile:(NSString *)path
options:(NSDataWritingOptions)writeOptionsMask
origin:(NSString *)origin
error:(NSError **)error
method:(BOOL (^)(NSString *, NSDataWritingOptions, NSError **))method
{
id<SentrySpan> span = [self startTrackingWritingNSData:data filePath:path];
id<SentrySpan> span = [self startTrackingWritingNSData:data filePath:path origin:origin];

BOOL result = method(path, writeOptionsMask, error);

Expand All @@ -88,9 +95,35 @@ - (BOOL)measureNSData:(NSData *)data
return result;
}

- (NSData *)measureNSDataFromFile:(NSString *)path method:(NSData * (^)(NSString *))method
- (BOOL)measureNSData:(NSData *)data
writeToURL:(NSURL *)url
options:(NSDataWritingOptions)writeOptionsMask
origin:(NSString *)origin
error:(NSError **)error
method:(BOOL (^)(NSURL *, NSDataWritingOptions, NSError **))method
{
// We dont track reads from a url that is not a file url
// because these reads are handled by NSURLSession and
// SentryNetworkTracker will create spans in these cases.
philprime marked this conversation as resolved.
Show resolved Hide resolved
if (![url.scheme isEqualToString:NSURLFileScheme])
return method(url, writeOptionsMask, error);

id<SentrySpan> span = [self startTrackingWritingNSData:data filePath:[url path] origin:origin];

BOOL result = method(url, writeOptionsMask, error);

if (span != nil) {
[self finishTrackingNSData:data span:span];
}

return result;
}

- (NSData *)measureNSDataFromFile:(NSString *)path
origin:(NSString *)origin
method:(NSData * (^)(NSString *))method
{
id<SentrySpan> span = [self startTrackingReadingFilePath:path];
id<SentrySpan> span = [self startTrackingReadingFilePath:path origin:origin];

NSData *result = method(path);

Expand All @@ -104,10 +137,11 @@ - (NSData *)measureNSDataFromFile:(NSString *)path method:(NSData * (^)(NSString

- (NSData *)measureNSDataFromFile:(NSString *)path
options:(NSDataReadingOptions)readOptionsMask
origin:(NSString *)origin
error:(NSError **)error
method:(NSData * (^)(NSString *, NSDataReadingOptions, NSError **))method
{
id<SentrySpan> span = [self startTrackingReadingFilePath:path];
id<SentrySpan> span = [self startTrackingReadingFilePath:path origin:origin];

NSData *result = method(path, readOptionsMask, error);

Expand All @@ -121,6 +155,7 @@ - (NSData *)measureNSDataFromFile:(NSString *)path

- (NSData *)measureNSDataFromURL:(NSURL *)url
options:(NSDataReadingOptions)readOptionsMask
origin:(NSString *)origin
error:(NSError **)error
method:(NSData * (^)(NSURL *, NSDataReadingOptions, NSError **))method
{
Expand All @@ -131,7 +166,7 @@ - (NSData *)measureNSDataFromURL:(NSURL *)url
if (![url.scheme isEqualToString:NSURLFileScheme])
return method(url, readOptionsMask, error);

id<SentrySpan> span = [self startTrackingReadingFilePath:url.path];
id<SentrySpan> span = [self startTrackingReadingFilePath:url.path origin:origin];

NSData *result = method(url, readOptionsMask, error);

Expand All @@ -146,11 +181,12 @@ - (NSData *)measureNSDataFromURL:(NSURL *)url
- (BOOL)measureNSFileManagerCreateFileAtPath:(NSString *)path
data:(NSData *)data
attributes:(NSDictionary<NSFileAttributeKey, id> *)attributes
origin:(NSString *)origin
method:
(BOOL (^)(NSString *_Nonnull, NSData *_Nonnull,
NSDictionary<NSFileAttributeKey, id> *_Nonnull))method
{
id<SentrySpan> span = [self startTrackingWritingNSData:data filePath:path];
id<SentrySpan> span = [self startTrackingWritingNSData:data filePath:path origin:origin];

BOOL result = method(path, data, attributes);

Expand All @@ -161,6 +197,7 @@ - (BOOL)measureNSFileManagerCreateFileAtPath:(NSString *)path
}

- (nullable id<SentrySpan>)spanForPath:(NSString *)path
origin:(NSString *)origin
operation:(NSString *)operation
size:(NSUInteger)size
{
Expand All @@ -175,20 +212,21 @@ - (BOOL)measureNSFileManagerCreateFileAtPath:(NSString *)path
}

__block id<SentrySpan> ioSpan;
[SentrySDK.currentHub.scope useSpan:^(id<SentrySpan> _Nullable span) {
SentryHub *hub = SentrySDK.currentHub;
SentryScope *scope = hub.scope;
[scope useSpan:^(id<SentrySpan> _Nullable span) {
ioSpan = [span startChildWithOperation:operation
description:[self transactionDescriptionForFile:path
fileSize:size]];
ioSpan.origin = SentryTraceOrigin.autoNSData;
ioSpan.origin = origin;
}];

if (ioSpan == nil) {
SENTRY_LOG_DEBUG(@"No transaction bound to scope. Won't track file IO operation.");
return nil;
}

SENTRY_LOG_DEBUG(
@"SentryNSDataTracker automatically started a new span with description: %@, operation: %@",
SENTRY_LOG_DEBUG(@"Automatically started a new span with description: %@, operation: %@",
ioSpan.description, operation);

[ioSpan setDataValue:path forKey:@"file.path"];
Expand Down Expand Up @@ -228,12 +266,17 @@ - (void)mainThreadExtraInfo:(id<SentrySpan>)span
}
}

- (nullable id<SentrySpan>)startTrackingWritingNSData:(NSData *)data filePath:(NSString *)path
- (nullable id<SentrySpan>)startTrackingWritingNSData:(NSData *)data
filePath:(NSString *)path
origin:(NSString *)origin
{
return [self spanForPath:path operation:SentrySpanOperation.fileWrite size:data.length];
return [self spanForPath:path
origin:origin
operation:SentrySpanOperation.fileWrite
size:data.length];
}

- (nullable id<SentrySpan>)startTrackingReadingFilePath:(NSString *)path
- (nullable id<SentrySpan>)startTrackingReadingFilePath:(NSString *)path origin:(NSString *)origin
{
// Some iOS versions nest constructors calls. This counter help us avoid create more than one
// span for the same operation.
Expand All @@ -245,7 +288,7 @@ - (void)mainThreadExtraInfo:(id<SentrySpan>)span
if (count)
return nil;

return [self spanForPath:path operation:SentrySpanOperation.fileRead size:0];
return [self spanForPath:path origin:origin operation:SentrySpanOperation.fileRead size:0];
}

- (void)endTrackingFile
Expand All @@ -269,7 +312,7 @@ - (void)finishTrackingNSData:(NSData *)data span:(id<SentrySpan>)span
[span setDataValue:[NSNumber numberWithUnsignedInteger:data.length] forKey:@"file.size"];
[span finish];

SENTRY_LOG_DEBUG(@"SentryNSDataTracker automatically finished span %@", span.description);
SENTRY_LOG_DEBUG(@"Automatically finished span %@", span.description);
}

- (BOOL)ignoreFile:(NSString *)path
Expand Down
Loading
Loading