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
32 33 34 35 36 37 38 |
# File 'lib/log_struct/integrations/action_mailer/metadata_collection.rb', line 32 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.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/log_struct/integrations/action_mailer/metadata_collection.rb', line 56 def self.(log_data) # Get current tags from ActiveSupport::TaggedLogging if available if ::ActiveSupport::TaggedLogging.respond_to?(:current_tags) = T.unsafe(::ActiveSupport::TaggedLogging). log_data[:tags] = if .present? end # 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 22 23 24 25 26 27 28 |
# File 'lib/log_struct/integrations/action_mailer/metadata_collection.rb', line 12 def self.(mailer, log_data) = mailer.respond_to?(:message) ? mailer. : nil # Add recipient count if message is available if # Don't log actual email addresses log_data[:recipient_count] = [.to, .cc, .bcc].flatten.compact.count # Handle case when attachments might be nil log_data[:has_attachments] = .&.any? || false log_data[:attachment_count] = .&.count || 0 else log_data[:recipient_count] = 0 log_data[:has_attachments] = false log_data[:attachment_count] = 0 end end |
.extract_ids_to_log_data(mailer, log_data) ⇒ void
This method returns an undefined value.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/log_struct/integrations/action_mailer/metadata_collection.rb', line 41 def self.extract_ids_to_log_data(mailer, log_data) # Extract account ID if available if mailer.instance_variable_defined?(:@account) account = mailer.instance_variable_get(:@account) log_data[:account_id] = account.id if account.respond_to?(:id) end # Extract user ID if available return unless mailer.instance_variable_defined?(:@user) user = mailer.instance_variable_get(:@user) log_data[:user_id] = user.id if user.respond_to?(:id) end |