Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6a5d2c3
hub interface & instanciation
rxlabz Oct 15, 2020
4f01775
- hub capture event
rxlabz Oct 15, 2020
ea5c55f
- hub capture exception
rxlabz Oct 15, 2020
bd09da0
hub captureMessage
rxlabz Oct 15, 2020
c5317a4
fix some tests
rxlabz Oct 15, 2020
6a8910e
fix more tests
rxlabz Oct 15, 2020
f5d3dd0
changelog
rxlabz Oct 15, 2020
f102ac3
fix all tests
rxlabz Oct 15, 2020
055b9b0
feedbacks
rxlabz Oct 15, 2020
370d2d5
fix test : revert to ArgumentError.notNull('options')
rxlabz Oct 15, 2020
974d1f6
remove required hub methods
rxlabz Oct 15, 2020
c8c1df0
implement `Hub.close()`
rxlabz Oct 16, 2020
6c6c649
feedbacks : remove the IHub interface + minors
rxlabz Oct 16, 2020
a924040
Hub.configureScope
rxlabz Oct 16, 2020
823c91c
Hub.clone and Scope.clone
rxlabz Oct 16, 2020
b04d67c
remove the non required scope methods
rxlabz Oct 16, 2020
37cf83c
replace the ListQueue _stack by a DoubleLinkedQueue
rxlabz Oct 16, 2020
b9f9f9e
rename `response` to `sentryId`
rxlabz Oct 16, 2020
5067a36
serialize the potential error stackTrace
rxlabz Oct 16, 2020
54729ba
Revert the DoubleLinkedQueue to a resourceless ListQueue
rxlabz Oct 16, 2020
729d6bc
fix a json serialization test
rxlabz Oct 16, 2020
4ea1537
add a const SentryId.emptyId
rxlabz Oct 16, 2020
5932534
don't assign a new lastEventId if the client capture method is not ca…
rxlabz Oct 16, 2020
97f6c53
feedbacks:
rxlabz Oct 16, 2020
e89c488
feedbacks:
rxlabz Oct 16, 2020
647f1b0
simplify the captureMessage API
rxlabz Oct 19, 2020
91f709a
capture message
rxlabz Oct 19, 2020
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
Next Next commit
hub interface & instanciation
  • Loading branch information
rxlabz committed Oct 15, 2020
commit 6a5d2c391cbca56e8a757cd61fd746dc3c4f974d
274 changes: 274 additions & 0 deletions dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
import 'dart:collection';

import 'package:meta/meta.dart';

import 'client.dart';
import 'protocol.dart';
import 'scope.dart';
import 'sentry_options.dart';

/// SDK API contract which combines a client and scope management
class Hub implements HubInterface {
static SentryClient _getClient({SentryOptions fromOptions}) => SentryClient(
dsn: fromOptions.dsn,
environmentAttributes: fromOptions.environmentAttributes,
compressPayload: fromOptions.compressPayload,
httpClient: fromOptions.httpClient,
clock: fromOptions.clock,
uuidGenerator: fromOptions.uuidGenerator,
);

final ListQueue<_StackItem> _stack;

factory Hub(SentryOptions options) {
_validateOptions(options);

final client = _getClient(fromOptions: options);
return Hub._(client: client, scope: Scope(options));
}

Hub._({@required SentryClient client, @required Scope scope})
: _stack = ListQueue() {
_stack.add(_StackItem(client, scope));
_isEnabled = true;
}

static void _validateOptions(SentryOptions options) {
if (options == null) {
throw ArgumentError.notNull('options');
}

if (options.dsn == null) {
throw ArgumentError.notNull('options.dsn');
}
}

bool _isEnabled = false;

@override
bool get isEnabled => _isEnabled;

SentryId _lastEventId;

@override
SentryId get lastEventId => _lastEventId;

@override
SentryId captureEvent(Event event) {
// TODO: implement captureEvent
throw UnimplementedError();
}

@override
SentryId captureException({Message message, SeverityLevel level}) {
// TODO: implement captureException
throw UnimplementedError();
}

@override
SentryId captureMessage({Message message, SeverityLevel level}) {
// TODO: implement captureMessage
throw UnimplementedError();
}

@override
void addBreadcrumb(Breadcrumb breadCrumb) {
// TODO: implement addBreadcrumb
throw UnimplementedError();
}

@override
void bindClient(SentryClient client) {
// TODO: implement bindClient
throw UnimplementedError();
}

@override
void clearBreadcrumbs() {
// TODO: implement clearBreadcrumbs
throw UnimplementedError();
}

@override
Hub clone() {
// TODO: implement clone
throw UnimplementedError();
}

@override
void close() {
// TODO: implement close
throw UnimplementedError();
}

@override
void configureScope(ScopeCallback callback) {
// TODO: implement configureScope
throw UnimplementedError();
}

@override
void popScope() {
// TODO: implement popScope
throw UnimplementedError();
}

@override
void pushScope() {
// TODO: implement pushScope
throw UnimplementedError();
}

@override
void removeExtra(String key) {
// TODO: implement removeExtra
throw UnimplementedError();
}

@override
void removeTag({String key}) {
// TODO: implement removeTag
throw UnimplementedError();
}

@override
void setExtra(String key, String value) {
// TODO: implement setExtra
throw UnimplementedError();
}

@override
void setFingerPrint(List<String> fingerPrint) {
// TODO: implement setFingerPrint
throw UnimplementedError();
}

@override
void setLevel(SeverityLevel level) {
// TODO: implement setLevel
throw UnimplementedError();
}

@override
void setTag({String key, String value}) {
// TODO: implement setTag
throw UnimplementedError();
}

@override
void setTransaction(String transaction) {
// TODO: implement setTransaction
throw UnimplementedError();
}

@override
void setUser(User user) {
// TODO: implement setUser
throw UnimplementedError();
}

@override
void startSession() {
// TODO: implement startSession
throw UnimplementedError();
}

@override
void stopSession() {
// TODO: implement stopSession
throw UnimplementedError();
}

@override
void withScope(ScopeCallback callback) {
// TODO: implement withScope
throw UnimplementedError();
}
}

