Class: ElasticAPM::Transaction Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
ChildDurations::Methods
Defined in:
lib/elastic_apm/transaction.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: Outcome

Constant Summary collapse

DEFAULT_TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'custom'
MUTEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Mutex.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ChildDurations::Methods

#child_durations, #child_started, #child_stopped

Constructor Details

#initialize(name = nil, type = nil, config:, sampled: true, sample_rate: 1, context: nil, trace_context: nil) ⇒ Transaction

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/ParameterLists



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/elastic_apm/transaction.rb', line 44

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

Instance Attribute Details

#breakdown_metricsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



100
101
102
# File 'lib/elastic_apm/transaction.rb', line 100

def breakdown_metrics
  @breakdown_metrics
end

#collect_metricsObject (readonly) Also known as: collect_metrics?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



100
101
102
# File 'lib/elastic_apm/transaction.rb', line 100

def collect_metrics
  @collect_metrics
end

#configObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



100
101
102
# File 'lib/elastic_apm/transaction.rb', line 100

def config
  @config
end

#contextObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



100
101
102
# File 'lib/elastic_apm/transaction.rb', line 100

def context
  @context
end

#dropped_spansObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



100
101
102
# File 'lib/elastic_apm/transaction.rb', line 100

def dropped_spans
  @dropped_spans
end

#durationObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



100
101
102
# File 'lib/elastic_apm/transaction.rb', line 100

def duration
  @duration
end

#framework_nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



100
101
102
# File 'lib/elastic_apm/transaction.rb', line 100

def framework_name
  @framework_name
end

#nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:enable Metrics/ParameterLists



90
91
92
# File 'lib/elastic_apm/transaction.rb', line 90

def name
  @name
end

#notificationsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



100
101
102
# File 'lib/elastic_apm/transaction.rb', line 100

def notifications
  @notifications
end

#outcomeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:enable Metrics/ParameterLists



90
91
92
# File 'lib/elastic_apm/transaction.rb', line 90

def outcome
  @outcome
end

#resultObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:enable Metrics/ParameterLists



90
91
92
# File 'lib/elastic_apm/transaction.rb', line 90

def result
  @result
end

#sample_rateObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:enable Metrics/ParameterLists



90
91
92
# File 'lib/elastic_apm/transaction.rb', line 90

def sample_rate
  @sample_rate
end

#sampledObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:enable Metrics/ParameterLists



90
91
92
# File 'lib/elastic_apm/transaction.rb', line 90

def sampled
  @sampled
end

#self_timeObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



100
101
102
# File 'lib/elastic_apm/transaction.rb', line 100

def self_time
  @self_time
end

#span_frames_min_durationObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



100
101
102
# File 'lib/elastic_apm/transaction.rb', line 100

def span_frames_min_duration
  @span_frames_min_duration
end

#started_spansObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:enable Metrics/ParameterLists



90
91
92
# File 'lib/elastic_apm/transaction.rb', line 90

def started_spans
  @started_spans
end

#timestampObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



100
101
102
# File 'lib/elastic_apm/transaction.rb', line 100

def timestamp
  @timestamp
end

#trace_contextObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



100
101
102
# File 'lib/elastic_apm/transaction.rb', line 100

def trace_context
  @trace_context
end

#transaction_max_spansObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



100
101
102
# File 'lib/elastic_apm/transaction.rb', line 100

def transaction_max_spans
  @transaction_max_spans
end

#typeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:enable Metrics/ParameterLists



90
91
92
# File 'lib/elastic_apm/transaction.rb', line 90

def type
  @type
end

Instance Method Details

#add_response(status = nil, **args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

context



163
164
165
# File 'lib/elastic_apm/transaction.rb', line 163

def add_response(status = nil, **args)
  context.response = Context::Response.new(status, **args)
end

#done(result = nil, clock_end: Util.monotonic_micros) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



142
143
144
145
146
# File 'lib/elastic_apm/transaction.rb', line 142

def done(result = nil, clock_end: Util.monotonic_micros)
  stop clock_end
  self.result = result if result
  self
end

#inc_started_spans!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

spans



150
151
152
153
154
155
156
157
158
159
# File 'lib/elastic_apm/transaction.rb', line 150

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

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



171
172
173
174
# File 'lib/elastic_apm/transaction.rb', line 171

def inspect
  "<ElasticAPM::Transaction id:#{id}" \
    " name:#{name.inspect} type:#{type.inspect}>"
end

#sampled?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


118
119
120
# File 'lib/elastic_apm/transaction.rb', line 118

def sampled?
  @sampled
end

#set_user(user) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



167
168
169
# File 'lib/elastic_apm/transaction.rb', line 167

def set_user(user)
  context.user = Context::User.infer(@config, user)
end

#start(clock_start = Util.monotonic_micros) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

life cycle



128
129
130
131
132
# File 'lib/elastic_apm/transaction.rb', line 128

def start(clock_start = Util.monotonic_micros)
  @timestamp = Util.micros
  @clock_start = clock_start
  self
end

#stop(clock_end = Util.monotonic_micros) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



134
135
136
137
138
139
140
# File 'lib/elastic_apm/transaction.rb', line 134

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?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


122
123
124
# File 'lib/elastic_apm/transaction.rb', line 122

def stopped?
  !!duration
end