Skip to content

Commit

Permalink
add origin to sqflite span
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Jun 26, 2023
1 parent 5370936 commit 9b84879
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions dart/lib/src/sentry_trace_origins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class SentryTraceOrigins {
static const autoHttpDioSentryTransformer = 'auto.http.dio.sentry_transformer';
static const autoFile = 'auto.file';
static const autoFileAssetBundle = 'auto.file.asset_bundle';
static const autoFileSqflite = 'auto.file.sqflite';
static const autoFileSqfliteSentryBatch = 'auto.file.sqflite.sentry_batch';
static const autoFileSqfliteSentryDatabaseExecutor = 'auto.file.sqflite.sentry_database_executor';
}
2 changes: 2 additions & 0 deletions sqflite/lib/src/sentry_sqflite.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Future<Database> openDatabaseWithSentry(
SentryDatabase.dbOp,
description: 'Open DB: $path',
);
// ignore: invalid_use_of_internal_member
span?.origin = SentryTraceOrigins.autoFileSqflite;

try {
final database =
Expand Down
22 changes: 20 additions & 2 deletions sqflite/test/sentry_sqflite_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ void main() {
databaseFactory = databaseFactoryFfi;
});

tearDown(() {
databaseFactory = sqfliteDatabaseFactoryDefault;
});

test('returns wrapped data base if performance enabled', () async {
final db =
await openDatabaseWithSentry(inMemoryDatabasePath, hub: fixture.hub);
Expand Down Expand Up @@ -82,10 +86,24 @@ void main() {
await db.close();
});

tearDown(() {
databaseFactory = sqfliteDatabaseFactoryDefault;
test('creates db open span', () async {
final db =
await openDatabaseWithSentry(inMemoryDatabasePath, hub: fixture.hub);

final span = fixture.tracer.children.last;

expect(span.context.operation, SentryDatabase.dbOp);
expect(span.context.description, 'Open DB: $inMemoryDatabasePath');
expect(span.status, SpanStatus.ok());
// ignore: invalid_use_of_internal_member
expect(span.origin, SentryTraceOrigins.autoFileSqflite);

await db.close();
});

});


}

class Fixture {
Expand Down

0 comments on commit 9b84879

Please sign in to comment.