class HeimdallApm::TrackedTransaction
A TrackedTransaction
is a collection of segments.
Constants
- JOB_MODE
- VISITORS
- WEB_MODE
Attributes
annotations[R]
Miscellaneous annotations made to the transaction. Must be a Hash.
recorder[R]
Recorder
used to process transaction data
root_segment[R]
First segment added to the transaction
scope[RW]
Scope of this transaction (controller routes / job id)
Public Class Methods
new(context)
click to toggle source
# File lib/heimdall_apm/tracked_transaction.rb, line 24 def initialize(context) @context = context @root_segment = nil @segments = [] @scope = nil @stopped = false @mode = nil @annotations = {} @recorder = context.recorder @vault = context.vault end
Public Instance Methods
annotate(hsh)
click to toggle source
# File lib/heimdall_apm/tracked_transaction.rb, line 91 def annotate(hsh) @annotations.merge!(hsh) end
current_segment()
click to toggle source
Grab the currently running segment. Will be `nil` for a finalized transaction
# File lib/heimdall_apm/tracked_transaction.rb, line 66 def current_segment @segments[-1] end
custom_series_name()
click to toggle source
Allows InfluxDB's series name to be customize via annotations
# File lib/heimdall_apm/tracked_transaction.rb, line 96 def custom_series_name annotations[:series_name] end
job?()
click to toggle source
# File lib/heimdall_apm/tracked_transaction.rb, line 108 def job? @mode == JOB_MODE end
record()
click to toggle source
# File lib/heimdall_apm/tracked_transaction.rb, line 74 def record # TODO: investigate on why mode can be nil sometimes return unless root_segment && @mode # TODO: doesn't feel like it should be done here return if annotations[:uri] && @context.ignored_uris.match?(annotations[:uri]) VISITORS.each do |_, klass| visitor = klass.new(@vault, self) root_segment.accept(visitor) visitor.store_in_vault end end
start_segment(segment)
click to toggle source
# File lib/heimdall_apm/tracked_transaction.rb, line 37 def start_segment(segment) @root_segment = segment unless @root_segment @segments.push(segment) # TODO: maybe use a visitor to check that at the end of the request intead @mode ||= case segment.type when 'Controller' then WEB_MODE when 'Job' then JOB_MODE else nil end segment.start end
stop_segment()
click to toggle source
# File lib/heimdall_apm/tracked_transaction.rb, line 53 def stop_segment segment = @segments.pop segment.record_stop_time if finalized? stop_request else @segments[-1].add_child(segment) end end
stopped?()
click to toggle source
# File lib/heimdall_apm/tracked_transaction.rb, line 87 def stopped? @stopped end
web?()
click to toggle source
# File lib/heimdall_apm/tracked_transaction.rb, line 104 def web? @mode == WEB_MODE end
Private Instance Methods
finalized?()
click to toggle source
Are we finished with this transaction, i.e. no layers are left to be popped out
# File lib/heimdall_apm/tracked_transaction.rb, line 128 def finalized? @segments.empty? end
pretty_print()
click to toggle source
# File lib/heimdall_apm/tracked_transaction.rb, line 114 def pretty_print visitor = HeimdallApm::Visitors::PrettyPrintVisitor.new(@scope) root_segment.accept(visitor) visitor.store_in_vault end
stop_request()
click to toggle source
Send the request off to be stored
# File lib/heimdall_apm/tracked_transaction.rb, line 121 def stop_request @stopped = true recorder.record(self) if recorder end