class ElasticAPM::Transaction

@api private

Constants

DEFAULT_TYPE

Attributes

context[R]
dropped_spans[R]
duration[R]
name[RW]

rubocop:enable Metrics/ParameterLists

notifications[R]
result[RW]

rubocop:enable Metrics/ParameterLists

started_spans[R]
timestamp[R]
trace_context[R]
type[RW]

rubocop:enable Metrics/ParameterLists

Public Class Methods

new( name = nil, type = nil, sampled: true, context: nil, tags: nil, trace_context: nil ) click to toggle source

rubocop:disable Metrics/ParameterLists

# File lib/elastic_apm/transaction.rb, line 18
def initialize(
  name = nil,
  type = nil,
  sampled: true,
  context: nil,
  tags: nil,
  trace_context: nil
)
  @name = name
  @type = type || DEFAULT_TYPE

  @sampled = sampled

  @context = context || Context.new # TODO: Lazy generate this?
  Util.reverse_merge!(@context.tags, tags) if tags

  @trace_context = trace_context || TraceContext.new(recorded: sampled)

  @started_spans = 0
  @dropped_spans = 0

  @notifications = [] # for AS::Notifications
end

Public Instance Methods

add_response(*args) click to toggle source

context

# File lib/elastic_apm/transaction.rb, line 97
def add_response(*args)
  context.response = Context::Response.new(*args)
end
done(result = nil, end_time: Util.micros) click to toggle source
# File lib/elastic_apm/transaction.rb, line 75
def done(result = nil, end_time: Util.micros)
  stop end_time
  self.result = result if result
  self
end
done?() click to toggle source
# File lib/elastic_apm/transaction.rb, line 56
def done?
  stopped?
end
inc_dropped_spans!() click to toggle source
# File lib/elastic_apm/transaction.rb, line 87
def inc_dropped_spans!
  @dropped_spans += 1
end
inc_started_spans!() click to toggle source

spans

# File lib/elastic_apm/transaction.rb, line 83
def inc_started_spans!
  @started_spans += 1
end
inspect() click to toggle source
# File lib/elastic_apm/transaction.rb, line 101
def inspect
  "<ElasticAPM::Transaction id:#{id}" \
    " name:#{name.inspect} type:#{type.inspect}>"
end
max_spans_reached?(config) click to toggle source
# File lib/elastic_apm/transaction.rb, line 91
def max_spans_reached?(config)
  started_spans > config.transaction_max_spans
end
sampled?() click to toggle source
# File lib/elastic_apm/transaction.rb, line 48
def sampled?
  @sampled
end
start(timestamp = Util.micros) click to toggle source

life cycle

# File lib/elastic_apm/transaction.rb, line 64
def start(timestamp = Util.micros)
  @timestamp = timestamp
  self
end
stop(end_timestamp = Util.micros) click to toggle source
# File lib/elastic_apm/transaction.rb, line 69
def stop(end_timestamp = Util.micros)
  raise 'Transaction not yet start' unless timestamp
  @duration = end_timestamp - timestamp
  self
end
stopped?() click to toggle source
# File lib/elastic_apm/transaction.rb, line 52
def stopped?
  !!duration
end