Class: ActiveRecord::ConnectionAdapters::TransactionInstrumenter

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/abstract/transaction.rb

Defined Under Namespace

Classes: InstrumentationAlreadyStartedError, InstrumentationNotStartedError

Instance Method Summary collapse

Constructor Details

#initialize(payload = {}) ⇒ TransactionInstrumenter

Returns a new instance of TransactionInstrumenter.



80
81
82
83
84
85
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 80

def initialize(payload = {})
  @handle = nil
  @started = false
  @payload = nil
  @base_payload = payload
end

Instance Method Details

#finish(outcome) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 101

def finish(outcome)
  raise InstrumentationNotStartedError.new("Called finish on a transaction that hasn't started") unless @started
  @started = false

  @payload[:outcome] = outcome
  @handle.finish
end

#startObject



90
91
92
93
94
95
96
97
98
99
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 90

def start
  raise InstrumentationAlreadyStartedError.new("Called start on an already started transaction") if @started
  @started = true

  ActiveSupport::Notifications.instrument("start_transaction.active_record", @base_payload)

  @payload = @base_payload.dup # We dup because the payload for a given event is mutated later to add the outcome.
  @handle = ActiveSupport::Notifications.instrumenter.build_handle("transaction.active_record", @payload)
  @handle.start
end