-
-
Notifications
You must be signed in to change notification settings - Fork 277
Feat : add a Hub class #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
6a5d2c3
hub interface & instanciation
rxlabz 4f01775
- hub capture event
rxlabz ea5c55f
- hub capture exception
rxlabz bd09da0
hub captureMessage
rxlabz c5317a4
fix some tests
rxlabz 6a8910e
fix more tests
rxlabz f5d3dd0
changelog
rxlabz f102ac3
fix all tests
rxlabz 055b9b0
feedbacks
rxlabz 370d2d5
fix test : revert to ArgumentError.notNull('options')
rxlabz 974d1f6
remove required hub methods
rxlabz c8c1df0
implement `Hub.close()`
rxlabz 6c6c649
feedbacks : remove the IHub interface + minors
rxlabz a924040
Hub.configureScope
rxlabz 823c91c
Hub.clone and Scope.clone
rxlabz b04d67c
remove the non required scope methods
rxlabz 37cf83c
replace the ListQueue _stack by a DoubleLinkedQueue
rxlabz b9f9f9e
rename `response` to `sentryId`
rxlabz 5067a36
serialize the potential error stackTrace
rxlabz 54729ba
Revert the DoubleLinkedQueue to a resourceless ListQueue
rxlabz 729d6bc
fix a json serialization test
rxlabz 4ea1537
add a const SentryId.emptyId
rxlabz 5932534
don't assign a new lastEventId if the client capture method is not ca…
rxlabz 97f6c53
feedbacks:
rxlabz e89c488
feedbacks:
rxlabz 647f1b0
simplify the captureMessage API
rxlabz 91f709a
capture message
rxlabz File filter
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
commit 6a5d2c391cbca56e8a757cd61fd746dc3c4f974d
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
marandaneto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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'); | ||
rxlabz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| 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(); | ||
| } | ||
rxlabz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @override | ||
| void bindClient(SentryClient client) { | ||
| // TODO: implement bindClient | ||
| throw UnimplementedError(); | ||
| } | ||
|
|
||
| @override | ||
| void clearBreadcrumbs() { | ||
| // TODO: implement clearBreadcrumbs | ||
| throw UnimplementedError(); | ||
| } | ||
rxlabz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @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(); | ||
| } | ||
rxlabz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @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(); | ||
| } | ||
rxlabz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @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); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
marandaneto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const SentryId(this.id); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', () { | ||
marandaneto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| test('should not instanciate without a sentryOptions', () { | ||
marandaneto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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); | ||
| }); | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| final fakeDns = 'https://[email protected]/1234567'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.