You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/platforms/apple/common/tracing/instrumentation/automatic-instrumentation.mdx
+49-25Lines changed: 49 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -312,59 +312,87 @@ Starting with iOS 18, tvOS 18, and macOS 15 the Swift classes `Data` and `FileMa
312
312
313
313
### Manual File/IO Tracing
314
314
315
+
Starting with iOS 18.0, macOS 15.0, and tvOS 18.0, the Swift class `Data` can not be instrumented automatically anymore. Instead, you need to use Sentry-specific type extensions.
316
+
315
317
Starting with version 8.48.0, the Sentry SDK offers extensions for the types `Data` and `FileManager` to track reading and writing data, as well as creating, moving, copying, and deleting files.
316
318
317
-
The method signatures of the extension resemble the ones of the original types, but they add a span to the current transaction:
319
+
The method signatures of these extensions resemble those of the original types, but they add a span to the current transaction. These methods can be used even when the Sentry SDK is not enabled—they will fall back to the original methods in that case.
320
+
321
+
**Behavior:**
322
+
- The SDK only creates spans when there is an active transaction on the scope
323
+
- Only file URLs are tracked (non-file URLs like HTTP URLs are ignored, as they are handled by network tracing)
324
+
- File size is automatically tracked for read and write operations
325
+
- Spans finish with `ok` status on success or `internalError` status if an exception is thrown
326
+
- Exceptions thrown during operations are associated with the span
318
327
319
328
**Data Operations:**
320
329
321
-
- `Data.init(contentsOfUrlWithSentryTracing:)` for `Data(contentsOf:)`
322
-
- `data.writeWithSentryTracing(to:options:)` for `data.write(to:)`
330
+
- `Data.init(contentsOfWithSentryTracing:options:)` for `Data(contentsOf:options:)` - Creates spans with operation `file.read`
331
+
- `data.writeWithSentryTracing(to:options:)` for `data.write(to:options:)` - Creates spans with operation `file.write`
323
332
324
333
```swift {tabTitle:Swift}
325
334
// Read data from a file URL
326
-
let data = Data(contentsOfUrlWithSentryTracing: url)
335
+
let url = URL(fileURLWithPath: "/path/to/file.txt")
336
+
let data = try Data(contentsOfWithSentryTracing: url)
337
+
338
+
// Read with options
339
+
let dataWithOptions = try Data(contentsOfWithSentryTracing: url, options: [.alwaysMapped])
-`FileManager.createFileWithSentryTracing(atPath:contents:attributes:)` for `FileManager.createFile(atPath:contents:attributes:)`
335
-
-`FileManager.moveItemWithSentryTracing(at:to:)` for `FileManager.moveItem(at:to:)`
336
-
-`FileManager.moveItemWithSentryTracing(atPath:toPath:)` for `FileManager.moveItem(atPath:toPath:)`
337
-
-`FileManager.copyItemWithSentryTracing(at:to:)` for `FileManager.copyItem(at:to:)`
338
-
-`FileManager.copyItemWithSentryTracing(atPath:toPath:)` for `FileManager.copyItem(atPath:toPath:)`
339
-
-`FileManager.removeItemWithSentryTracing(at:)` for `FileManager.removeItem(at:)`
340
-
-`FileManager.removeItemWithSentryTracing(atPath:)` for `FileManager.removeItem(atPath:)`
350
+
-`FileManager.createFileWithSentryTracing(atPath:contents:attributes:)` for `FileManager.createFile(atPath:contents:attributes:)` - Creates spans with operation `file.write`
351
+
-`FileManager.moveItemWithSentryTracing(at:to:)` for `FileManager.moveItem(at:to:)` - Creates spans with operation `file.rename`
352
+
-`FileManager.moveItemWithSentryTracing(atPath:toPath:)` for `FileManager.moveItem(atPath:toPath:)` - Creates spans with operation `file.rename`
353
+
-`FileManager.copyItemWithSentryTracing(at:to:)` for `FileManager.copyItem(at:to:)` - Creates spans with operation `file.copy`
354
+
-`FileManager.copyItemWithSentryTracing(atPath:toPath:)` for `FileManager.copyItem(atPath:toPath:)` - Creates spans with operation `file.copy`
355
+
-`FileManager.removeItemWithSentryTracing(at:)` for `FileManager.removeItem(at:)` - Creates spans with operation `file.delete`
356
+
-`FileManager.removeItemWithSentryTracing(atPath:)` for `FileManager.removeItem(atPath:)` - Creates spans with operation `file.delete`
We recommend you disable the swizzling of `NSData` and `NSFileManager` when using manual file I/O tracing, as the internal behavior of these classes differs between platform versions and can cause duplicate spans in your traces.
389
+
**Important:**We recommend you disable the swizzling of `NSData` and `NSFileManager` when using manual file I/O tracing, as the internal behavior of these classes differs between platform versions and can cause duplicate spans in your traces.
362
390
363
391
```swift {tabTitle:Swift}
364
392
importSentry
365
393
366
394
SentrySDK.start { options in
367
-
options.dsn="___PUBLIC_DSN___";
395
+
options.dsn="___PUBLIC_DSN___"
368
396
options.enableFileIOTracing=true
369
397
options.enableDataSwizzling=false
370
398
options.enableFileManagerSwizzling=false
@@ -393,17 +421,13 @@ SentrySDK.start { options in
0 commit comments