Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APM for hive #1672

Merged
merged 40 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7a9ea7d
setup sentry hive library
denrase Oct 10, 2023
2fa0411
Add SentryBox with first test
denrase Oct 10, 2023
071dd1e
test added spans
denrase Oct 10, 2023
bee44de
Merge branch 'main' into feat/hive
denrase Oct 16, 2023
5881d84
Add sentry hive impl
denrase Oct 16, 2023
296e25e
introduce base box to avoid duplication
denrase Oct 16, 2023
6ea6914
implement lazy box test
denrase Oct 17, 2023
e35a82d
expose sentry hive and updata documentation
denrase Oct 17, 2023
22bed30
add hive to flutter example app
denrase Oct 17, 2023
e5c2b9b
test throwing in base_box, cleanup
denrase Oct 23, 2023
7a41832
test lazy box error cases
denrase Oct 23, 2023
ee12365
test sentry hive impl failures
denrase Oct 23, 2023
f72c0a8
run fix & format
denrase Oct 23, 2023
8fa3182
fix test failure race condition
denrase Oct 23, 2023
08cfc16
add hive workflow, update other workflows
denrase Oct 23, 2023
69d6404
Merge branch 'main' into feat/hive
denrase Oct 23, 2023
f5dd006
add changelog entry
denrase Oct 23, 2023
9237bee
remove path+provider from dev_dependencies
denrase Oct 23, 2023
887adb0
add coverage dev dependency
denrase Oct 23, 2023
ea89cf6
fix deprecation warnings
denrase Oct 23, 2023
8c7e7cc
Merge branch 'main' into feat/hive
denrase Oct 30, 2023
5f7c196
fix changelog
denrase Oct 30, 2023
2ca2783
move span wrapping on own class to avoid duplication
denrase Oct 30, 2023
380c8a2
add sentry box collection
denrase Oct 30, 2023
71d3f8e
test added spans, fix imports
denrase Oct 31, 2023
d286b62
test throwing code
denrase Oct 31, 2023
1f9c37f
Merge branch 'main' into feat/hive
denrase Oct 31, 2023
9e02a29
fix changelog
denrase Oct 31, 2023
e888f6f
Merge branch 'main' into feat/hive
denrase Nov 6, 2023
22a1637
change dbSystem value
denrase Nov 6, 2023
d959c80
Merge branch 'main' into feat/hive
denrase Nov 6, 2023
158f93f
change db system
denrase Nov 6, 2023
aeed961
Merge branch 'main' into feat/hive
denrase Nov 13, 2023
f99d255
remove unneccessary async & await
denrase Nov 13, 2023
da8309f
Merge branch 'main' into feat/hive
buenaflor Nov 15, 2023
7119d74
Fix analyze
buenaflor Nov 15, 2023
34ea841
Formatting
buenaflor Nov 15, 2023
2db8de9
Add changelog symlink
buenaflor Nov 15, 2023
fccc34c
Ignore hive coverage
buenaflor Nov 15, 2023
19ebd4b
Create symlink for dartdoc_options
buenaflor Nov 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- "dio/**"
- "file/**"
- "sqflite/**"
- "hive/**"

jobs:
cancel-previous-workflow:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/diagrams.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ jobs:
working-directory: ./logging
run: lakos . -i "{test/**,example/**}" | dot -Tsvg -o class-diagram.svg

- name: hive
working-directory: ./hive
run: lakos . -i "{test/**,example/**}" | dot -Tsvg -o class-diagram.svg

# Source: https://stackoverflow.com/a/58035262
- name: Extract branch name
shell: bash
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/dio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- "flutter/**"
- "file/**"
- "sqflite/**"
- "hive/**"

jobs:
cancel-previous-workflow:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/e2e_dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- "flutter/**"
- "file/**"
- "sqflite/**"
- "hive/**"

env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- "flutter/**"
- "dio/**"
- "sqflite/**"
- "hive/**"

jobs:
cancel-previous-workflow:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- "dio/**"
- "file/**"
- "sqflite/**"
- "hive/**"

