File I/O

The sentry_file library provides File support for Sentry wrapping the File class with a SentryFile wrapper. The SentryFile is able to run performance monitoring for File operations.

The source can be found on GitHub.

On this page, we get you up and running with Sentry's file I/O integration, so that it will automatically start a span from an active transaction that's bound to the scope of each operation such as copy, create, delete, open, rename, read, and write.


To use the SentryFile wrapper, add the sentry_file dependency.

  sentry: ^7.7.0
  sentry_file: ^7.7.0


import 'package:sentry/sentry.dart';
import 'package:sentry_file/sentry_file.dart';
import 'dart:io';

Future<void> main() async {
  await Sentry.init(
    (options) {
      options.dsn = '';
      // To set a uniform sample rate
      options.tracesSampleRate = 1.0;
    appRunner: runApp, // Init your App.

Future<void> runApp() async {
  final file = File('my_file.txt');
  // Call the Sentry extension method to wrap up the File
  final sentryFile = file.sentryTrace();

  // Start a transaction if there's no active transaction
  final transaction = Sentry.startTransaction(
    bindToScope: true,

  // create the File
  await sentryFile.create();
  // Write some content
  await sentryFile.writeAsString('Hello World');
  // Read the content
  final text = await sentryFile.readAsString();


  // Delete the file
  await sentryFile.delete();

  // Finish the transaction
  await transaction.finish(status: SpanStatus.ok());

  await Sentry.close();

To view the recorded transaction, log into and open your project. Clicking Performance will open a page with transactions, where you can select the just recorded transaction with the name MyFileExample.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").