Hive Database Instrumentation

(New in version 7.13.1)

The sentry_hive package provides Hive support for database instrumentation. The source can be found on GitHub. You must Set Up Performance monitoring to capture transactions for this integration to work.

Install

Add the sentry_hive dependency to install the Hive database instrumentation.

pubspec.yaml
Copied
dependencies:
sentry_flutter: ^7.14.0
sentry_hive: ^7.14.0
path_provider: ^2.0.0

Configure

Use SentryHive to initialize the instance:

Copied
import 'package:path_provider/path_provider.dart';
import 'package:sentry_hive/sentry_hive.dart';

final appDir = await getApplicationDocumentsDirectory();
SentryHive.init(appDir.path);

After configuring, you can use SentryHive for every CRUD operation which will be automatically instrumented and sent to Sentry.

Example

Copied
import 'package:sentry_hive/sentry_hive.dart';

Future<void> hiveTest() async {
    final tr = Sentry.startTransaction(
      'hiveTest',
      'db',
      bindToScope: true,
    );

    final appDir = await getApplicationDocumentsDirectory();
    SentryHive.init(appDir.path);

    final catsBox = await SentryHive.openBox<Map>('cats');
    await catsBox.put('fluffy', {'name': 'Fluffy', 'age': 4});
    await catsBox.put('loki', {'name': 'Loki', 'age': 2});
    await catsBox.clear();
    await catsBox.close();

    SentryHive.close();

    await tr.finish(status: const SpanStatus.ok());
}
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").