Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add SentryBox with first test
  • Loading branch information
denrase committed Oct 10, 2023
commit 2fa0411d456e9fde144e9bf92d17489ad8b05076
3 changes: 3 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,7 @@ class SentryTraceOrigins {
'auto.db.sqflite.database_executor';
static const autoDbSqfliteDatabaseFactory =
'auto.db.sqflite.database_factory';

static const autoDbHive = 'auto.db.hive';
static const autoDbHiveBox = 'auto.db.hive.box';
}
2 changes: 1 addition & 1 deletion hive/lib/sentry_hive.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library;
library sentry_hive;

export 'src/sentry_hive.dart';
export 'src/sentry_box.dart';
200 changes: 200 additions & 0 deletions hive/lib/src/sentry_box.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
import 'package:meta/meta.dart';
import 'package:hive/hive.dart';
import 'package:sentry/sentry.dart';

import '../sentry_hive.dart';

// ignore: public_member_api_docs
class SentryBox<E> implements Box<E> {

final Box<E> _box;
final Hub _hub;

// ignore: public_member_api_docs
SentryBox(this._box, @internal Hub? hub) : _hub = hub ?? HubAdapter();

@override
Future<int> add(E value) async {
return _asyncWrapInSpan('add', () async {
return await _box.add(value);
});
}

@override
Future<Iterable<int>> addAll(Iterable<E> values) async {
return _asyncWrapInSpan('addAll', () async {
return await _box.addAll(values);
});
}

@override
Future<int> clear() async {
return _asyncWrapInSpan('clear', () async {
return await _box.clear();
});
}

@override
Future<void> close() async {
return _asyncWrapInSpan('close', () async {
return await _box.close();
});
}

@override
Future<void> compact() async {
return _asyncWrapInSpan('compact', () async {
return await _box.compact();
});
}

@override
bool containsKey(key) {
return _box.containsKey(key);
}

@override
Future<void> delete(key) async {
return _asyncWrapInSpan('delete', () async {
return await _box.delete(key);
});
}

@override
// ignore: strict_raw_type
Future<void> deleteAll(Iterable keys) async {
return _asyncWrapInSpan('delete', () async {
return await _box.deleteAll(keys);
});
}

@override
Future<void> deleteAt(int index) async {
return _asyncWrapInSpan('deleteAt', () async {
return await _box.deleteAt(index);
});
}

@override
Future<void> deleteFromDisk() async {
return _asyncWrapInSpan('deleteFromDisk', () async {
return await _box.deleteFromDisk();
});
}

@override
Future<void> flush() async {
return _asyncWrapInSpan('flush', () async {
return await _box.flush();
});
}

@override
E? get(key, {E? defaultValue}) {
return _box.get(key, defaultValue: defaultValue);
}

@override
E? getAt(int index) {
return _box.getAt(index);
}

@override
bool get isEmpty => _box.isEmpty;

@override
bool get isNotEmpty => _box.isNotEmpty;

@override
bool get isOpen => _box.isOpen;

@override
dynamic keyAt(int index) {
return _box.keyAt(index);
}

@override
// ignore: strict_raw_type
Iterable get keys => _box.keys;

@override
bool get lazy => _box.lazy;

@override
int get length => _box.length;

@override
String get name => _box.name;

@override
String? get path => _box.path;

@override
Future<void> put(key, E value) async {
return _asyncWrapInSpan('put', () async {
return await _box.put(key, value);
});
}

@override
Future<void> putAll(Map<dynamic, E> entries) async {
return _asyncWrapInSpan('putAll', () async {
return await _box.putAll(entries);
});
}

@override
Future<void> putAt(int index, E value) async {
return _asyncWrapInSpan('putAt', () async {
return await _box.putAt(index, value);
});
}

@override
Map<dynamic, E> toMap() {
return _box.toMap();
}

@override
Iterable<E> get values => _box.values;

@override
Iterable<E> valuesBetween({startKey, endKey}) {
return _box.valuesBetween(startKey: startKey, endKey: endKey);
}

@override
Stream<BoxEvent> watch({key}) {
return _box.watch(key: key);
}

// Helper

Future<T> _asyncWrapInSpan<T>(String description, Future<T> Function() execute) async {
final currentSpan = _hub.getSpan();
final span = currentSpan?.startChild(
SentryHive.dbOp,
description: description,
);

// ignore: invalid_use_of_internal_member
span?.origin = SentryTraceOrigins.autoDbHiveBox;

span?.setData(SentryHive.dbSystemKey, SentryHive.dbSystem);
span?.setData(SentryHive.dbNameKey, name);

try {
final result = await execute();
span?.status = SpanStatus.ok();

return result;
} catch (exception) {
span?.throwable = exception;
span?.status = SpanStatus.internalError();

rethrow;
} finally {
await span?.finish();
}
}
}
19 changes: 16 additions & 3 deletions hive/lib/src/sentry_hive.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
// TODO: Put public facing types in this file.
import 'package:meta/meta.dart';

/// Checks if you are awesome. Spoiler: you are.
class Awesome {
bool get isAwesome => true;
class SentryHive {
@internal
// ignore: public_member_api_docs
static const dbOp = 'db';

@internal
// ignore: public_member_api_docs
static const dbSystemKey = 'db.system';
@internal
// ignore: public_member_api_docs
static const dbSystem = 'sqlite';

@internal
// ignore: public_member_api_docs
static const dbNameKey = 'db.name';
}
4 changes: 4 additions & 0 deletions hive/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ environment:
dependencies:
sentry: 7.10.1
hive: ^2.2.3
meta: ^1.3.0

dev_dependencies:
lints: ^2.0.0
test: ^1.21.0
yaml: ^3.1.0 # needed for version match (code and pubspec)
mockito: ^5.1.0
build_runner: ^2.4.2
path_provider: ^2.1.1
3 changes: 3 additions & 0 deletions hive/test/common.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'dart:ffi';
import 'dart:io';
import 'dart:math';
9 changes: 9 additions & 0 deletions hive/test/mocks/mocks.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:mockito/annotations.dart';
import 'package:sentry/sentry.dart';

@GenerateMocks(
[
Hub,
]
)
void main() {}
Loading