jobs:
cancel-previous-workflow:
Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/hive.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: sentry-hive
on:
push:
branches:
- main
- release/**
pull_request:
paths-ignore:
- "**/*.md"
- "logging/**"
- "flutter/**"
- "dio/**"
- "file/**"
- "sqflite/**"

jobs:
cancel-previous-workflow:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 # pin@0.11.0
with:
access_token: ${{ github.token }}

build:
name: Build ${{matrix.sdk}} on ${{matrix.os}}
runs-on: ${{ matrix.os }}
timeout-minutes: 30
defaults:
run:
shell: bash
working-directory: ./hive
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
sdk: [stable, beta]
exclude:
- os: windows-latest
sdk: beta
- os: macos-latest
sdk: beta
steps:
- uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d # pin@v1
with:
sdk: ${{ matrix.sdk }}
- uses: actions/checkout@v3

- name: Test VM
run: |
dart pub get
dart test -p vm --coverage=coverage --test-randomize-ordering-seed=random --chain-stack-traces
dart pub run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info --packages=.dart_tool/package_config.json --report-on=lib

- uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # pin@v3
if: runner.os == 'Linux' && matrix.sdk == 'stable'
with:
name: sentry_hive
files: ./hive/coverage/lcov.info

- uses: VeryGoodOpenSource/very_good_coverage@e5c91bc7ce9843e87c800b3bcafdfb86fbe28491 # pin@v2.1.0
if: runner.os == 'Linux' && matrix.sdk == 'stable'
with:
path: "./hive/coverage/lcov.info"
min_coverage: 55

analyze:
uses: ./.github/workflows/analyze.yml
with:
package: hive
panaThreshold: 90
1 change: 1 addition & 0 deletions .github/workflows/logging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- "flutter/**"
- "file/**"
- "sqflite/**"
- "hive/**"

jobs:
cancel-previous-workflow:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/min_version_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- "**/*.md"
- "file/**"
- "sqflite/**"
- "hive/**"

jobs:
cancel-previous-workflow:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/sqflite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- "flutter/**"
- "dio/**"
- "file/**"
- "hive/**"

