From 2d4f3792f9488fc7c7d68c39b19f34916a24e28a Mon Sep 17 00:00:00 2001 From: Daijiro Fukuda Date: Wed, 11 Sep 2024 15:41:01 +0900 Subject: [PATCH] log: add caller plugin-id about emitting error events It would be helpful if we could know what plugin emitted the error event. https://github.com/fluent/fluentd/issues/4567 We need to care about the compatibility. This signature change would not break compatibility. However, I'm concerned that `caller_plugin_id` has a race condition, although I don't confirm it. It looks to me that the id can be another plugin-id running concurrently... It is not the issue with this fix, it is the issue of the existing implementation. Signed-off-by: Daijiro Fukuda --- lib/fluent/agent.rb | 2 +- lib/fluent/event_router.rb | 2 +- lib/fluent/label.rb | 4 ++-- lib/fluent/root_agent.rb | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/fluent/agent.rb b/lib/fluent/agent.rb index 7e662704b1..33b081c3ef 100644 --- a/lib/fluent/agent.rb +++ b/lib/fluent/agent.rb @@ -159,7 +159,7 @@ def add_filter(type, pattern, conf) end # For handling invalid record - def emit_error_event(tag, time, record, error) + def emit_error_event(tag, time, record, error, plugin_id: nil) end def handle_emits_error(tag, es, error) diff --git a/lib/fluent/event_router.rb b/lib/fluent/event_router.rb index 9a133b5c6b..7961b2963c 100644 --- a/lib/fluent/event_router.rb +++ b/lib/fluent/event_router.rb @@ -123,7 +123,7 @@ def emit_stream(tag, es) end def emit_error_event(tag, time, record, error) - @emit_error_handler.emit_error_event(tag, time, record, error) + @emit_error_handler.emit_error_event(tag, time, record, error, plugin_id: @caller_plugin_id) end def match?(tag) diff --git a/lib/fluent/label.rb b/lib/fluent/label.rb index 674492efec..1899455fbb 100644 --- a/lib/fluent/label.rb +++ b/lib/fluent/label.rb @@ -35,8 +35,8 @@ def configure(conf) end end - def emit_error_event(tag, time, record, e) - @root_agent.emit_error_event(tag, time, record, e) + def emit_error_event(tag, time, record, e, plugin_id: nil) + @root_agent.emit_error_event(tag, time, record, e, plugin_id: plugin_id) end def handle_emits_error(tag, es, e) diff --git a/lib/fluent/root_agent.rb b/lib/fluent/root_agent.rb index d10f366044..383830dace 100644 --- a/lib/fluent/root_agent.rb +++ b/lib/fluent/root_agent.rb @@ -341,8 +341,9 @@ def find_label(label_name) end end - def emit_error_event(tag, time, record, error) + def emit_error_event(tag, time, record, error, plugin_id: nil) error_info = {error: error, location: (error.backtrace ? error.backtrace.first : nil), tag: tag, time: time} + error_info[:plugin_id] = plugin_id if plugin_id if @error_collector # A record is not included in the logs because <@ERROR> handles it. This warn is for the notification log.warn "send an error event to @ERROR:", error_info