# frozen_string_literal: true module BusinessFlow # Include me to fire ActiveSupport notifications on the flow, every step, # and for any errors that happen. module Instrument def self.included(klass) klass.extend(ClassMethods) klass.step_executor ::BusinessFlow::InstrumentedExecutor end # Contains methods that we add to the DSL module ClassMethods INSTRUMENTATION_PREFIX = 'business_flow'.freeze def instrument(name, flow) payload = { flow: flow } ActiveSupport::Notifications.instrument( "#{INSTRUMENTATION_PREFIX}.#{name}.#{instrumentation_name}", payload ) do yield payload end end def instrument_steps step_executor ::BusinessFlow::InstrumentedStepExecutor end def instrumentation_name @instrumentation_name ||= to_s.underscore.freeze end def event_name @event_name ||= "#{INSTRUMENTATION_PREFIX}.flow.#{instrumentation_name}".freeze end end end end