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.



92
93
94
# File 'lib/elastic_apm/transaction.rb', line 92

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.



92
93
94
# File 'lib/elastic_apm/transaction.rb', line 92

def collect_metrics
  @collect_metrics
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.



92
93
94
# File 'lib/elastic_apm/transaction.rb', line 92

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.



92
93
94
# File 'lib/elastic_apm/transaction.rb', line 92

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.



92
93
94
# File 'lib/elastic_apm/transaction.rb', line 92

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.



92
93
94
# File 'lib/elastic_apm/transaction.rb', line 92

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.



92
93
94
# File 'lib/elastic_apm/transaction.rb', line 92

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 (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.



92
93
94
# File 'lib/elastic_apm/transaction.rb', line 92

def sample_rate
  @sample_rate
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.



92
93
94
# File 'lib/elastic_apm/transaction.rb', line 92

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.



92
93
94
# File 'lib/elastic_apm/transaction.rb', line 92

def span_frames_min_duration
  @span_frames_min_duration
end

#started_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.



92
93
94
# File 'lib/elastic_apm/transaction.rb', line 92

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.



92
93
94
# File 'lib/elastic_apm/transaction.rb', line 92

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.



92
93
94
# File 'lib/elastic_apm/transaction.rb', line 92

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.



92
93
94
# File 'lib/elastic_apm/transaction.rb', line 92

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



156
157
158
# File 'lib/elastic_apm/transaction.rb', line 156

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.



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

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



143
144
145
146
147
148
149
150
151
152
# File 'lib/elastic_apm/transaction.rb', line 143

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.



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

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)


111
112
113
# File 'lib/elastic_apm/transaction.rb', line 111

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.



160
161
162
# File 'lib/elastic_apm/transaction.rb', line 160

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



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

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.



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

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)


115
116
117
# File 'lib/elastic_apm/transaction.rb', line 115

def stopped?
  !!duration
end