Class: Julewire::Rails::StructuredEventRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/julewire/rails/structured_event_record.rb

Constant Summary collapse

DEBUG_EVENT_PREFIXES =
%w[
  action_view.
  active_record.
].freeze
DEBUG_EVENTS =
%w[
  action_controller.unpermitted_parameters
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(configuration, parameter_filter: Core::UNSET) ⇒ StructuredEventRecord

Returns a new instance of StructuredEventRecord.



17
18
19
20
# File 'lib/julewire/rails/structured_event_record.rb', line 17

def initialize(configuration, parameter_filter: Core::UNSET)
  @configuration = configuration
  @parameter_filter_override = parameter_filter
end

Instance Method Details

#call(event, name:, payload:) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/julewire/rails/structured_event_record.rb', line 22

def call(event, name:, payload:)
  values = Core::Integration::Values::Shape
  {
    timestamp: values.timestamp(event[:timestamp]),
    severity: severity_for(name),
    event: name,
    logger: "Rails.event",
    source: @configuration.source,
    context: values.hash_or_empty(event[:context]),
    attributes: attributes_for(event, payload),
    neutral: neutral_for(event)
  }.compact
end

#payload_hash(payload) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/julewire/rails/structured_event_record.rb', line 36

def payload_hash(payload)
  case payload
  when nil
    {}
  when Hash
    values = Core::Integration::Values::Shape
    values.payload_hash(payload)
  else
    serialize_payload_object(payload)
  end
end