Skip to content

Commit cd75428

Browse files
Document EnrichmentLogProcessor more comprehensively #3266 (comment)
1 parent 00c0897 commit cd75428

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

examples/logs-advanced/src/main.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,29 @@ fn main() {
5757
let _ = provider.shutdown();
5858
}
5959

60+
/// A log processor that enriches log records with additional attributes before
61+
/// delegating to an underlying processor.
62+
///
63+
/// If this were implemented as a standalone processor in a chain (e.g.,
64+
/// EnrichmentProcessor -> SimpleLogProcessor), the performance benefits of the
65+
/// `event_enabled` check would be nullified. Here's why:
66+
///
67+
/// - The `event_enabled` method is crucial for performance - it allows processors
68+
/// to skip expensive operations for logs that will ultimately be filtered out
69+
/// - A standalone EnrichmentProcessor would need to implement `event_enabled`,
70+
/// but it has no knowledge of downstream filtering logic
71+
/// - It would have to return `true` by default, causing unnecessary enrichment
72+
/// work even for logs that the downstream processor will discard
73+
///
74+
/// Because this processor wraps another, it must delegate all trait methods
75+
/// to the underlying processor, including:
76+
/// - `shutdown_with_timeout` / `shutdown`
77+
/// - `set_resource`
78+
/// - `force_flush`
79+
/// - `event_enabled`
80+
///
81+
/// This ensures the underlying processor receives all necessary lifecycle events
82+
/// and configuration updates.
6083
#[derive(Debug)]
6184
pub struct EnrichmentLogProcessor<P: LogProcessor> {
6285
/// The wrapped processor that will receive enriched log records
@@ -93,11 +116,6 @@ impl<P: LogProcessor> LogProcessor for EnrichmentLogProcessor<P> {
93116

94117
#[cfg(feature = "spec_unstable_logs_enabled")]
95118
fn event_enabled(&self, level: Severity, target: &str, name: Option<&str>) -> bool {
96-
// It is important to call the delegate's event_enabled method to ensure that
97-
// any filtering or logic implemented by downstream processors is respected so
98-
// that no unnecessary work is done, causing an unwanted performance issue.
99-
// Skipping this call could result in logs being emitted that should have been filtered out
100-
// or in bypassing other custom logic in the processor chain.
101119
self.delegate.event_enabled(level, target, name)
102120
}
103121
}

0 commit comments

Comments
 (0)