Skip to content

Commit

Permalink
pass processed breadacrumb to scope observer
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Feb 28, 2023
1 parent 2d3b03d commit f1d95f0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
13 changes: 7 additions & 6 deletions dart/lib/src/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ class Scope {

Scope(this._options);

bool _addBreadCrumbSync(Breadcrumb breadcrumb, {dynamic hint}) {
Breadcrumb? _addBreadCrumbSync(Breadcrumb breadcrumb, {dynamic hint}) {
// bail out if maxBreadcrumbs is zero
if (_options.maxBreadcrumbs == 0) {
return false;
return null;
}

Breadcrumb? processedBreadcrumb = breadcrumb;
Expand All @@ -174,7 +174,7 @@ class Scope {
SentryLevel.info,
'Breadcrumb was dropped by beforeBreadcrumb',
);
return false;
return null;
}
} catch (exception, stackTrace) {
_options.logger(
Expand All @@ -193,14 +193,15 @@ class Scope {
}
_breadcrumbs.add(processedBreadcrumb);
}
return true;
return processedBreadcrumb;
}

/// Adds a breadcrumb to the breadcrumbs queue
Future<void> addBreadcrumb(Breadcrumb breadcrumb, {dynamic hint}) async {
if (_addBreadCrumbSync(breadcrumb, hint: hint)) {
final addedBreadcrumb = _addBreadCrumbSync(breadcrumb, hint: hint);
if (addedBreadcrumb != null) {
await _callScopeObservers((scopeObserver) async =>
await scopeObserver.addBreadcrumb(breadcrumb));
await scopeObserver.addBreadcrumb(addedBreadcrumb));
}
}

Expand Down
2 changes: 2 additions & 0 deletions dart/test/mocks/mock_scope_observer.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:sentry/sentry.dart';

class MockScopeObserver extends ScopeObserver {
List<Breadcrumb> addedBreadcrumbs = [];
bool calledAddBreadcrumb = false;
bool calledClearBreadcrumbs = false;
bool calledRemoveContexts = false;
Expand All @@ -25,6 +26,7 @@ class MockScopeObserver extends ScopeObserver {
Future<void> addBreadcrumb(Breadcrumb breadcrumb) async {
calledAddBreadcrumb = true;
numberOfAddBreadcrumbCalls += 1;
addedBreadcrumbs.add(breadcrumb);
}

@override
Expand Down
16 changes: 16 additions & 0 deletions dart/test/scope_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,22 @@ void main() {
expect(true, fixture.mockScopeObserver.calledAddBreadcrumb);
});

test('addBreadcrumb passes processed breadcrumb to scope observers',
() async {
final sut = fixture.getSut(
scopeObserver: fixture.mockScopeObserver,
beforeBreadcrumbCallback: (
Breadcrumb? breadcrumb, {
dynamic hint,
}) {
return breadcrumb?.copyWith(message: "modified");
},
);
await sut.addBreadcrumb(Breadcrumb());

expect(fixture.mockScopeObserver.addedBreadcrumbs[0].message, "modified");
});

test('clearBreadcrumbs should call scope observers', () async {
final sut = fixture.getSut(scopeObserver: fixture.mockScopeObserver);
await sut.clearBreadcrumbs();
Expand Down

0 comments on commit f1d95f0

Please sign in to comment.