drift_sentry 2.0.1 copy "drift_sentry: ^2.0.1" to clipboard
drift_sentry: ^2.0.1 copied to clipboard

An integration which adds support for performance tracing for the Drift package.

example/example.dart

// ignore_for_file: avoid_print

import 'dart:async';
import 'dart:io';

import 'package:drift/native.dart';
import 'package:drift_sentry/drift_sentry.dart';
import 'package:sentry/sentry.dart';

import 'database.dart';

const dsn = String.fromEnvironment('dsn');

void main() async {
  await runZonedGuarded(() async {
    await Sentry.init(
      (options) => options
        ..dsn = dsn
        ..tracesSampleRate = 1.0
        ..debug = true,
    );
    await _run();
    exit(0);
  }, (exception, stackTrace) async {
    await Sentry.close();
    stderr.writeln(exception.toString());
    exit(-1);
  });
}

Future<void> _run() async {
  final database = ExampleDatabase(
    NativeDatabase.memory().addSentry(),
  );

  final transaction = Sentry.startTransaction(
    'example-transaction',
    'db',
    bindToScope: true,
  );
  try {
    await database
        .into(database.products)
        .insert(ProductsCompanion.insert(title: 'My product'));

    final allProducts = await database.select(database.products).get();
    print('Products in database: $allProducts');

    transaction.status = const SpanStatus.ok();
  } catch (exception) {
    transaction.throwable = exception;
    transaction.status = const SpanStatus.internalError();
    rethrow;
  } finally {
    await transaction.finish();
  }
}
1
likes
110
pub points
48%
popularity

Publisher

unverified uploader

An integration which adds support for performance tracing for the Drift package.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

drift, meta, sentry

More

Packages that depend on drift_sentry