Skip to content

Commit 1c6be04

Browse files
denrasebuenaflorvivianyentran
authored
feat(flutter): isar integration (#9181)
* Add isar page * Update docs/platforms/flutter/integrations/isar-instrumentation.mdx Co-authored-by: vivianyentran <20403606+vivianyentran@users.noreply.github.com> * Update isar-instrumentation.mdx * update text --------- Co-authored-by: Giancarlo Buenaflor <giancarlo_buenaflor@yahoo.com> Co-authored-by: vivianyentran <20403606+vivianyentran@users.noreply.github.com>
1 parent 41d91f3 commit 1c6be04

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
title: Isar Database Instrumentation
3+
description: "Learn more about the Sentry Isar Database Instrumentation for the Flutter SDK."
4+
caseStyle: camelCase
5+
supportLevel: production
6+
sdk: sentry.dart.flutter
7+
categories:
8+
- mobile
9+
---
10+
11+
<Include name="feature-stage-beta.mdx" />
12+
13+
_(New in version 7.16.0)_
14+
15+
Isar is a fast cross-platform database for Flutter.
16+
The [sentry_isar](https://pub.dev/packages/sentry_isar) package provides `Isar` support for database instrumentation and allows you to track the performance of your queries.
17+
18+
## Instrumentation Behaviour
19+
20+
The created spans will be attached to the transaction on the scope. If no transaction is on the scope the Isar span will not be sent to Sentry.
21+
22+
## Prerequisites
23+
24+
Before starting, ensure:
25+
26+
1. The Sentry Flutter SDK is initialized. Learn more [here](/platforms/flutter/#configure).
27+
2. Performance Monitoring is set up. Learn more [here](/platforms/flutter/performance/).
28+
29+
## Install
30+
31+
Add the `sentry_isar` dependency to install the Isar database instrumentation.
32+
33+
```yml {filename:pubspec.yaml}
34+
dependencies:
35+
sentry_flutter: ^{{@inject packages.version('sentry.dart.flutter', '7.16.0') }}
36+
sentry_isar: ^{{@inject packages.version('sentry.dart.isar', '7.16.0') }}
37+
path_provider: ^2.0.0
38+
```
39+
40+
## Configure
41+
42+
Use `SentryIsar` to initialize the instance:
43+
44+
```dart
45+
import 'package:path_provider/path_provider.dart';
46+
import 'package:sentry_flutter/sentry_flutter.dart';
47+
import 'package:sentry_isar/sentry_isar.dart';
48+
49+
import 'user.dart'; // Import your Isar model instead
50+
51+
final dir = await getApplicationDocumentsDirectory();
52+
final isar = await SentryIsar.open(
53+
[UserSchema],
54+
directory: dir.path,
55+
);
56+
```
57+
58+
## Verify
59+
60+
### 1. Execute the Code
61+
62+
```dart
63+
import 'package:path_provider/path_provider.dart';
64+
import 'package:sentry_flutter/sentry_flutter.dart';
65+
import 'package:sentry_isar/sentry_isar.dart';
66+
67+
import 'user.dart'; // Import your Isar model instead
68+
69+
Future<void> runApp() async {
70+
final tr = Sentry.startTransaction('isarTest', 'db', bindToScope: true);
71+
72+
final dir = await getApplicationDocumentsDirectory();
73+
74+
final isar = await SentryIsar.open(
75+
[UserSchema],
76+
directory: dir.path,
77+
);
78+
79+
final newUser = User()
80+
..name = 'Joe Dirt'
81+
..age = 36;
82+
83+
await isar.writeTxn(() async {
84+
await isar.users.put(newUser); // insert & update
85+
});
86+
87+
final existingUser = await isar.users.get(newUser.id); // get
88+
89+
await isar.writeTxn(() async {
90+
await isar.users.delete(existingUser!.id); // delete
91+
});
92+
93+
await tr.finish(status: const SpanStatus.ok());
94+
}
95+
```
96+
97+
### 2. View the Transaction on Sentry.io
98+
99+
To view the recorded transaction, log into [sentry.io](https://sentry.io). Use the left sidebar to navigate to the **Performance** page. Select your project and scroll down to the transactions table to see the just recorded transaction with the name `isarTest`. You can also use the search bar to find the transaction. Click on the transaction to open its **Transaction Summary** page for more performance details.

0 commit comments

Comments
 (0)