@@ -3,6 +3,7 @@ use std::cell::RefCell;
3
3
use std:: collections:: BTreeMap ;
4
4
use std:: sync:: Arc ;
5
5
6
+ use bitflags:: bitflags;
6
7
use sentry_core:: protocol:: Value ;
7
8
use sentry_core:: { Breadcrumb , TransactionOrSpan } ;
8
9
use tracing_core:: field:: Visit ;
@@ -13,21 +14,22 @@ use tracing_subscriber::registry::LookupSpan;
13
14
use crate :: converters:: * ;
14
15
use crate :: TAGS_PREFIX ;
15
16
16
- /// The action that Sentry should perform for a given [`Event`]
17
- #[ derive( Debug , Clone , Copy ) ]
18
- pub enum EventFilter {
19
- /// Ignore the [`Event`]
20
- Ignore ,
21
- /// Create a [`Breadcrumb`] from this [`Event`]
22
- Breadcrumb ,
23
- /// Create a [`sentry_core::protocol::Event`] from this [`Event`]
24
- Event ,
25
- /// Create a [`sentry_core::protocol::Log`] from this [`Event`]
26
- #[ cfg( feature = "logs" ) ]
27
- Log ,
17
+ bitflags ! {
18
+ /// The action that Sentry should perform for a given [`Event`]
19
+ #[ derive( Debug , Clone , Copy ) ]
20
+ pub struct EventFilter : u32 {
21
+ /// Ignore the [`Event`]
22
+ const Ignore = 0b000 ;
23
+ /// Create a [`Breadcrumb`] from this [`Event`]
24
+ const Breadcrumb = 0b001 ;
25
+ /// Create a [`sentry_core::protocol::Event`] from this [`Event`]
26
+ const Event = 0b010 ;
27
+ /// Create a [`sentry_core::protocol::Log`] from this [`Event`]
28
+ const Log = 0b100 ;
29
+ }
28
30
}
29
31
30
- /// The type of data Sentry should ingest for a [`Event`]
32
+ /// The type of data Sentry should ingest for an [`Event`].
31
33
#[ derive( Debug ) ]
32
34
#[ allow( clippy:: large_enum_variant) ]
33
35
pub enum EventMapping {
@@ -40,6 +42,27 @@ pub enum EventMapping {
40
42
/// Captures the [`sentry_core::protocol::Log`] to Sentry.
41
43
#[ cfg( feature = "logs" ) ]
42
44
Log ( sentry_core:: protocol:: Log ) ,
45
+ /// Captures multiple items to Sentry.
46
+ Combined ( CombinedEventMapping ) ,
47
+ }
48
+
49
+ /// A list of event mappings.
50
+ #[ derive( Debug ) ]
51
+ pub struct CombinedEventMapping ( Vec < EventMapping > ) ;
52
+
53
+ impl From < EventMapping > for CombinedEventMapping {
54
+ fn from ( value : EventMapping ) -> Self {
55
+ match value {
56
+ EventMapping :: Combined ( combined) => combined,
57
+ _ => CombinedEventMapping ( vec ! [ value] ) ,
58
+ }
59
+ }
60
+ }
61
+
62
+ impl From < Vec < EventMapping > > for CombinedEventMapping {
63
+ fn from ( value : Vec < EventMapping > ) -> Self {
64
+ Self ( value)
65
+ }
43
66
}
44
67
45
68
/// The default event filter.
@@ -211,30 +234,44 @@ where
211
234
S : Subscriber + for < ' a > LookupSpan < ' a > ,
212
235
{
213
236
fn on_event ( & self , event : & Event , ctx : Context < ' _ , S > ) {
214
- let item = match & self . event_mapper {
237
+ let items = match & self . event_mapper {
215
238
Some ( mapper) => mapper ( event, ctx) ,
216
239
None => {
217
240
let span_ctx = self . with_span_attributes . then_some ( ctx) ;
218
- match ( self . event_filter ) ( event. metadata ( ) ) {
219
- EventFilter :: Ignore => EventMapping :: Ignore ,
220
- EventFilter :: Breadcrumb => {
221
- EventMapping :: Breadcrumb ( breadcrumb_from_event ( event, span_ctx) )
222
- }
223
- EventFilter :: Event => EventMapping :: Event ( event_from_event ( event, span_ctx) ) ,
224
- #[ cfg( feature = "logs" ) ]
225
- EventFilter :: Log => EventMapping :: Log ( log_from_event ( event, span_ctx) ) ,
241
+ let filter = ( self . event_filter ) ( event. metadata ( ) ) ;
242
+ let mut items = vec ! [ ] ;
243
+ if filter. contains ( EventFilter :: Breadcrumb ) {
244
+ items. push ( EventMapping :: Breadcrumb ( breadcrumb_from_event (
245
+ event,
246
+ span_ctx. as_ref ( ) ,
247
+ ) ) ) ;
226
248
}
249
+ if filter. contains ( EventFilter :: Event ) {
250
+ items. push ( EventMapping :: Event ( event_from_event (
251
+ event,
252
+ span_ctx. as_ref ( ) ,
253
+ ) ) ) ;
254
+ }
255
+ #[ cfg( feature = "logs" ) ]
256
+ if filter. contains ( EventFilter :: Log ) {
257
+ items. push ( EventMapping :: Log ( log_from_event ( event, span_ctx. as_ref ( ) ) ) ) ;
258
+ }
259
+ EventMapping :: Combined ( CombinedEventMapping ( items) )
227
260
}
228
261
} ;
229
-
230
- match item {
231
- EventMapping :: Event ( event) => {
232
- sentry_core:: capture_event ( event) ;
262
+ let items = CombinedEventMapping :: from ( items) ;
263
+
264
+ for item in items. 0 {
265
+ match item {
266
+ EventMapping :: Ignore => ( ) ,
267
+ EventMapping :: Breadcrumb ( breadcrumb) => sentry_core:: add_breadcrumb ( breadcrumb) ,
268
+ EventMapping :: Event ( event) => {
269
+ sentry_core:: capture_event ( event) ;
270
+ }
271
+ #[ cfg( feature = "logs" ) ]
272
+ EventMapping :: Log ( log) => sentry_core:: Hub :: with_active ( |hub| hub. capture_log ( log) ) ,
273
+ _ => ( ) ,
233
274
}
234
- EventMapping :: Breadcrumb ( breadcrumb) => sentry_core:: add_breadcrumb ( breadcrumb) ,
235
- #[ cfg( feature = "logs" ) ]
236
- EventMapping :: Log ( log) => sentry_core:: Hub :: with_active ( |hub| hub. capture_log ( log) ) ,
237
- _ => ( ) ,
238
275
}
239
276
}
240
277
0 commit comments