sqflite Database Instrumentation
This feature is currently in Beta. Beta features are still in-progress and may have bugs. We recognize the irony.
(New in version 7.2.0)
The sentry_sqflite package provides sqflite
support for database instrumentation. The source can be found on GitHub. Note, that to capture transactions, you have to first set up performance monitoring.
Install
Add the sentry_sqflite
dependency to install the sqflite database instrumentation.
pubspec.yaml
dependencies:
sentry_flutter: ^7.7.0
sentry_sqflite: ^7.7.0
sqflite: ^2.0.0
Configure
There are four ways to configure the sqflite database instrumentation:
By using the global databaseFactory
, (which is used by the openDatabase
method). With this approach, every call to openDatabase
will be instrumented, including from other packages:
import 'package:sentry_sqflite/sentry_sqflite.dart';
import 'package:sqflite/sqflite.dart';
databaseFactory = SentrySqfliteDatabaseFactory();
final database = await openDatabase('path/to/db');
If you're using the FFI
factories, you can instrument the SentrySqfliteDatabaseFactory
with its factory:
import 'package:sentry_sqflite/sentry_sqflite.dart';
import 'package:sqflite/sqflite.dart';
databaseFactory = SentrySqfliteDatabaseFactory(databaseFactory: databaseFactoryFfi);
final database = await openDatabase('path/to/db');
By using the openDatabaseWithSentry
wrapper. With this approach, only the database opened with this method will be instrumented:
import 'package:sentry_sqflite/sentry_sqflite.dart';
import 'package:sqflite/sqflite.dart';
final database = await openDatabaseWithSentry('path/to/db');
// or final database = await openReadOnlyDatabaseWithSentry('path/to/db');
By using the SentryDatabase
wrapper, which can be used to instrument any Database
instance:
import 'package:sentry_sqflite/sentry_sqflite.dart';
import 'package:sqflite/sqflite.dart';
final database = await openDatabase('path/to/db');
final sentryDatabase = SentryDatabase(database);
After configuring via one of the above methods, every CRUD
operation, including database transactions and batches, will be automatically instrumented and sent to Sentry.
The spans' operation
are either db
, db.sql.execute
, db.sql.query
or db.sql.transaction
. Its description
is the SQL statement using placeholders instead of its values due to the possibility of containing PII.
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").
- Package:
- pub:sentry_flutter
- Version:
- 7.7.0
- Repository:
- https://github.com/getsentry/sentry-dart