Skip to content

Commit

Permalink
Wrapped methods return a Future instead of executing right away (#1476)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored May 24, 2023
1 parent f9d18f3 commit 43760f9
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 103 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

### Fixes

- Wrapped methods return a `Future` instead of executing right away ([#1476](https://github.com/getsentry/sentry-dart/pull/1476))
- Relates to ([#1462](https://github.com/getsentry/sentry-dart/pull/1462))

### Dependencies

- Bump Android SDK from v6.19.0 to v6.19.1 ([#1466](https://github.com/getsentry/sentry-dart/pull/1466))
Expand Down
30 changes: 10 additions & 20 deletions flutter/lib/src/sentry_asset_bundle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SentryAssetBundle implements AssetBundle {

@override
Future<ByteData> load(String key) {
Future<ByteData> future() async {
return Future<ByteData>(() async {
final span = _hub.getSpan()?.startChild(
'file.read',
description: 'AssetBundle.load: ${_fileName(key)}',
Expand All @@ -75,9 +75,7 @@ class SentryAssetBundle implements AssetBundle {
await span?.finish();
}
return data;
}

return future();
});
}

@override
Expand All @@ -90,7 +88,7 @@ class SentryAssetBundle implements AssetBundle {

Future<T> _loadStructuredDataWithTracing<T>(
String key, _StringParser<T> parser) {
Future<T> future() async {
return Future<T>(() async {
final span = _hub.getSpan()?.startChild(
'file.read',
description:
Expand Down Expand Up @@ -127,14 +125,12 @@ class SentryAssetBundle implements AssetBundle {
await span?.finish();
}
return data;
}

return future();
});
}

Future<T> _loadStructuredBinaryDataWithTracing<T>(
String key, _ByteParser<T> parser) {
Future<T> future() async {
return Future<T>(() async {
final span = _hub.getSpan()?.startChild(
'file.read',
description:
Expand Down Expand Up @@ -171,14 +167,12 @@ class SentryAssetBundle implements AssetBundle {
await span?.finish();
}
return data;
}

return future();
});
}

@override
Future<String> loadString(String key, {bool cache = true}) {
Future<String> future() async {
return Future<String>(() async {
final span = _hub.getSpan()?.startChild(
'file.read',
description: 'AssetBundle.loadString: ${_fileName(key)}',
Expand All @@ -199,9 +193,7 @@ class SentryAssetBundle implements AssetBundle {
await span?.finish();
}
return data;
}

return future();
});
}

void _setDataLength(dynamic data, ISentrySpan? span) {
Expand Down Expand Up @@ -238,7 +230,7 @@ class SentryAssetBundle implements AssetBundle {
// This is an override on Flutter greater than 3.1
// ignore: override_on_non_overriding_member
Future<ImmutableBuffer> loadBuffer(String key) {
Future<ImmutableBuffer> future() async {
return Future<ImmutableBuffer>(() async {
final span = _hub.getSpan()?.startChild(
'file.read',
description: 'AssetBundle.loadBuffer: ${_fileName(key)}',
Expand All @@ -259,9 +251,7 @@ class SentryAssetBundle implements AssetBundle {
await span?.finish();
}
return data;
}

return future();
});
}

Future<ImmutableBuffer> _loadBuffer(String key) {
Expand Down
12 changes: 4 additions & 8 deletions sqflite/lib/src/sentry_batch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SentryBatch implements Batch {

@override
Future<List<Object?>> apply({bool? noResult, bool? continueOnError}) {
Future<List<Object?>> future() async {
return Future<List<Object?>>(() async {
final currentSpan = _hub.getSpan();

final span = currentSpan?.startChild(
Expand All @@ -65,9 +65,7 @@ class SentryBatch implements Batch {
} finally {
await span?.finish();
}
}

return future();
});
}

@override
Expand All @@ -76,7 +74,7 @@ class SentryBatch implements Batch {
bool? noResult,
bool? continueOnError,
}) {
Future<List<Object?>> future() async {
return Future<List<Object?>>(() async {
final currentSpan = _hub.getSpan();

final span = currentSpan?.startChild(
Expand All @@ -102,9 +100,7 @@ class SentryBatch implements Batch {
} finally {
await span?.finish();
}
}

return future();
});
}

@override
Expand Down
12 changes: 4 additions & 8 deletions sqflite/lib/src/sentry_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {

@override
Future<void> close() {
Future<void> future() async {
return Future<void>(() async {
final currentSpan = _hub.getSpan();
final span = currentSpan?.startChild(
dbOp,
Expand All @@ -73,9 +73,7 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
} finally {
await span?.finish();
}
}

return future();
});
}

@override
Expand Down Expand Up @@ -105,7 +103,7 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
Future<T> Function(Transaction txn) action, {
bool? exclusive,
}) {
Future<T> future() async {
return Future<T>(() async {
final currentSpan = _hub.getSpan();
final span = currentSpan?.startChild(
_dbSqlOp,
Expand Down Expand Up @@ -136,8 +134,6 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
} finally {
await span?.finish();
}
}

return future();
});
}
}
66 changes: 22 additions & 44 deletions sqflite/lib/src/sentry_database_executor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {

@override
Future<int> delete(String table, {String? where, List<Object?>? whereArgs}) {
Future<int> future() async {
return Future<int>(() async {
final currentSpan = _parentSpan ?? _hub.getSpan();
final builder =
SqlBuilder.delete(table, where: where, whereArgs: whereArgs);
Expand All @@ -55,14 +55,12 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
} finally {
await span?.finish();
}
}

return future();
});
}

@override
Future<void> execute(String sql, [List<Object?>? arguments]) {
Future<void> future() async {
return Future<void>(() async {
final currentSpan = _parentSpan ?? _hub.getSpan();
final span = currentSpan?.startChild(
SentryDatabase.dbSqlExecuteOp,
Expand All @@ -81,9 +79,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
} finally {
await span?.finish();
}
}

return future();
});
}

@override
Expand All @@ -93,7 +89,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
String? nullColumnHack,
ConflictAlgorithm? conflictAlgorithm,
}) {
Future<int> future() async {
return Future<int>(() async {
final currentSpan = _parentSpan ?? _hub.getSpan();
final builder = SqlBuilder.insert(
table,
Expand Down Expand Up @@ -125,9 +121,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
} finally {
await span?.finish();
}
}

return future();
});
}

@override
Expand All @@ -143,7 +137,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
int? limit,
int? offset,
}) {
Future<List<Map<String, Object?>>> future() async {
return Future<List<Map<String, Object?>>>(() async {
final currentSpan = _parentSpan ?? _hub.getSpan();
final builder = SqlBuilder.query(
table,
Expand Down Expand Up @@ -187,9 +181,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
} finally {
await span?.finish();
}
}

return future();
});
}

@override
Expand All @@ -206,7 +198,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
int? offset,
int? bufferSize,
}) {
Future<QueryCursor> future() async {
return Future<QueryCursor>(() async {
final currentSpan = _parentSpan ?? _hub.getSpan();
final builder = SqlBuilder.query(
table,
Expand Down Expand Up @@ -251,14 +243,12 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
} finally {
await span?.finish();
}
}

return future();
});
}

@override
Future<int> rawDelete(String sql, [List<Object?>? arguments]) {
Future<int> future() async {
return Future<int>(() async {
final currentSpan = _parentSpan ?? _hub.getSpan();
final span = currentSpan?.startChild(
SentryDatabase.dbSqlExecuteOp,
Expand All @@ -279,14 +269,12 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
} finally {
await span?.finish();
}
}

return future();
});
}

@override
Future<int> rawInsert(String sql, [List<Object?>? arguments]) {
Future<int> future() async {
return Future<int>(() async {
final currentSpan = _parentSpan ?? _hub.getSpan();
final span = currentSpan?.startChild(
SentryDatabase.dbSqlExecuteOp,
Expand All @@ -307,17 +295,15 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
} finally {
await span?.finish();
}
}

return future();
});
}

@override
Future<List<Map<String, Object?>>> rawQuery(
String sql, [
List<Object?>? arguments,
]) {
Future<List<Map<String, Object?>>> future() async {
return Future<List<Map<String, Object?>>>(() async {
final currentSpan = _parentSpan ?? _hub.getSpan();
final span = currentSpan?.startChild(
SentryDatabase.dbSqlQueryOp,
Expand All @@ -338,9 +324,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
} finally {
await span?.finish();
}
}

return future();
});
}

@override
Expand All @@ -349,7 +333,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
List<Object?>? arguments, {
int? bufferSize,
}) {
Future<QueryCursor> future() async {
return Future<QueryCursor>(() async {
final currentSpan = _parentSpan ?? _hub.getSpan();
final span = currentSpan?.startChild(
SentryDatabase.dbSqlQueryOp,
Expand All @@ -374,14 +358,12 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
} finally {
await span?.finish();
}
}

return future();
});
}

@override
Future<int> rawUpdate(String sql, [List<Object?>? arguments]) {
Future<int> future() async {
return Future<int>(() async {
final currentSpan = _parentSpan ?? _hub.getSpan();
final span = currentSpan?.startChild(
SentryDatabase.dbSqlExecuteOp,
Expand All @@ -402,9 +384,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
} finally {
await span?.finish();
}
}

return future();
});
}

@override
Expand All @@ -415,7 +395,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
List<Object?>? whereArgs,
ConflictAlgorithm? conflictAlgorithm,
}) {
Future<int> future() async {
return Future<int>(() async {
final currentSpan = _parentSpan ?? _hub.getSpan();
final builder = SqlBuilder.update(
table,
Expand Down Expand Up @@ -449,8 +429,6 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
} finally {
await span?.finish();
}
}

return future();
});
}
}
Loading

0 comments on commit 43760f9

Please sign in to comment.