---
title: "Hive Database Instrumentation"
description: "Learn more about the Sentry Hive Database Instrumentation for the Flutter SDK."
url: https://docs.sentry.io/platforms/dart/guides/flutter/integrations/hive-instrumentation/
---

# Hive Database Instrumentation | Sentry for Flutter

References to "transactions" on this page apply to the default transaction mode. In stream mode, this integration creates service spans instead, and Sentry sends them as they finish. See [Streamed Spans](https://docs.sentry.io/platforms/dart/guides/flutter/tracing/streamed-spans.md) for more information.

This feature is currently in Beta. Beta features are still in progress and may have bugs. We recognize the irony.

*(New in version 7.13.1)*

Hive is a lightweight and fast key-value database for Flutter and Dart applications. The [sentry\_hive](https://pub.dev/packages/sentry_hive) package provides `Hive` support for database instrumentation and allows you to track the performance of your queries.

## [Instrumentation Behaviour](https://docs.sentry.io/platforms/dart/guides/flutter/integrations/hive-instrumentation.md#instrumentation-behaviour)

The created spans attach to the active span. In transaction mode, that's the transaction bound to the scope; in stream mode, it's the span started with `Sentry.startSpan()`. If no span is active, the Hive span won't be sent to Sentry.

## [Prerequisites](https://docs.sentry.io/platforms/dart/guides/flutter/integrations/hive-instrumentation.md#prerequisites)

Before starting, ensure:

1. The Sentry Flutter SDK is initialized. Learn more [here](https://docs.sentry.io/platforms/dart/guides/flutter.md#configure).
2. Tracing is set up. Learn more [here](https://docs.sentry.io/platforms/dart/guides/flutter/tracing.md).

## [Install](https://docs.sentry.io/platforms/dart/guides/flutter/integrations/hive-instrumentation.md#install)

Add the `sentry_hive` dependency to install the Hive database instrumentation.

```yml
dependencies:
sentry_flutter: ^9.26.0
sentry_hive: ^9.26.0
path_provider: ^2.0.0
```

## [Configure](https://docs.sentry.io/platforms/dart/guides/flutter/integrations/hive-instrumentation.md#configure)

Use `SentryHive` to initialize the instance:

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

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

## [Verify](https://docs.sentry.io/platforms/dart/guides/flutter/integrations/hive-instrumentation.md#verify)

### [1. Execute the Code](https://docs.sentry.io/platforms/dart/guides/flutter/integrations/hive-instrumentation.md#1-execute-the-code)

**Transaction Mode (Default)**

```dart
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());
}
```

**Stream Mode**

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

Future<void> hiveTest() async {
  await Sentry.startSpan('hiveTest', (span) async {
    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();
  }, parentSpan: null);
}
```

### [2. View the Transaction on Sentry.io](https://docs.sentry.io/platforms/dart/guides/flutter/integrations/hive-instrumentation.md#2-view-the-transaction-on-sentryio)

To view the recorded transaction, log into [sentry.io](https://sentry.io) and open your project. Clicking **Performance** will open a page with transactions, where you can select the just recorded transaction with the name `hiveTest`.
