-
-
Notifications
You must be signed in to change notification settings - Fork 277
feat: before breadcrumb and scope ref #122
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 all commits
53d5d0d
15c53ab
b54cb69
583d5eb
e63dc3d
59c9d75
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 |
|---|---|---|
|
|
@@ -6,32 +6,14 @@ import 'sentry_options.dart'; | |
| /// Scope data to be sent with the event | ||
| class Scope { | ||
| /// How important this event is. | ||
| SentryLevel _level; | ||
|
|
||
| SentryLevel get level => _level; | ||
|
|
||
| set level(SentryLevel level) { | ||
| _level = level; | ||
| } | ||
| SentryLevel level; | ||
|
|
||
| /// The name of the transaction which generated this event, | ||
| /// for example, the route name: `"/users/<username>/"`. | ||
| String _transaction; | ||
|
|
||
| String get transaction => _transaction; | ||
|
|
||
| set transaction(String transaction) { | ||
| _transaction = transaction; | ||
| } | ||
| String transaction; | ||
|
|
||
| /// Information about the current user. | ||
| User _user; | ||
|
|
||
| User get user => _user; | ||
|
|
||
| set user(User user) { | ||
| _user = user; | ||
| } | ||
| User user; | ||
|
|
||
| /// Used to deduplicate events by grouping ones with the same fingerprint | ||
| /// together. | ||
|
|
@@ -71,21 +53,38 @@ class Scope { | |
|
|
||
| Map<String, dynamic> get extra => Map.unmodifiable(_extra); | ||
|
|
||
| // TODO: EventProcessors, Contexts, BeforeBreadcrumbCallback, Breadcrumb Hint, clone | ||
| // TODO: Contexts | ||
|
|
||
| /// Scope's event processor list | ||
| final List<EventProcessor> _eventProcessors = []; | ||
|
|
||
| List<EventProcessor> get eventProcessors => | ||
| List.unmodifiable(_eventProcessors); | ||
|
|
||
| final SentryOptions _options; | ||
|
|
||
| Scope(this._options) : assert(_options != null, 'SentryOptions is required'); | ||
|
|
||
| /// Adds a breadcrumb to the breadcrumbs queue | ||
| void addBreadcrumb(Breadcrumb breadcrumb) { | ||
| void addBreadcrumb(Breadcrumb breadcrumb, {dynamic hint}) { | ||
| assert(breadcrumb != null, "Breadcrumb can't be null"); | ||
|
|
||
| // bail out if maxBreadcrumbs is zero | ||
| if (_options.maxBreadcrumbs == 0) { | ||
| return; | ||
| } | ||
|
|
||
| // run before breadcrumb callback if set | ||
| if (_options.beforeBreadcrumbCallback != null) { | ||
| breadcrumb = _options.beforeBreadcrumbCallback(breadcrumb, hint); | ||
|
|
||
| if (breadcrumb == null) { | ||
| _options.logger( | ||
| SentryLevel.info, 'Breadcrumb was dropped by beforeBreadcrumb'); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| // remove first item if list if full | ||
| if (_breadcrumbs.length >= _options.maxBreadcrumbs && | ||
| _breadcrumbs.isNotEmpty) { | ||
|
|
@@ -100,15 +99,23 @@ class Scope { | |
| _breadcrumbs.clear(); | ||
| } | ||
|
|
||
| /// Adds an event processor | ||
| void addEventProcessor(EventProcessor eventProcessor) { | ||
| assert(eventProcessor != null, "EventProcessor can't be null"); | ||
|
|
||
| _eventProcessors.add(eventProcessor); | ||
| } | ||
|
|
||
| /// Resets the Scope to its default state | ||
| void clear() { | ||
| clearBreadcrumbs(); | ||
| _level = null; | ||
| _transaction = null; | ||
| _user = null; | ||
| level = null; | ||
| transaction = null; | ||
| user = null; | ||
| _fingerprint = null; | ||
| _tags.clear(); | ||
| _extra.clear(); | ||
| _eventProcessors.clear(); | ||
| } | ||
|
|
||
| /// Sets a tag to the Scope | ||
|
|
@@ -135,6 +142,7 @@ class Scope { | |
| /// Removes an extra from the Scope | ||
| void removeExtra(String key) => _extra.remove(key); | ||
|
|
||
| /// Clones the current Scope | ||
| Scope clone() { | ||
| final clone = Scope(_options) | ||
| ..user = user | ||
|
|
@@ -153,6 +161,10 @@ class Scope { | |
| clone.addBreadcrumb(breadcrumb); | ||
| } | ||
|
|
||
| for (final eventProcessor in _eventProcessors) { | ||
|
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. Since we're in the class, what about a private constructor or factory method that takes all fields as named args?
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. mm yeah but rethinking this right now, maybe it'd make sense to just do a copyWith and follow the convention? tbh I just added the missing field in the existent method, I will check whats the state of the art for cloning objects on Dart.
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. https://pub.dev/documentation/copyable/latest/#examples
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 will add this as a task on our project, so I can merge this now
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. copyWith is probably the "most standard way" ( used a lot in Flutter source code, and in https://pub.dev/packages/freezed, a popular immutable package) |
||
| clone.addEventProcessor(eventProcessor); | ||
| } | ||
|
|
||
| return clone; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.