class ElasticAPM::Transaction
@api private
def add_response(status = nil, **args)
def add_response(status = nil, **args) context.response = Context::Response.new(status, **args) end
def done(result = nil, clock_end: Util.monotonic_micros)
def done(result = nil, clock_end: Util.monotonic_micros) stop clock_end self.result = result if result self end
def inc_started_spans!
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
def initialize(
def initialize( name = nil, type = nil, config:, sampled: true, sample_rate: 1, context: nil, 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
def inspect
def inspect "<ElasticAPM::Transaction id:#{id}" \ " name:#{name.inspect} type:#{type.inspect}>" end
def sampled?
def sampled? @sampled end
def set_user(user)
def set_user(user) context.user = Context::User.infer(@config, user) end
def start(clock_start = Util.monotonic_micros)
def start(clock_start = Util.monotonic_micros) @timestamp = Util.micros @clock_start = clock_start self end
def stop(clock_end = Util.monotonic_micros)
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
def stopped?
def stopped? !!duration end