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

Breadcrumbs for database operations #1656

Merged
merged 26 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
347b8f4
Prepare breadcrumb tests
denrase Sep 19, 2023
12f0b6d
Merge branch 'main' into feat/database-breadcrumbs
denrase Sep 25, 2023
6de44bb
create breadcrumbs for batch operations
denrase Sep 25, 2023
bd9a135
add breadcrumbs to sentry database & executor
denrase Sep 25, 2023
2e6d025
create breadcrumb when opening db
denrase Sep 25, 2023
b7a2fbc
create breadcrumb in SentrySqfliteDatabaseFactory
denrase Sep 25, 2023
86d796e
choose correct breadcrumb in batch tests
denrase Sep 26, 2023
cfc7715
set additional error info in batch
denrase Sep 26, 2023
98ee0af
set query and error breadcrumb type
denrase Sep 26, 2023
a38cfd5
update in sqflite and database factory
denrase Sep 26, 2023
932ca1c
Merge branch 'main' into feat/database-breadcrumbs
denrase Sep 26, 2023
aa66f4a
run format
denrase Sep 26, 2023
0382383
add changelog entries
denrase Sep 26, 2023
2778594
bump ios im runtime
denrase Sep 26, 2023
9978a74
manually set deployemtn target for pods
denrase Oct 3, 2023
26a77fc
Merge branch 'main' into feat/database-breadcrumbs
denrase Oct 17, 2023
788364d
Change status value
denrase Oct 17, 2023
e58a4d8
Merge branch 'main' into feat/database-breadcrumbs
denrase Oct 24, 2023
af3d295
change breadcrumb type and level
denrase Oct 24, 2023
1a5d4e3
remove duplicated lines
denrase Oct 24, 2023
aaf22b4
set type query to success breadcrumbs
denrase Oct 24, 2023
24f79d4
Merge branch 'main' into feat/database-breadcrumbs
denrase Oct 30, 2023
73d740a
fix changelog
denrase Oct 30, 2023
2c353b2
remove remaining error level
denrase Oct 31, 2023
6830e50
Merge branch 'main' into feat/database-breadcrumbs
denrase Oct 31, 2023
a20d194
fix changelog
denrase Oct 31, 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
2 changes: 1 addition & 1 deletion .github/workflows/flutter_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:
run: |
case "${{ matrix.target }}" in
ios)
device=$(xcrun simctl create sentryPhone com.apple.CoreSimulator.SimDeviceType.iPhone-14 com.apple.CoreSimulator.SimRuntime.iOS-16-4)
device=$(xcrun simctl create sentryPhone com.apple.CoreSimulator.SimDeviceType.iPhone-14 com.apple.CoreSimulator.SimRuntime.iOS-17-0)
xcrun simctl boot ${device}
echo "platform=iOS Simulator,id=${device}" >> "$GITHUB_OUTPUT"
;;
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Features

- Breadcrumbs for database operations ([#1656](https://github.com/getsentry/sentry-dart/pull/1656))

## 7.12.0

### Enhancements
Expand Down
3 changes: 3 additions & 0 deletions flutter/example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
end
end
end
31 changes: 31 additions & 0 deletions sqflite/lib/src/sentry_batch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ class SentryBatch implements Batch {
span?.origin = SentryTraceOrigins.autoDbSqfliteBatch;
setDatabaseAttributeData(span, _dbName);

var breadcrumb = Breadcrumb(
message: _buffer.toString().trim(),
data: {},
type: 'query',
);
setDatabaseAttributeOnBreadcrumb(breadcrumb, _dbName);

try {
final result = await _batch.apply(
noResult: noResult,
Expand All @@ -64,14 +71,23 @@ class SentryBatch implements Batch {

span?.status = SpanStatus.ok();

breadcrumb.data?['status'] = 'ok';

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

breadcrumb.data?['status'] = 'internal_error';
breadcrumb = breadcrumb.copyWith(
level: SentryLevel.warning,
);

rethrow;
} finally {
await span?.finish();
// ignore: invalid_use_of_internal_member
await _hub.scope.addBreadcrumb(breadcrumb);
}
});
}
Expand All @@ -94,6 +110,13 @@ class SentryBatch implements Batch {
span?.origin = SentryTraceOrigins.autoDbSqfliteBatch;
setDatabaseAttributeData(span, _dbName);

var breadcrumb = Breadcrumb(
message: _buffer.toString().trim(),
data: {},
type: 'query',
);
setDatabaseAttributeOnBreadcrumb(breadcrumb, _dbName);

try {
final result = await _batch.commit(
exclusive: exclusive,
Expand All @@ -102,15 +125,23 @@ class SentryBatch implements Batch {
);

span?.status = SpanStatus.ok();
breadcrumb.data?['status'] = 'ok';

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

breadcrumb.data?['status'] = 'internal_error';
breadcrumb = breadcrumb.copyWith(
level: SentryLevel.warning,
);

rethrow;
} finally {
await span?.finish();
// ignore: invalid_use_of_internal_member
await _hub.scope.addBreadcrumb(breadcrumb);
}
});
}
Expand Down
36 changes: 34 additions & 2 deletions sqflite/lib/src/sentry_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,39 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
Future<void> close() {
return Future<void>(() async {
final currentSpan = _hub.getSpan();
final description = 'Close DB: ${_database.path}';
final span = currentSpan?.startChild(
dbOp,
description: 'Close DB: ${_database.path}',
description: description,
);
// ignore: invalid_use_of_internal_member
span?.origin = SentryTraceOrigins.autoDbSqfliteDatabase;

var breadcrumb = Breadcrumb(
message: description,
category: dbOp,
data: {},
type: 'query',
);

try {
await _database.close();

span?.status = SpanStatus.ok();
breadcrumb.data?['status'] = 'ok';
} catch (exception) {
span?.throwable = exception;
span?.status = SpanStatus.internalError();
breadcrumb.data?['status'] = 'internal_error';
breadcrumb = breadcrumb.copyWith(
level: SentryLevel.warning,
);

rethrow;
} finally {
await span?.finish();
// ignore: invalid_use_of_internal_member
await _hub.scope.addBreadcrumb(breadcrumb);
}
});
}
Expand Down Expand Up @@ -126,14 +141,23 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
}) {
return Future<T>(() async {
final currentSpan = _hub.getSpan();
final description = 'Transaction DB: ${_database.path}';
final span = currentSpan?.startChild(
_dbSqlOp,
description: 'Transaction DB: ${_database.path}',
description: description,
);
// ignore: invalid_use_of_internal_member
span?.origin = SentryTraceOrigins.autoDbSqfliteDatabase;
setDatabaseAttributeData(span, dbName);

var breadcrumb = Breadcrumb(
message: description,
category: _dbSqlOp,
data: {},
type: 'query',
);
setDatabaseAttributeOnBreadcrumb(breadcrumb, dbName);

Future<T> newAction(Transaction txn) async {
final executor = SentryDatabaseExecutor(
txn,
Expand All @@ -152,15 +176,23 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
await _database.transaction(newAction, exclusive: exclusive);

span?.status = SpanStatus.ok();
breadcrumb.data?['status'] = 'ok';

return result;
} catch (exception) {
span?.throwable = exception;
span?.status = SpanStatus.internalError();
breadcrumb.data?['status'] = 'internal_error';
breadcrumb = breadcrumb.copyWith(
level: SentryLevel.warning,
);

rethrow;
} finally {
await span?.finish();

// ignore: invalid_use_of_internal_member
await _hub.scope.addBreadcrumb(breadcrumb);
}
});
}
Expand Down
Loading
Loading