@@ -6,32 +6,14 @@ import 'sentry_options.dart';
66/// Scope data to be sent with the event
77class Scope {
88 /// How important this event is.
9- SentryLevel _level;
10-
11- SentryLevel get level => _level;
12-
13- set level (SentryLevel level) {
14- _level = level;
15- }
9+ SentryLevel level;
1610
1711 /// The name of the transaction which generated this event,
1812 /// for example, the route name: `"/users/<username>/"` .
19- String _transaction;
20-
21- String get transaction => _transaction;
22-
23- set transaction (String transaction) {
24- _transaction = transaction;
25- }
13+ String transaction;
2614
2715 /// Information about the current user.
28- User _user;
29-
30- User get user => _user;
31-
32- set user (User user) {
33- _user = user;
34- }
16+ User user;
3517
3618 /// Used to deduplicate events by grouping ones with the same fingerprint
3719 /// together.
@@ -71,21 +53,38 @@ class Scope {
7153
7254 Map <String , dynamic > get extra => Map .unmodifiable (_extra);
7355
74- // TODO: EventProcessors, Contexts, BeforeBreadcrumbCallback, Breadcrumb Hint, clone
56+ // TODO: Contexts
57+
58+ /// Scope's event processor list
59+ final List <EventProcessor > _eventProcessors = [];
60+
61+ List <EventProcessor > get eventProcessors =>
62+ List .unmodifiable (_eventProcessors);
7563
7664 final SentryOptions _options;
7765
7866 Scope (this ._options) : assert (_options != null , 'SentryOptions is required' );
7967
8068 /// Adds a breadcrumb to the breadcrumbs queue
81- void addBreadcrumb (Breadcrumb breadcrumb) {
69+ void addBreadcrumb (Breadcrumb breadcrumb, { dynamic hint} ) {
8270 assert (breadcrumb != null , "Breadcrumb can't be null" );
8371
8472 // bail out if maxBreadcrumbs is zero
8573 if (_options.maxBreadcrumbs == 0 ) {
8674 return ;
8775 }
8876
77+ // run before breadcrumb callback if set
78+ if (_options.beforeBreadcrumbCallback != null ) {
79+ breadcrumb = _options.beforeBreadcrumbCallback (breadcrumb, hint);
80+
81+ if (breadcrumb == null ) {
82+ _options.logger (
83+ SentryLevel .info, 'Breadcrumb was dropped by beforeBreadcrumb' );
84+ return ;
85+ }
86+ }
87+
8988 // remove first item if list if full
9089 if (_breadcrumbs.length >= _options.maxBreadcrumbs &&
9190 _breadcrumbs.isNotEmpty) {
@@ -100,15 +99,23 @@ class Scope {
10099 _breadcrumbs.clear ();
101100 }
102101
102+ /// Adds an event processor
103+ void addEventProcessor (EventProcessor eventProcessor) {
104+ assert (eventProcessor != null , "EventProcessor can't be null" );
105+
106+ _eventProcessors.add (eventProcessor);
107+ }
108+
103109 /// Resets the Scope to its default state
104110 void clear () {
105111 clearBreadcrumbs ();
106- _level = null ;
107- _transaction = null ;
108- _user = null ;
112+ level = null ;
113+ transaction = null ;
114+ user = null ;
109115 _fingerprint = null ;
110116 _tags.clear ();
111117 _extra.clear ();
118+ _eventProcessors.clear ();
112119 }
113120
114121 /// Sets a tag to the Scope
@@ -135,6 +142,7 @@ class Scope {
135142 /// Removes an extra from the Scope
136143 void removeExtra (String key) => _extra.remove (key);
137144
145+ /// Clones the current Scope
138146 Scope clone () {
139147 final clone = Scope (_options)
140148 ..user = user
@@ -153,6 +161,10 @@ class Scope {
153161 clone.addBreadcrumb (breadcrumb);
154162 }
155163
164+ for (final eventProcessor in _eventProcessors) {
165+ clone.addEventProcessor (eventProcessor);
166+ }
167+
156168 return clone;
157169 }
158170}
0 commit comments