Module: TypedOperation::Instrumentation::Traceable

Defined in:
lib/typed_operation/instrumentation.rb

Overview

Module to be prepended to operation classes to enable tracing. This is automatically included when using ‘explain`.

Instance Method Summary collapse

Instance Method Details

#execute_operationObject

: () -> untyped



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/typed_operation/instrumentation.rb', line 142

def execute_operation
  return super unless Instrumentation.tracing?

  trace = Trace.new(
    operation_class: self.class,
    params: extract_params_for_trace
  )

  # Apply chain context if available
  if (chain_ctx = Instrumentation.take_chain_context)
    trace.pass_mode = chain_ctx[:pass_mode]
    trace.extracted_params = chain_ctx[:extracted_params]
    trace.fallback_used = chain_ctx[:fallback_used]
  end

  Instrumentation.push_trace(trace)

  result = nil
  exception = nil
  begin
    result = super
  rescue => e
    exception = e
  end

  trace.finish!(result: result, exception: exception)
  Instrumentation.pop_trace

  raise exception if exception
  result
end