class _StackItem {
final SentryClient _client;

final Scope _scope;

_StackItem(this._client, this._scope);
}

abstract class HubInterface {
/// Check if the Hub is enabled/active.
bool get isEnabled;

/// Last event id recorded in the current scope
SentryId get lastEventId;

/// Captures the event.
SentryId captureEvent(Event event);

/// Captures the exception
SentryId captureException({Message message, SeverityLevel level});

/// Captures the message.
SentryId captureMessage({Message message, SeverityLevel level});

/// Starts a new session. If there's a running session, it ends it before starting the new one.
void startSession();

/// ends the current session
void stopSession();

/// Flushes out the queue for up to timeout seconds and disable the Hub.
void close();

/// Adds a breadcrumb to the current Scope
void addBreadcrumb(Breadcrumb breadCrumb);

/// Sets the level of all events sent within current Scope
void setLevel(SeverityLevel level);

/// Sets the name of the current transaction to the current Scope.
void setTransaction(String transaction);

/// Shallow merges user configuration (email, username, etc) to the current Scope.
void setUser(User user);

/// Sets the fingerprint to group specific events together to the current Scope.
void setFingerPrint(List<String> fingerPrint);

/// Deletes current breadcrumbs from the current scope.
void clearBreadcrumbs();

/// Sets the tag to a string value to the current Scope, overwriting a potential previous value
void setTag({String key, String value});

/// Removes the tag to a string value to the current Scope
void removeTag({String key});

/// Sets the extra key to an arbitrary value to the current Scope, overwriting a potential previous value
void setExtra(String key, String value);

/// Removes the extra key to an arbitrary value to the current Scope
void removeExtra(String key);

/// Pushes a new scope while inheriting the current scope's data.
void pushScope();

/// Removes the first scope
void popScope();

/// Runs the callback with a new scope which gets dropped at the end
void withScope(ScopeCallback callback);

/// Configures the scope through the callback.
void configureScope(ScopeCallback callback);

/// Binds a different client to the hub
void bindClient(SentryClient client);

/// Flushes events queued up, but keeps the Hub enabled. Not implemented yet.
/// void flush({int timeout} )

/// Clones the Hub
Hub clone();
}

typedef ScopeCallback = void Function(Scope);
1 change: 1 addition & 0 deletions dart/lib/src/protocol.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export 'protocol/message.dart';
export 'protocol/package.dart';
export 'protocol/runtime.dart';
export 'protocol/sdk.dart';
export 'protocol/sentry_id.dart';
export 'protocol/system.dart';
export 'protocol/user.dart';
7 changes: 7 additions & 0 deletions dart/lib/src/protocol/sentry_id.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// Sentry response id
class SentryId {
/// The ID Sentry.io assigned to the submitted event for future reference.
final String id;

const SentryId(this.id);
}
22 changes: 22 additions & 0 deletions dart/test/hub_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:sentry/sentry.dart';
import 'package:sentry/src/hub.dart';
import 'package:test/test.dart';

import 'mocks.dart';

void main() {
group('Hub instanciation', () {
test('should not instanciate without a sentryOptions', () {
expect(() => Hub(null), throwsArgumentError);
});

test('should not instanciate without a dsn', () {
expect(() => Hub(SentryOptions()), throwsArgumentError);
});

test('should instanciate with a dsn', () {
final hub = Hub(SentryOptions(dsn: fakeDns));
expect(hub.isEnabled, true);
});
});
}
1 change: 1 addition & 0 deletions dart/test/mocks.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
final fakeDns = 'https://[email protected]/1234567';
6 changes: 3 additions & 3 deletions dart/test/sentry_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import 'package:mockito/mockito.dart';
import 'package:sentry/sentry.dart';
import 'package:test/test.dart';

import 'mocks.dart';

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

Exception anException;

final dns = 'https://[email protected]/1234567';

setUp(() {
Sentry.init((options) => options.dsn = dns);
Sentry.init((options) => options.dsn = fakeDns);

client = MockSentryClient();
Sentry.initClient(client);
Expand Down