-
-
Notifications
You must be signed in to change notification settings - Fork 277
ref: Hub passes the Scope #114
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
Changes from 7 commits
8c6727d
7570846
c1033b2
c3f453a
a46e144
8a14620
4c3f323
35e3072
30fa7a9
9088c88
e93f85e
7b05b0b
1f70e4f
1f4bb44
d4334a9
d02947f
ba721bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,10 @@ class Hub { | |
| ); | ||
| } | ||
|
|
||
| final ListQueue<_StackItem> _stack; | ||
| final ListQueue<_StackItem> _stack = ListQueue(); | ||
|
|
||
| /// if stack is empty, it throws IterableElementError.noElement() | ||
| _StackItem _peek() => _stack.isNotEmpty ? _stack.first : null; | ||
|
|
||
| final SentryOptions _options; | ||
|
|
||
|
|
@@ -32,20 +35,18 @@ class Hub { | |
| return Hub._(options); | ||
| } | ||
|
|
||
| Hub._(SentryOptions options) | ||
| : _options = options, | ||
| _stack = ListQueue() { | ||
| Hub._(SentryOptions options) : _options = options { | ||
| _stack.add(_StackItem(_getClient(fromOptions: options), Scope(_options))); | ||
| _isEnabled = true; | ||
| } | ||
|
|
||
| static void _validateOptions(SentryOptions options) { | ||
| if (options == null) { | ||
| throw ArgumentError.notNull('options'); | ||
| throw ArgumentError.notNull('SentryOptions is required.'); | ||
| } | ||
|
|
||
| if (options.dsn == null) { | ||
| throw ArgumentError.notNull('options.dsn'); | ||
| if (options.dsn == null || options.dsn.isEmpty) { | ||
marandaneto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| throw ArgumentError.notNull('DSN is required.'); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -54,7 +55,7 @@ class Hub { | |
| /// Check if the Hub is enabled/active. | ||
| bool get isEnabled => _isEnabled; | ||
|
|
||
| SentryId _lastEventId; | ||
| SentryId _lastEventId = SentryId.empty(); | ||
|
|
||
| /// Last event id recorded in the current scope | ||
| SentryId get lastEventId => _lastEventId; | ||
|
|
@@ -74,7 +75,7 @@ class Hub { | |
| 'captureEvent called with null parameter.', | ||
| ); | ||
| } else { | ||
| final item = _stack.first; | ||
| final item = _peek(); | ||
| if (item != null) { | ||
| try { | ||
| sentryId = await item.client.captureEvent(event, scope: item.scope); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rxlabz I noticed that all the methods are sync now because of
should we aim for sync calls or keep it async?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While we send the envelope to the client/transport to be sent to the network directly, this should be async. I'd propose we stick to async for now, user code already expects do await on capture methods, and allows us to interface with the native layer by purely writing an envelope to disk (which is async) if you're not using
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand. They are not sync, they return a Future
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rxlabz
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
FutureOr<SentryId> captureEvent(Event event) async {//...}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a big fan because of:
but I got it I guess: let's keep as it is till we have a concrete implementation of the transport layer, so we'd know what looks better. |
||
|
|
@@ -115,14 +116,11 @@ class Hub { | |
| 'captureException called with null parameter.', | ||
| ); | ||
| } else { | ||
| final item = _stack.first; | ||
| final item = _peek(); | ||
| if (item != null) { | ||
| try { | ||
| // TODO pass the scope | ||
| sentryId = await item.client.captureException( | ||
| throwable, | ||
| stackTrace: stackTrace, | ||
| ); | ||
| sentryId = await item.client.captureException(throwable, | ||
| stackTrace: stackTrace, scope: item.scope); | ||
| } catch (err) { | ||
| _options.logger( | ||
| SeverityLevel.error, | ||
|
|
@@ -162,16 +160,14 @@ class Hub { | |
| 'captureMessage called with null parameter.', | ||
| ); | ||
| } else { | ||
| final item = _stack.first; | ||
| final item = _peek(); | ||
| if (item != null) { | ||
| try { | ||
| // TODO pass the scope | ||
| sentryId = await item.client.captureMessage( | ||
| message, | ||
| level: level, | ||
| template: template, | ||
| params: params, | ||
| ); | ||
| sentryId = await item.client.captureMessage(message, | ||
| level: level, | ||
| template: template, | ||
| params: params, | ||
| scope: item.scope); | ||
marandaneto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } catch (err) { | ||
| _options.logger( | ||
| SeverityLevel.error, | ||
|
|
@@ -196,7 +192,7 @@ class Hub { | |
| _options.logger(SeverityLevel.warning, | ||
| "Instance is disabled and this 'bindClient' call is a no-op."); | ||
| } else { | ||
| final item = _stack.first; | ||
| final item = _peek(); | ||
| if (item != null) { | ||
| if (client != null) { | ||
| _options.logger(SeverityLevel.debug, 'New client bound to scope.'); | ||
|
|
@@ -234,7 +230,7 @@ class Hub { | |
| "Instance is disabled and this 'close' call is a no-op.", | ||
| ); | ||
| } else { | ||
| final item = _stack.first; | ||
| final item = _peek(); | ||
| if (item != null) { | ||
| try { | ||
| item.client.close(); | ||
|
|
@@ -262,7 +258,7 @@ class Hub { | |
| "Instance is disabled and this 'configureScope' call is a no-op.", | ||
| ); | ||
| } else { | ||
| final item = _stack.first; | ||
| final item = _peek(); | ||
| if (item != null) { | ||
| try { | ||
| callback(item.scope); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import 'dart:async'; | ||
|
|
||
| import 'package:sentry/src/client.dart'; | ||
| import 'package:sentry/src/hub.dart'; | ||
| import 'package:sentry/src/protocol/sentry_id.dart'; | ||
| import 'package:sentry/src/protocol/level.dart'; | ||
| import 'package:sentry/src/protocol/event.dart'; | ||
|
||
|
|
||
| import 'hub.dart'; | ||
|
|
||
| class NoOpHub implements Hub { | ||
| NoOpHub._(); | ||
|
|
||
| static final NoOpHub _instance = NoOpHub._(); | ||
|
|
||
| factory NoOpHub() { | ||
| return _instance; | ||
| } | ||
|
|
||
| @override | ||
| void bindClient(SentryClient client) {} | ||
|
|
||
| @override | ||
| Future<SentryId> captureEvent(Event event) => Future.value(SentryId.empty()); | ||
|
|
||
| @override | ||
| Future<SentryId> captureException(throwable, {stackTrace}) => | ||
| Future.value(SentryId.empty()); | ||
|
|
||
| @override | ||
| Future<SentryId> captureMessage(String message, | ||
| {SeverityLevel level = SeverityLevel.info, | ||
| String template, | ||
| List params}) => | ||
| Future.value(SentryId.empty()); | ||
marandaneto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @override | ||
| Hub clone() => this; | ||
|
|
||
| @override | ||
| void close() {} | ||
|
|
||
| @override | ||
| void configureScope(callback) {} | ||
|
|
||
| @override | ||
| bool get isEnabled => false; | ||
|
|
||
| @override | ||
| SentryId get lastEventId => SentryId.empty(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,16 @@ | ||
| /// Sentry response id | ||
| class SentryId { | ||
| static const String emptyId = '00000000-0000-0000-0000-000000000000'; | ||
| static const String _emptyId = '00000000-0000-0000-0000-000000000000'; | ||
|
|
||
| /// The ID Sentry.io assigned to the submitted event for future reference. | ||
| final String _id; | ||
|
|
||
| String get id => _id; | ||
| // TODO: should we generate the new UUID here with an empty ctor? | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if so, we'd need to import the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I maybe missed it, but I didn't found a method to generate a Uuid from String in the uuid package
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created a task for it |
||
|
|
||
| const SentryId(this._id); | ||
|
|
||
| factory SentryId.empty() => SentryId(emptyId); | ||
| factory SentryId.empty() => SentryId(_emptyId); | ||
|
|
||
| @override | ||
| String toString() => _id.replaceAll('-', ''); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.