Module: LogStruct::Integrations::ActionMailer::MetadataCollection
- Extended by:
- T::Sig
- Defined in:
- lib/log_struct/integrations/action_mailer/metadata_collection.rb
Overview
Handles collection of metadata for email logging
Class Method Summary collapse
-
.add_context_metadata(mailer, log_data) ⇒ void
Add context metadata to log data.
- .add_current_tags_to_log_data(log_data) ⇒ void
-
.add_message_metadata(mailer, log_data) ⇒ void
Add message-specific metadata to log data.
- .extract_ids_to_log_data(mailer, log_data) ⇒ void
Class Method Details
.add_context_metadata(mailer, log_data) ⇒ void
This method returns an undefined value.
Add context metadata to log data
25 26 27 28 29 30 31 |
# File 'lib/log_struct/integrations/action_mailer/metadata_collection.rb', line 25 def self.(mailer, log_data) # Add account ID information if available (but not user email) extract_ids_to_log_data(mailer, log_data) # Add any current tags from ActiveJob or ActionMailer (log_data) end |
.add_current_tags_to_log_data(log_data) ⇒ void
This method returns an undefined value.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/log_struct/integrations/action_mailer/metadata_collection.rb', line 48 def self.(log_data) # Get current tags from thread-local storage or ActiveSupport::TaggedLogging = if ::ActiveSupport::TaggedLogging.respond_to?(:current_tags) T.unsafe(::ActiveSupport::TaggedLogging). else Thread.current[:activesupport_tagged_logging_tags] || [] end log_data[:tags] = if .present? # Get request_id from ActionDispatch if available if ::ActionDispatch::Request.respond_to?(:current_request_id) && T.unsafe(::ActionDispatch::Request).current_request_id.present? log_data[:request_id] = T.unsafe(::ActionDispatch::Request).current_request_id end # Get job_id from ActiveJob if available if defined?(::ActiveJob::Logging) && ::ActiveJob::Logging.respond_to?(:job_id) && T.unsafe(::ActiveJob::Logging).job_id.present? log_data[:job_id] = T.unsafe(::ActiveJob::Logging).job_id end end |
.add_message_metadata(mailer, log_data) ⇒ void
This method returns an undefined value.
Add message-specific metadata to log data
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/log_struct/integrations/action_mailer/metadata_collection.rb', line 12 def self.(mailer, log_data) = mailer.respond_to?(:message) ? mailer. : nil # Add attachment count if message is available log_data[:attachment_count] = if .&.count || 0 else 0 end end |
.extract_ids_to_log_data(mailer, log_data) ⇒ void
This method returns an undefined value.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/log_struct/integrations/action_mailer/metadata_collection.rb', line 34 def self.extract_ids_to_log_data(mailer, log_data) # Use configured ID mapping from LogStruct configuration id_mapping = LogStruct.config.integrations.actionmailer_id_mapping id_mapping.each do |ivar_name, log_key| ivar = :"@#{ivar_name}" next unless mailer.instance_variable_defined?(ivar) obj = mailer.instance_variable_get(ivar) log_data[log_key] = obj.id if obj.respond_to?(:id) end end |