Skip to content

Commit

Permalink
Pass processed Breadcrumb to scope observer (#1298)
Browse files Browse the repository at this point in the history
Co-authored-by: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com>
  • Loading branch information
denrase and marandaneto authored Feb 28, 2023
1 parent d2f62d6 commit 69670c9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

### Fixes

- Pass processed Breadcrumb to scope observer ([#1298](https://github.com/getsentry/sentry-dart/pull/1298))
- Remove duplicated breadcrumbs when syncing with iOS/macOS ([#1283](https://github.com/getsentry/sentry-dart/pull/1283))

## 6.20.1
Expand Down
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 69670c9

Please sign in to comment.