@@ -6,7 +6,7 @@ use opentelemetry_sdk::Resource;
66use tracing:: { info, error} ;
77use tracing_subscriber:: { prelude:: * , EnvFilter } ;
88use opentelemetry:: InstrumentationScope ;
9- use opentelemetry:: logs:: Severity ;
9+ use opentelemetry:: logs:: { Severity , LogRecord } ;
1010use opentelemetry_sdk:: error:: OTelSdkResult ;
1111
1212fn main ( ) {
@@ -90,7 +90,6 @@ impl<P: LogProcessor> LogProcessor for FilteringLogProcessor<P> {
9090
9191 #[ cfg( feature = "spec_unstable_logs_enabled" ) ]
9292 fn event_enabled ( & self , level : Severity , target : & str , name : Option < & str > ) -> bool {
93- println ! ( "filtering: severity is {level:?}" ) ;
9493 self . delegate . event_enabled ( level, target, name) && level >= self . min_severity
9594 }
9695}
@@ -111,8 +110,12 @@ impl<P: LogProcessor> SlowEnrichmentLogProcessor<P> {
111110
112111impl < P : LogProcessor > LogProcessor for SlowEnrichmentLogProcessor < P > {
113112 fn emit ( & self , data : & mut SdkLogRecord , instrumentation : & InstrumentationScope ) {
114- println ! ( "slow enrichment log processor is waiting 1 s" ) ;
113+ // Simulate an expensive enrichment step (e.g., fetching from a DB or service)
115114 sleep ( Duration :: from_secs ( 1 ) ) ;
115+ // Enrich the log record with a custom attribute using the public API
116+ data. add_attribute ( "enriched" , true ) ;
117+ // You could also add more context, e.g., thread id, timestamp, etc.
118+ // data.add_attribute("thread_id", format!("{:?}", std::thread::current().id()));
116119 self . delegate . emit ( data, instrumentation) ;
117120 }
118121
@@ -122,7 +125,10 @@ impl<P: LogProcessor> LogProcessor for SlowEnrichmentLogProcessor<P> {
122125
123126 #[ cfg( feature = "spec_unstable_logs_enabled" ) ]
124127 fn event_enabled ( & self , level : Severity , target : & str , name : Option < & str > ) -> bool {
125- println ! ( "slow enrichment: severity is {level:?}" ) ;
128+ // It is important to call the delegate's event_enabled method to ensure that
129+ // any filtering or logic implemented by downstream processors is respected.
130+ // Skipping this call could result in logs being emitted that should have been filtered out
131+ // or in bypassing other custom logic in the processor chain.
126132 self . delegate . event_enabled ( level, target, name)
127133 }
128134}
0 commit comments