Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- Ref: added Transport #123
- Feat: apply sample rate
- Ref: execute before send callback
- Feat: addBreadcrumb on Static API

# `package:sentry` changelog

Expand Down
4 changes: 3 additions & 1 deletion dart/example/event_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ final event = SentryEvent(
ipAddress: '127.0.0.1',
extras: <String, String>{'first-sign-in': '2020-01-01'}),
breadcrumbs: [
Breadcrumb('UI Lifecycle', DateTime.now().toUtc(),
Breadcrumb(
message: 'UI Lifecycle',
timestamp: DateTime.now().toUtc(),
category: 'ui.lifecycle',
type: 'navigation',
data: {'screen': 'MainActivity', 'state': 'created'},
Expand Down
25 changes: 25 additions & 0 deletions dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,31 @@ class Hub {
return sentryId;
}

/// Adds a breacrumb to the current Scope
void addBreadcrumb(Breadcrumb crumb, {dynamic hint}) {
if (!_isEnabled) {
_options.logger(
SentryLevel.warning,
"Instance is disabled and this 'addBreadcrumb' call is a no-op.",
);
} else if (crumb == null) {
_options.logger(
SentryLevel.warning,
'addBreadcrumb called with null parameter.',
);
} else {
final item = _peek();
if (item != null) {
item.scope.addBreadcrumb(crumb, hint: hint);
} else {
_options.logger(
SentryLevel.fatal,
'Stack peek was null when addBreadcrumb',
);
}
}
}

/// Binds a different client to the hub
void bindClient(SentryClient client) {
if (!_isEnabled) {
Expand Down
5 changes: 5 additions & 0 deletions dart/lib/src/noop_hub.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:async';

import 'package:sentry/src/protocol/breadcrumb.dart';

import 'client.dart';
import 'hub.dart';
import 'protocol/sentry_event.dart';
Expand Down Expand Up @@ -54,4 +56,7 @@ class NoOpHub implements Hub {

@override
SentryId get lastEventId => SentryId.empty();

@override
void addBreadcrumb(Breadcrumb crumb, {dynamic hint}) {}
}
6 changes: 3 additions & 3 deletions dart/lib/src/protocol/breadcrumb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import 'sentry_level.dart';
/// * https://docs.sentry.io/development/sdk-dev/event-payloads/breadcrumbs/
class Breadcrumb {
/// Creates a breadcrumb that can be attached to an [Event].
const Breadcrumb(
Breadcrumb({
this.message,
this.timestamp, {
DateTime timestamp,
this.category,
this.data,
this.level = SentryLevel.info,
this.type,
}) : assert(timestamp != null);
}) : timestamp = timestamp ?? getUtcDateTime();

/// Describes the breadcrumb.
///
Expand Down
5 changes: 5 additions & 0 deletions dart/lib/src/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ class Sentry {
/// Check if the current Hub is enabled/active.
static bool get isEnabled => currentHub.isEnabled;

/// Adds a breacrumb to the current Scope
static void addBreadcrumb(Breadcrumb crumb, {dynamic hint}) {
currentHub.addBreadcrumb(crumb, hint: hint);
}

static bool _setDefaultConfiguration(SentryOptions options) {
if (options.dsn == null) {
throw ArgumentError.notNull(
Expand Down
11 changes: 7 additions & 4 deletions dart/test/event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ void main() {
test('$Breadcrumb serializes', () {
expect(
Breadcrumb(
'example log',
DateTime.utc(2019),
message: 'example log',
timestamp: DateTime.utc(2019),
level: SentryLevel.debug,
category: 'test',
).toJson(),
Expand Down Expand Up @@ -63,8 +63,11 @@ void main() {
extras: <String, String>{'foo': 'bar'});

final breadcrumbs = [
Breadcrumb('test log', timestamp,
level: SentryLevel.debug, category: 'test'),
Breadcrumb(
message: 'test log',
timestamp: timestamp,
level: SentryLevel.debug,
category: 'test'),
];

final error = StateError('test-error');
Expand Down
11 changes: 11 additions & 0 deletions dart/test/hub_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ void main() {
true,
);
});

test('should add breadcrumb to current Scope', () {
hub.configureScope((Scope scope) {
expect(0, scope..breadcrumbs.length);
});
hub.addBreadcrumb(Breadcrumb(message: 'test'));
hub.configureScope((Scope scope) {
expect(1, scope..breadcrumbs.length);
expect('test', scope..breadcrumbs.first.message);
});
});
});

group('Hub Client', () {
Expand Down
4 changes: 3 additions & 1 deletion dart/test/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ final fakeEvent = SentryEvent(
ipAddress: '127.0.0.1',
extras: <String, String>{'first-sign-in': '2020-01-01'}),
breadcrumbs: [
Breadcrumb('UI Lifecycle', DateTime.now().toUtc(),
Breadcrumb(
message: 'UI Lifecycle',
timestamp: DateTime.now().toUtc(),
category: 'ui.lifecycle',
type: 'navigation',
data: {'screen': 'MainActivity', 'state': 'created'},
Expand Down
55 changes: 44 additions & 11 deletions dart/test/scope_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ void main() {
test('adds $Breadcrumb', () {
final sut = fixture.getSut();

final breadcrumb = Breadcrumb('test log', DateTime.utc(2019));
final breadcrumb = Breadcrumb(
message: 'test log',
timestamp: DateTime.utc(2019),
);
sut.addBreadcrumb(breadcrumb);

expect(sut.breadcrumbs.last, breadcrumb);
Expand All @@ -53,7 +56,10 @@ void main() {
beforeBreadcrumbCallback: fixture.beforeBreadcrumbCallback,
);

final breadcrumb = Breadcrumb('test log', DateTime.utc(2019));
final breadcrumb = Breadcrumb(
message: 'test log',
timestamp: DateTime.utc(2019),
);
sut.addBreadcrumb(breadcrumb);

expect(sut.breadcrumbs.length, 0);
Expand All @@ -71,9 +77,18 @@ void main() {
final maxBreadcrumbs = 2;
final sut = fixture.getSut(maxBreadcrumbs: maxBreadcrumbs);

final breadcrumb1 = Breadcrumb('test log', DateTime.utc(2019));
final breadcrumb2 = Breadcrumb('test log', DateTime.utc(2019));
final breadcrumb3 = Breadcrumb('test log', DateTime.utc(2019));
final breadcrumb1 = Breadcrumb(
message: 'test log',
timestamp: DateTime.utc(2019),
);
final breadcrumb2 = Breadcrumb(
message: 'test log',
timestamp: DateTime.utc(2019),
);
final breadcrumb3 = Breadcrumb(
message: 'test log',
timestamp: DateTime.utc(2019),
);
sut.addBreadcrumb(breadcrumb1);
sut.addBreadcrumb(breadcrumb2);
sut.addBreadcrumb(breadcrumb3);
Expand All @@ -84,9 +99,18 @@ void main() {
test('rotates $Breadcrumb', () {
final sut = fixture.getSut(maxBreadcrumbs: 2);

final breadcrumb1 = Breadcrumb('test log', DateTime.utc(2019));
final breadcrumb2 = Breadcrumb('test log', DateTime.utc(2019));
final breadcrumb3 = Breadcrumb('test log', DateTime.utc(2019));
final breadcrumb1 = Breadcrumb(
message: 'test log',
timestamp: DateTime.utc(2019),
);
final breadcrumb2 = Breadcrumb(
message: 'test log',
timestamp: DateTime.utc(2019),
);
final breadcrumb3 = Breadcrumb(
message: 'test log',
timestamp: DateTime.utc(2019),
);
sut.addBreadcrumb(breadcrumb1);
sut.addBreadcrumb(breadcrumb2);
sut.addBreadcrumb(breadcrumb3);
Expand All @@ -100,7 +124,10 @@ void main() {
final maxBreadcrumbs = 0;
final sut = fixture.getSut(maxBreadcrumbs: maxBreadcrumbs);

final breadcrumb1 = Breadcrumb('test log', DateTime.utc(2019));
final breadcrumb1 = Breadcrumb(
message: 'test log',
timestamp: DateTime.utc(2019),
);
sut.addBreadcrumb(breadcrumb1);

expect(sut.breadcrumbs.length, maxBreadcrumbs);
Expand All @@ -109,7 +136,10 @@ void main() {
test('clears $Breadcrumb list', () {
final sut = fixture.getSut();

final breadcrumb1 = Breadcrumb('test log', DateTime.utc(2019));
final breadcrumb1 = Breadcrumb(
message: 'test log',
timestamp: DateTime.utc(2019),
);
sut.addBreadcrumb(breadcrumb1);
sut.clear();

Expand Down Expand Up @@ -153,7 +183,10 @@ void main() {
test('clears $Scope', () {
final sut = fixture.getSut();

final breadcrumb1 = Breadcrumb('test log', DateTime.utc(2019));
final breadcrumb1 = Breadcrumb(
message: 'test log',
timestamp: DateTime.utc(2019),
);
sut.addBreadcrumb(breadcrumb1);

sut.level = SentryLevel.debug;
Expand Down