Module: Easyop::Plugins::Recording

Defined in:
lib/easyop/plugins/recording.rb

Overview

Records operation executions to a database model.

Usage:

class ApplicationOperation
  include Easyop::Operation
  plugin Easyop::Plugins::Recording, model: OperationLog
end

Required model columns (create with the generator migration):

operation_name  :string,   null: false
success         :boolean,  null: false
error_message   :string
params_data     :text               # stored as JSON
duration_ms     :float
performed_at    :datetime, null: false

Optional flow-tracing columns:

root_reference_id     :string   # shared across entire execution tree
reference_id          :string   # unique to this operation execution
parent_operation_name :string   # class name of the direct parent
parent_reference_id   :string   # reference_id of the direct parent

Optional result column:

result_data           :text     # stored as JSON — selected ctx keys after call

Optional execution order column:

execution_index       :integer  # nil for root; 1-based within each parent

Opt out per operation class:

class MyOp < ApplicationOperation
  recording false
end

Options:

model:         (required) ActiveRecord class
record_params: true       pass false to skip params serialization; also accepts
                          Hash ({ attrs: :key }), Proc, or Symbol (method name)
record_result: false      configure result capture at plugin level; also accepts
                          true (full ctx snapshot), Hash, Proc, or Symbol
filter_keys:   []         additional keys/patterns to filter from params_data
                          (Symbol, String, or Regexp — additive with FILTERED_KEYS)
                          Filtered keys are kept in params_data but their value
                          is replaced with "[FILTERED]".

Defined Under Namespace

Modules: ClassMethods, RunWrapper

Constant Summary collapse

FILTERED_KEYS =

Sensitive keys always filtered in params_data before persisting. Their values are replaced with “[FILTERED]” rather than removed.

%i[password password_confirmation token secret api_key].freeze
INTERNAL_CTX_KEYS =

Internal ctx keys used for flow tracing — excluded from params_data.

%i[
  __recording_root_reference_id
  __recording_parent_operation_name
  __recording_parent_reference_id
  __recording_child_counts
].freeze

Class Method Summary collapse

Class Method Details

.install(base, model:, record_params: true, record_result: false, filter_keys: [], **_options) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/easyop/plugins/recording.rb', line 63

def self.install(base, model:, record_params: true, record_result: false, filter_keys: [], **_options)
  base.extend(ClassMethods)
  base.prepend(RunWrapper)
  base.instance_variable_set(:@_recording_model,          model)
  base.instance_variable_set(:@_recording_record_params,  record_params)
  base.instance_variable_set(:@_recording_record_result,  record_result)
  base.instance_variable_set(:@_recording_filter_keys,    Array(filter_keys))
end