class Atatus::Transaction
@api private
Constants
- DEFAULT_TYPE
- MUTEX
Attributes
breakdown_metrics[R]
collect_metrics[R]
collect_metrics?[R]
context[R]
dropped_spans[R]
duration[R]
framework_name[R]
name[RW]
rubocop:enable Metrics/ParameterLists
notifications[R]
result[RW]
rubocop:enable Metrics/ParameterLists
ruby_time[RW]
rubocop:enable Metrics/ParameterLists
sample_rate[R]
self_time[R]
span_frames_min_duration[R]
spans[RW]
rubocop:enable Metrics/ParameterLists
started_spans[R]
timestamp[R]
trace_context[R]
transaction_max_spans[R]
type[RW]
rubocop:enable Metrics/ParameterLists
Public Class Methods
new( name = nil, type = nil, sampled: true, sample_rate: 1, context: nil, config:, trace_context: nil )
click to toggle source
rubocop:disable Metrics/ParameterLists
# File lib/atatus/transaction.rb, line 33 def initialize( name = nil, type = nil, sampled: true, sample_rate: 1, context: nil, config:, trace_context: nil ) @name = name @type = type || DEFAULT_TYPE @config = config # Cache these values in case they are changed during the # transaction's lifetime via the remote config @span_frames_min_duration = config.span_frames_min_duration @collect_metrics = config.collect_metrics? @breakdown_metrics = config.breakdown_metrics? @framework_name = config.framework_name @transaction_max_spans = config.transaction_max_spans @default_labels = config.default_labels @sampled = sampled @sample_rate = sample_rate @context = context || Context.new # TODO: Lazy generate this? if @default_labels Util.reverse_merge!(@context.labels, @default_labels) end unless (@trace_context = trace_context) @trace_context = TraceContext.new( traceparent: TraceContext::Traceparent.new(recorded: sampled), tracestate: TraceContext::Tracestate.new(sample_rate: sampled ? sample_rate : 0) ) end @started_spans = 0 @dropped_spans = 0 @notifications = [] # for AS::Notifications end
Public Instance Methods
add_response(status = nil, **args)
click to toggle source
context
# File lib/atatus/transaction.rb, line 143 def add_response(status = nil, **args) context.response = Context::Response.new(status, **args) end
done(result = nil, clock_end: Util.monotonic_micros)
click to toggle source
# File lib/atatus/transaction.rb, line 122 def done(result = nil, clock_end: Util.monotonic_micros) stop clock_end self.result = result if result self end
inc_started_spans!()
click to toggle source
spans
# File lib/atatus/transaction.rb, line 130 def inc_started_spans! MUTEX.synchronize do @started_spans += 1 if @started_spans > transaction_max_spans @dropped_spans += 1 return false end end true end
inspect()
click to toggle source
# File lib/atatus/transaction.rb, line 151 def inspect "<Atatus::Transaction id:#{id}" \ " name:#{name.inspect} type:#{type.inspect}>" end
sampled?()
click to toggle source
# File lib/atatus/transaction.rb, line 98 def sampled? @sampled end
set_user(user)
click to toggle source
# File lib/atatus/transaction.rb, line 147 def set_user(user) context.user = Context::User.infer(@config, user) end
start(clock_start = Util.monotonic_micros)
click to toggle source
life cycle
# File lib/atatus/transaction.rb, line 108 def start(clock_start = Util.monotonic_micros) @timestamp = Util.micros @clock_start = clock_start self end
stop(clock_end = Util.monotonic_micros)
click to toggle source
# File lib/atatus/transaction.rb, line 114 def stop(clock_end = Util.monotonic_micros) raise 'Transaction not yet start' unless timestamp @duration = clock_end - @clock_start @self_time = @duration - child_durations.duration self end
stopped?()
click to toggle source
# File lib/atatus/transaction.rb, line 102 def stopped? !!duration end