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 .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGELOG.md merge=union
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- Ref: SentryId generates UUID #119
- Ref: Event now is SentryEvent and added GPU #121
- Feat: before breadcrumb and scope ref. #122
- Ref: Sentry init with null and empty DSN and close method #126
- Ref: Hint is passed across Sentry static class, Hub and Client #124
- Ref: Remove stackFrameFilter in favor of beforeSendCallback #125

Expand Down
2 changes: 1 addition & 1 deletion dart/lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ abstract class SentryClient {
return captureEvent(event, scope: scope, hint: hint);
}

Future<void> close() async {
void close() {
options.httpClient?.close();
}

Expand Down
23 changes: 19 additions & 4 deletions dart/lib/src/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ class Sentry {
);
}

_setDefaultConfiguration(options);
// if there's an empty DSN, SDK is disabled
if (!_setDefaultConfiguration(options)) {
return;
}

final hub = currentHub;
_hub = Hub(options);
Expand Down Expand Up @@ -82,17 +85,29 @@ class Sentry {
}

/// Close the client SDK
static Future<void> close() async => currentHub.close();
static void close() {
final hub = currentHub;
_hub = NoOpHub();
return hub.close();
}

/// Check if the current Hub is enabled/active.
static bool get isEnabled => currentHub.isEnabled;

static void _setDefaultConfiguration(SentryOptions options) {
// TODO: check DSN nullability and empty
static bool _setDefaultConfiguration(SentryOptions options) {
if (options.dsn == null) {
throw ArgumentError.notNull(
'DSN is required. Use empty string to disable SDK.');
}
if (options.dsn.isEmpty) {
close();
return false;
}

if (options.debug && options.logger == noOpLogger) {
options.logger = dartLogger;
}
return true;
}

/// client injector only use for testing
Expand Down
35 changes: 32 additions & 3 deletions dart/test/sentry_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:test/test.dart';
import 'mocks.dart';

void main() {
group('Sentry static entry', () {
group('Sentry capture methods', () {
SentryClient client;

Exception anException;
Expand All @@ -17,9 +17,12 @@ void main() {
client = MockSentryClient();
Sentry.initClient(client);
});
tearDown(() {
Sentry.close();
});

test('should capture the event', () {
Sentry.captureEvent(fakeEvent);
test('should capture the event', () async {
await Sentry.captureEvent(fakeEvent);
verify(
client.captureEvent(
fakeEvent,
Expand Down Expand Up @@ -54,4 +57,30 @@ void main() {
).called(1);
});
});
group('Sentry is enabled or closed', () {
test('null DSN', () {
expect(
() => Sentry.init((options) => options.dsn = null),
throwsArgumentError,
);
expect(Sentry.isEnabled, false);
});

test('empty DSN', () {
Sentry.init((options) => options.dsn = '');
expect(Sentry.isEnabled, false);
});

test('empty DSN', () {
Sentry.init((options) => options.dsn = fakeDsn);

Sentry.initClient(MockSentryClient());

expect(Sentry.isEnabled, true);

Sentry.close();

expect(Sentry.isEnabled, false);
});
});
}