Skip to content

Commit e35a82d

Browse files
committed
expose sentry hive and updata documentation
1 parent 6ea6914 commit e35a82d

16 files changed

+369
-102
lines changed

dart/lib/src/sentry_trace_origins.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class SentryTraceOrigins {
2020
'auto.db.sqflite.database_factory';
2121

2222
static const autoDbHive = 'auto.db.hive';
23-
static const autoDbHiveOpenDatabase = 'auto.db.hive.open_database';
2423
static const autoDbHiveBoxBase = 'auto.db.hive.box_base';
2524
static const autoDbHiveLazyBox = 'auto.db.hive.lazy_box';
2625
}

hive/README.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,78 @@
66
</p>
77

88
Sentry integration for `hive` package
9-
===========
9+
===========
10+
11+
| package | build | pub | likes | popularity | pub points |
12+
|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------| ------- |
13+
| 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)
14+
15+
Integration for the [`hive`](https://pub.dev/packages/hive) package.
16+
17+
#### Usage
18+
19+
- Sign up for a Sentry.io account and get a DSN at https://sentry.io.
20+
21+
- Follow the installing instructions on [pub.dev](https://pub.dev/packages/sentry/install).
22+
23+
- Initialize the Sentry SDK using the DSN issued by Sentry.io.
24+
25+
- Call...
26+
27+
```dart
28+
import 'package:sentry/sentry.dart';
29+
import 'package:hive/hive.dart';
30+
import 'package:sentry_hive/sentry_hive.dart';
31+
32+
Future<void> main() async {
33+
await SentryFlutter.init(
34+
(options) {
35+
options.dsn = 'https://example@sentry.io/add-your-dsn-here';
36+
options.tracesSampleRate = 1.0;
37+
},
38+
appRunner: () => runApp(YourApp()),
39+
);
40+
}
41+
42+
Future<void> insertUser() async {
43+
// Use [SentryHive] where you would use [Hive]
44+
SentryHive
45+
..init(Directory.current.path)
46+
..registerAdapter(PersonAdapter());
47+
48+
var box = await SentryHive.openBox('testBox');
49+
50+
var person = Person(
51+
name: 'Dave',
52+
age: 22,
53+
);
54+
55+
await box.put('dave', person);
56+
57+
print(box.get('dave')); // Dave: 22
58+
}
59+
60+
@HiveType(typeId: 1)
61+
class Person {
62+
Person({required this.name, required this.age});
63+
64+
@HiveField(0)
65+
String name;
66+
67+
@HiveField(1)
68+
int age;
69+
70+
@override
71+
String toString() {
72+
return '$name: $age';
73+
}
74+
}
75+
```
76+
77+
#### Resources
78+
79+
* [![Documentation](https://img.shields.io/badge/documentation-sentry.io-green.svg)](https://docs.sentry.io/platforms/dart/)
80+
* [![Forum](https://img.shields.io/badge/forum-sentry-green.svg)](https://forum.sentry.io/c/sdks)
81+
* [![Discord](https://img.shields.io/discord/621778831602221064)](https://discord.gg/Ww9hbqr)
82+
* [![Stack Overflow](https://img.shields.io/badge/stack%20overflow-sentry-green.svg)](https://stackoverflow.com/questions/tagged/sentry)
83+
* [![Twitter Follow](https://img.shields.io/twitter/follow/getsentry?label=getsentry&style=social)](https://twitter.com/intent/follow?screen_name=getsentry)

hive/example/example.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import 'package:hive/hive.dart';
21
import 'package:sentry/sentry.dart';
2+
import 'package:hive/hive.dart';
33
import 'package:sentry_hive/sentry_hive.dart';
44

55
part 'main.g.dart';
66

77
Future<void> main() async {
88
// ATTENTION: Change the DSN below with your own to see the events in Sentry. Get one at sentry.io
99
const dsn =
10-
'https://e85b375ffb9f43cf8bdf9787768149e0@o447951.ingest.sentry.io/5428562';
10+
'https://e85b375ffb9f43cf8bdf9787768149e0@o447951.ingest.sentry.io/5428562';
1111

1212
await Sentry.init(
13-
(options) {
13+
(options) {
1414
options.dsn = dsn;
1515
options.tracesSampleRate = 1.0;
1616
options.debug = true;
@@ -20,16 +20,21 @@ Future<void> main() async {
2020
}
2121

2222
Future<void> runApp() async {
23-
Hive
23+
// Use [SentryHive] where you would use [Hive]
24+
SentryHive
2425
..init(Directory.current.path)
2526
..registerAdapter(PersonAdapter());
2627

27-
var box = await Hive.openBox('testBox');
28+
var box = await SentryHive.openBox('testBox');
2829

29-
var sentryBox = SentryBox
30+
var person = Person(
31+
name: 'Dave',
32+
age: 22,
33+
);
3034

31-
var person = Person(name: 'Dave', age: 23);
35+
await box.put('dave', person);
3236

37+
print(box.get('dave')); // Dave: 22
3338
}
3439

3540
@HiveType(typeId: 1)

hive/lib/sentry_hive.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
library sentry_hive;
22

3-
export 'src/sentry_hive.dart';
4-
export 'src/sentry_box.dart';
3+
import 'package:meta/meta.dart';
4+
import 'package:hive/hive.dart';
5+
import 'src/sentry_hive_impl.dart';
6+
import 'src/sentry_hive_interface.dart';
7+
8+
export 'src/sentry_hive_interface.dart';
9+
10+
/// Use [SentryHive] constant instead of [Hive] to get automatic performance
11+
/// monitoring.
12+
@experimental
13+
// ignore: non_constant_identifier_names
14+
SentryHiveInterface SentryHive = SentryHiveImpl(Hive);

hive/lib/src/default_key_comparator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ int defaultKeyComparator(dynamic k1, dynamic k2) {
1717
} else {
1818
return 1;
1919
}
20-
}
20+
}

hive/lib/src/sentry_box.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import 'package:sentry/sentry.dart';
44

55
import 'sentry_box_base.dart';
66

7-
///
8-
@experimental
7+
/// @nodoc
8+
@internal
99
class SentryBox<E> extends SentryBoxBase<E> implements Box<E> {
10-
1110
final Box<E> _box;
1211

13-
///
12+
/// @nodoc
1413
SentryBox(this._box, @internal Hub hub) : super(_box, hub);
1514

1615
@override

hive/lib/src/sentry_box_base.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
21
import 'package:hive/hive.dart';
32
import 'package:meta/meta.dart';
43
import 'package:sentry/sentry.dart';
54
import 'sentry_hive_impl.dart';
65

7-
///
6+
/// @nodoc
7+
@internal
88
class SentryBoxBase<E> implements BoxBase<E> {
9-
109
final BoxBase<E> _boxBase;
1110
final Hub _hub;
1211

13-
///
12+
/// @nodoc
1413
SentryBoxBase(this._boxBase, this._hub);
1514

1615
@override
@@ -145,7 +144,8 @@ class SentryBoxBase<E> implements BoxBase<E> {
145144

146145
// Helper
147146

148-
Future<T> _asyncWrapInSpan<T>(String description, Future<T> Function() execute) async {
147+
Future<T> _asyncWrapInSpan<T>(
148+
String description, Future<T> Function() execute) async {
149149
final currentSpan = _hub.getSpan();
150150
final span = currentSpan?.startChild(
151151
SentryHiveImpl.dbOp,
@@ -172,4 +172,4 @@ class SentryBoxBase<E> implements BoxBase<E> {
172172
await span?.finish();
173173
}
174174
}
175-
}
175+
}

hive/lib/src/sentry_hive.dart

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)