Skip to content

Commit 573744a

Browse files
marandanetokahest
andauthored
sqflite integration for Flutter (#6500)
Co-authored-by: Karl Heinz Struggl <kahest@users.noreply.github.com>
1 parent 311984d commit 573744a

File tree

8 files changed

+99
-14
lines changed

8 files changed

+99
-14
lines changed

src/platform-includes/getting-started-primer/flutter.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Features:
3333
- [Slow and frozen frames](/platforms/flutter/performance/instrumentation/automatic-instrumentation/#slow-and-frozen-frames)
3434
- [AssetBundle Instrumentation](/platforms/flutter/performance/instrumentation/automatic-instrumentation/#assetbundle-instrumentation)
3535
- [File I/O Integration](/platforms/dart/configuration/integrations/file/)
36+
- [sqflite Database Instrumentation](/platforms/flutter/configuration/integrations/sqflite-instrumentation/)
3637
- [Logging Integration](/platforms/dart/configuration/integrations/logging)
3738
- [Screenshot attachments for errors](/platforms/flutter/enriching-events/screenshots/)
3839
- [View Hierarchy attachments for errors](/platforms/flutter/enriching-events/viewhierarchy/)

src/platforms/android/configuration/integrations/file-io.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Supported in Sentry Android Gradle Plugin version `3.0.0` and above.
1717

1818
The [Sentry Android Gradle Plugin](/platforms/android/gradle/) provides file I/O support through bytecode manipulation. The source can be found [on GitHub](https://github.com/getsentry/sentry-android-gradle-plugin/tree/main/plugin-build/src/main/kotlin/io/sentry/android/gradle/instrumentation).
1919

20-
On this page, we get you up and running with Sentry's file I/O integration, so that it will automatically start a span out of the active transaction, bound to the scope for each file input/output stream operation.
20+
On this page, we get you up and running with Sentry's file I/O integration, so that it will automatically start a span from an active transaction that's bound to the scope of each file input/output stream operation.
2121

2222
## Install
2323

src/platforms/android/configuration/integrations/fragment.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ categories:
1010

1111
The `sentry-android-fragment` library provides [Fragment](https://developer.android.com/jetpack/androidx/releases/fragment) support for Sentry using the [FragmentLifecycleIntegration](https://github.com/getsentry/sentry-java/blob/a5f30b43b1dad2634ce020809f3b52e0d564a22a/sentry-android-fragment/src/main/java/io/sentry/android/fragment/FragmentLifecycleIntegration.kt). The source can be found [on GitHub](https://github.com/getsentry/sentry-java/tree/main/sentry-android-fragment/src/main/java/io/sentry/android/fragment).
1212

13-
On this page, we get you up and running with Sentry's Fragment Integration, so that it will automatically add a breadcrumb for each fragment's lifecycle and start a span out of the active transaction bound to the scope for each launch of a fragment.
13+
On this page, we get you up and running with Sentry's Fragment Integration, so that it will automatically add a breadcrumb for each fragment's lifecycle and start a span from an active transaction that's bound to the scope of each launch of a fragment.
1414

1515
## Auto-Installation With the Sentry Android Gradle Plugin
1616

@@ -46,7 +46,7 @@ plugins {
4646

4747
Then, initialize the [Android SDK](/platforms/android/#configure).
4848

49-
The Android SDK automatically adds the `FragmentLifecycleIntegration` if the `sentry-android-fragment` dependency was found on the classpath. The integration is added with both `enableFragmentLifecycleBreadcrumbs` and `enableAutoFragmentLifecycleTracing` enabled.
49+
The Android SDK automatically adds the `FragmentLifecycleIntegration` if the `sentry-android-fragment` dependency was found on the classpath. The integration is added with both `enableFragmentLifecycleBreadcrumbs` and `enableAutoFragmentLifecycleTracing` enabled.
5050

5151
However, you can still override the default behaviour by adding your own instance of the `FragmentLifecycleIntegration`. For that, refer to the [manual installation](/platforms/android/configuration/integrations/fragment/#configure) section below.
5252

src/platforms/android/configuration/integrations/room-and-sqlite.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Supported in Sentry Android Gradle Plugin version `3.0.0` and above.
1717

1818
The [Sentry Android Gradle Plugin](/platforms/android/gradle/) provides Room and AndroidX SQLite support through bytecode manipulation. The source can be found [on GitHub](https://github.com/getsentry/sentry-android-gradle-plugin/tree/main/plugin-build/src/main/kotlin/io/sentry/android/gradle/instrumentation).
1919

20-
On this page, we get you up and running with Sentry's Room and SQLite Integration, so that it will automatically start a span out of the active transaction, bound to the scope for each sqlite/dao query.
20+
On this page, we get you up and running with Sentry's Room and SQLite Integration, so that it will automatically start a span from an active transaction that's bound to the scope of each sqlite/dao query.
2121

2222
## Install
2323

src/platforms/dart/common/performance/instrumentation/automatic-instrumentation.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ The Sentry-specific file I/O implementation starts a span out of the active span
3838

3939
In addition, the span contains other useful information such as `file.size` (raw number of bytes), `file.path` (an absolute path to the file), and `file.async` (`true` if the called method returns a `Future`, or `false` if it's a `Sync` call) as part of the `data` payload.
4040

41-
The span finishes once the operation has been executed. The span `status` is set to `SpanStatus.ok` if successful or `SpanStatus.internalError` if there was any error.
41+
The span finishes once the operation has been executed. The span `status` is then set to `SpanStatus.ok` if successful, or `SpanStatus.internalError` if there was an error.
4242

43-
When the operation throws an `Exception`, Sentry's SDK associates this exception to the running span. If you haven't set the SDK to swallow the exception and capture it, the span and `SentryEvent` will be linked when viewing it on the **Issue Details** page in [sentry.io](https://sentry.io).
43+
When the operation throws an `Exception`, Sentry's SDK associates it with the running span. If you haven't set the SDK to swallow and capture the exception, the span and `SentryEvent` will be shown as linked on the **Issue Details** page in [sentry.io](https://sentry.io).
4444

4545
For more information see our [file I/O integration](/platforms/dart/configuration/integrations/file/).

src/platforms/dart/configuration/integrations/file.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The `sentry_file` library provides [File](https://api.dart.dev/stable/2.18.5/dar
88

99
The source can be found [on GitHub](https://github.com/getsentry/sentry-dart/tree/main/file/).
1010

11-
On this page, we get you up and running with Sentry's file I/O integration, so that it will automatically start a span out of the active transaction, bound to the scope for operations such as `copy`, `create`, `delete`, `open`, `rename`, `read`, and `write`.
11+
On this page, we get you up and running with Sentry's file I/O integration, so that it will automatically start a span from an active transaction that's bound to the scope of each operation such as `copy`, `create`, `delete`, `open`, `rename`, `read`, and `write`.
1212

1313
<Note>
1414

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: sqflite Database Instrumentation
3+
caseStyle: camelCase
4+
supportLevel: production
5+
sdk: sentry.dart.sqflite
6+
description: "Learn more about the Sentry sqflite Database Instrumentation for the Flutter SDK."
7+
categories:
8+
- mobile
9+
---
10+
11+
<Include name="beta-note.mdx" />
12+
13+
_(New in version 7.2.0)_
14+
15+
The [sentry_sqflite](https://pub.dev/packages/sentry_sqflite) package provides `sqflite` support for database instrumentation. The source can be found [on GitHub](https://github.com/getsentry/sentry-dart/tree/main/sqflite). Note, that to capture transactions, you have to first <PlatformLink to="/performance/">set up performance monitoring</PlatformLink>.
16+
17+
## Install
18+
19+
Add the `sentry_sqflite` dependency to install the sqflite database instrumentation.
20+
21+
```yml {filename:pubspec.yaml}
22+
dependencies:
23+
sentry_flutter: ^{{ packages.version('sentry.dart.flutter', '7.2.0') }}
24+
sentry_sqflite: ^{{ packages.version('sentry.dart.sqflite', '7.2.0') }}
25+
sqflite: ^2.0.0
26+
```
27+
28+
## Configure
29+
30+
There are four ways to configure the sqflite database instrumentation:
31+
32+
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:
33+
34+
```dart
35+
import 'package:sentry_sqflite/sentry_sqflite.dart';
36+
import 'package:sqflite/sqflite.dart';
37+
38+
databaseFactory = SentrySqfliteDatabaseFactory();
39+
final database = await openDatabase('path/to/db');
40+
```
41+
42+
If you're using the `FFI` factories, you can instrument the `SentrySqfliteDatabaseFactory` with its factory:
43+
44+
```dart
45+
import 'package:sentry_sqflite/sentry_sqflite.dart';
46+
import 'package:sqflite/sqflite.dart';
47+
48+
databaseFactory = SentrySqfliteDatabaseFactory(databaseFactory: databaseFactoryFfi);
49+
final database = await openDatabase('path/to/db');
50+
```
51+
52+
By using the `openDatabaseWithSentry` wrapper. With this approach, only the database opened with this method will be instrumented:
53+
54+
```dart
55+
import 'package:sentry_sqflite/sentry_sqflite.dart';
56+
import 'package:sqflite/sqflite.dart';
57+
58+
final database = await openDatabaseWithSentry('path/to/db');
59+
// or final database = await openReadOnlyDatabaseWithSentry('path/to/db');
60+
```
61+
62+
By using the `SentryDatabase` wrapper, which can be used to instrument any `Database` instance:
63+
64+
```dart
65+
import 'package:sentry_sqflite/sentry_sqflite.dart';
66+
import 'package:sqflite/sqflite.dart';
67+
68+
final database = await openDatabase('path/to/db');
69+
final sentryDatabase = SentryDatabase(database);
70+
```
71+
72+
After configuring via one of the above methods, every `CRUD` operation, including database transactions and batches, will be automatically instrumented and sent to Sentry.
73+
74+
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.

src/platforms/flutter/common/performance/instrumentation/automatic-instrumentation.mdx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Learn more in our [User Interaction Instrumentation](/platforms/flutter/configur
9797

9898
### http.Client Library Instrumentation
9999

100-
The `http.Client` instrumentation, once added the `SentryHttpClient` and enabled the [performance](/platforms/flutter/performance/) feature, starts a span out of the active transaction bound to the scope for each HTTP Request. The SDK sets the span `operation` to `http.client` and `description` to request `$METHOD $url`; for example, `GET https://sentry.io`.
100+
The `http.Client` instrumentation, once added the `SentryHttpClient` and enabled the [performance](/platforms/flutter/performance/) feature, starts a span from an active transaction that's bound to the scope of each HTTP Request. The SDK sets the span `operation` to `http.client` and `description` to request `$METHOD $url`; for example, `GET https://sentry.io`.
101101

102102
The span finishes once the request has been executed. The span `status` depends on either the HTTP Response `code` or `SpanStatus.internalError()` if the `code` does not match any of Sentry's `SpanStatus`.
103103

@@ -107,7 +107,7 @@ For more information see our [SentryHttpClient integration](/platforms/dart/conf
107107

108108
### Dio HTTP Library Instrumentation
109109

110-
The Dio instrumentation starts a span out of the active transaction bound to the scope for each HTTP request. The SDK sets the span `operation` to `http.client` and the `description` to request `$METHOD $url`. For example, `GET https://sentry.io`.
110+
The Dio instrumentation starts a span from an active transaction that's bound to the scope of each HTTP request. The SDK sets the span `operation` to `http.client` and the `description` to request `$METHOD $url`. For example, `GET https://sentry.io`.
111111

112112
The span finishes once the request has been executed. The span `status` depends on either the HTTP response `code` or `SpanStatus.internalError()` if the `code` does not match any of Sentry's `SpanStatus` options.
113113

@@ -198,9 +198,9 @@ Future<void> main() async {
198198
}
199199
```
200200

201-
The `SentryAssetBundle` instrumentation starts a span out of the active transaction bound to the scope for each `load` and `loadString` call. The SDK sets the span `operation` to `file.read`.
201+
The `SentryAssetBundle` instrumentation starts a span from an active transaction that's bound to the scope of each `load` and `loadString` call. The SDK sets the span `operation` to `file.read`.
202202

203-
The `SentryAssetBundle` instrumentation starts a span out of the active transaction bound to the scope for each `loadStructuredData` call. The SDK sets the span `operation` to `serialize`.
203+
The `SentryAssetBundle` instrumentation starts a span from an active transaction that's bound to the scope of each `loadStructuredData` call. The SDK sets the span `operation` to `serialize`.
204204

205205
The `loadStructuredData` is an opt-out feature. The following example shows how to disable it:
206206

@@ -212,12 +212,22 @@ SentryAssetBundle(enableStructuredDataTracing: false)
212212

213213
### File I/O Instrumentation
214214

215-
The Sentry-specific file I/O implementation starts a span out of the active span, bound to the scope for each file I/O operation. The SDK sets the span `operation` to `file.copy`, `file.write`, `file.delete`, `file.open`, `file.read` or `file.rename`, and `description` to `filename` (for example, `file.txt`).
215+
The Sentry-specific file I/O instrumentation starts a span from an active transaction that's bound to the scope of each file I/O operation. The SDK sets the span `operation` to `file.copy`, `file.write`, `file.delete`, `file.open`, `file.read` or `file.rename`, and `description` to `filename` (for example, `file.txt`).
216216

217217
In addition, the span contains other useful information such as `file.size` (raw number of bytes), `file.path` (an absolute path to the file) and `file.async` (`true` if the called method returns a `Future`, or `false` if it's a `Sync` call) as part of the `data` payload.
218218

219-
The span finishes once the operation has been executed. The span `status` is set to `SpanStatus.ok` if successful or `SpanStatus.internalError` if there was any error.
219+
The span finishes once the operation has been executed. The span `status` is then set to `SpanStatus.ok` if successful, or `SpanStatus.internalError` if there was an error.
220220

221-
When the operation throws an `Exception`, Sentry's SDK associates this exception to the running span. If you haven't set the SDK to swallow the exception and capture it, the span and `SentryEvent` will be linked when viewing it on the **Issue Details** page in [sentry.io](https://sentry.io).
221+
When the operation throws an `Exception`, Sentry's SDK associates it with the running span. If you haven't set the SDK to swallow and capture the exception, the span and `SentryEvent` will be shown as linked on the **Issue Details** page in [sentry.io](https://sentry.io).
222222

223223
Learn more about our [file I/O integration](/platforms/dart/configuration/integrations/file/).
224+
225+
### sqflite Database Instrumentation
226+
227+
The sqflite database instrumentation starts a span from an active transaction that's bound to the scope of each `CRUD` operation.
228+
229+
The span finishes once the operation has been executed. The span `status` is then set to `SpanStatus.ok` if successful, or `SpanStatus.internalError` if there was an error.
230+
231+
When the operation throws an `Exception`, Sentry's SDK associates it with the running span. If you haven't set the SDK to swallow and capture the exception, the span and `SentryEvent` will be shown as linked on the **Issue Details** page in [sentry.io](https://sentry.io).
232+
233+
Learn more about our [sqflite Database Instrumentation](/platforms/flutter/configuration/integrations/sqflite-instrumentation/).

0 commit comments

Comments
 (0)