jobs:
cancel-previous-workflow:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- StackTraces in `PlatformException.message` will get nicely formatted too when present ([#1716](https://github.com/getsentry/sentry-dart/pull/1716))
- Breadcrumbs for database operations ([#1656](https://github.com/getsentry/sentry-dart/pull/1656))
- APM for hive ([#1672](https://github.com/getsentry/sentry-dart/pull/1672))
- Add `attachScreenshotOnlyWhenResumed` to options ([#1700](https://github.com/getsentry/sentry-dart/pull/1700))

### Dependencies
Expand Down
5 changes: 5 additions & 0 deletions dart/lib/src/sentry_trace_origins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ class SentryTraceOrigins {
'auto.db.sqflite.database_executor';
static const autoDbSqfliteDatabaseFactory =
'auto.db.sqflite.database_factory';

static const autoDbHive = 'auto.db.hive';
static const autoDbHiveBoxBase = 'auto.db.hive.box_base';
static const autoDbHiveLazyBox = 'auto.db.hive.lazy_box';
static const autoDbHiveBoxCollection = 'auto.db.hive.box_collection';
}
31 changes: 31 additions & 0 deletions flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:logging/logging.dart';
import 'package:path_provider/path_provider.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_sqflite/sentry_sqflite.dart';
import 'package:sqflite/sqflite.dart';
Expand All @@ -19,6 +20,7 @@ import 'user_feedback_dialog.dart';
import 'package:dio/dio.dart';
import 'package:sentry_dio/sentry_dio.dart';
import 'package:sentry_logging/sentry_logging.dart';
import 'package:sentry_hive/sentry_hive.dart';

// ATTENTION: Change the DSN below with your own to see the events in Sentry. Get one at sentry.io
const String exampleDsn =
Expand Down Expand Up @@ -149,6 +151,10 @@ class MainScaffold extends StatelessWidget {
children: [
if (_isIntegrationTest) const IntegrationTestWidget(),
const Center(child: Text('Trigger an action:\n')),
ElevatedButton(
onPressed: () => hiveTest(),
child: const Text('hive'),
),
ElevatedButton(
onPressed: () => sqfliteTest(),
child: const Text('sqflite'),
Expand Down Expand Up @@ -422,6 +428,31 @@ class MainScaffold extends StatelessWidget {
);
}

Future<void> hiveTest() async {
if (kIsWeb) {
return;
}

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

Future<void> sqfliteTest() async {
final tr = Sentry.startTransaction(
'sqfliteTest',
Expand Down
2 changes: 2 additions & 0 deletions flutter/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:
sentry_logging:
sentry_sqflite:
sentry_file:
sentry_hive:
universal_platform: ^1.0.0
feedback: ^2.0.0
provider: ^6.0.0
Expand All @@ -28,6 +29,7 @@ dependencies:
#sqflite_common_ffi: ^2.0.0
#sqflite_common_ffi_web: ^0.3.0
http: ^1.0.0
hive: any # This gets constrained by `sentry_hive`

dev_dependencies:
flutter_lints: ^2.0.0
Expand Down
2 changes: 2 additions & 0 deletions flutter/example/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ dependency_overrides:
path: ../../sqflite
sentry_file:
path: ../../file
sentry_hive:
path: ../../hive
14 changes: 14 additions & 0 deletions hive/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Omit committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/
21 changes: 21 additions & 0 deletions hive/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Sentry

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
85 changes: 85 additions & 0 deletions hive/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<p align="center">
<a href="https://sentry.io" target="_blank" align="center">
<img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280">
</a>
<br />
</p>

Sentry integration for `hive` package
===========

| package | build | pub | likes | popularity | pub points |
|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------| ------- |
| sentry_hive | [![build](https://github.com/getsentry/sentry-dart/workflows/sentry-hive/badge.svg?branch=main)](https://github.com/getsentry/sentry-dart/actions?query=workflow%3Asentry-hive) | [![pub package](https://img.shields.io/pub/v/sentry_hive.svg)](https://pub.dev/packages/sentry_hive) | [![likes](https://img.shields.io/pub/likes/sentry_hive)](https://pub.dev/packages/sentry_hive/score) | [![popularity](https://img.shields.io/pub/popularity/sentry_hive)](https://pub.dev/packages/sentry_hive/score) | [![pub points](https://img.shields.io/pub/points/sentry_hive)](https://pub.dev/packages/sentry_hive/score)

Integration for the [`hive`](https://pub.dev/packages/hive) package.

#### Usage

- Sign up for a Sentry.io account and get a DSN at https://sentry.io.

- Follow the installing instructions on [pub.dev](https://pub.dev/packages/sentry/install).

- Initialize the Sentry SDK using the DSN issued by Sentry.io.

- Call...

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

Future<void> main() async {
await SentryFlutter.init(
(options) {
options.dsn = 'https://example@sentry.io/add-your-dsn-here';
options.tracesSampleRate = 1.0;
},
appRunner: () => runApp(YourApp()),
);
}

Future<void> insertUser() async {
// Use [SentryHive] where you would use [Hive]
final appDir = await getApplicationDocumentsDirectory();
SentryHive
..init(appDir.path)
..registerAdapter(PersonAdapter());

var box = await SentryHive.openBox('testBox');

var person = Person(
name: 'Dave',
age: 22,
);

await box.put('dave', person);

print(box.get('dave')); // Dave: 22
}

@HiveType(typeId: 1)
class Person {
Person({required this.name, required this.age});

@HiveField(0)
String name;

@HiveField(1)
int age;

@override
String toString() {
return '$name: $age';
}
}
```

#### Resources

* [![Documentation](https://img.shields.io/badge/documentation-sentry.io-green.svg)](https://docs.sentry.io/platforms/dart/)
* [![Forum](https://img.shields.io/badge/forum-sentry-green.svg)](https://forum.sentry.io/c/sdks)
* [![Discord](https://img.shields.io/discord/621778831602221064)](https://discord.gg/Ww9hbqr)
* [![Stack Overflow](https://img.shields.io/badge/stack%20overflow-sentry-green.svg)](https://stackoverflow.com/questions/tagged/sentry)
* [![Twitter Follow](https://img.shields.io/twitter/follow/getsentry?label=getsentry&style=social)](https://twitter.com/intent/follow?screen_name=getsentry)
Loading