Class: ElasticAPM::Transaction Private

Inherits:
Object
  • Object
show all
Extended by:
Deprecations
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.

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'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Deprecations

deprecate

Constructor Details

#initialize(name = nil, type = nil, sampled: true, context: nil, tags: 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, Metrics/MethodLength



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/elastic_apm/transaction.rb', line 13

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

  if trace_context
    @parent_id = trace_context.span_id
    @trace_context = trace_context
  else
    @trace_context = TraceContext.for_transaction(sampled: sampled)
  end

  @started_spans = 0
  @dropped_spans = 0

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

Instance Attribute Details

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



45
46
47
# File 'lib/elastic_apm/transaction.rb', line 45

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.



45
46
47
# File 'lib/elastic_apm/transaction.rb', line 45

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.



45
46
47
# File 'lib/elastic_apm/transaction.rb', line 45

def duration
  @duration
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, Metrics/MethodLength



43
44
45
# File 'lib/elastic_apm/transaction.rb', line 43

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.



45
46
47
# File 'lib/elastic_apm/transaction.rb', line 45

def notifications
  @notifications
end

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



45
46
47
# File 'lib/elastic_apm/transaction.rb', line 45

def parent_id
  @parent_id
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, Metrics/MethodLength



43
44
45
# File 'lib/elastic_apm/transaction.rb', line 43

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



45
46
47
# File 'lib/elastic_apm/transaction.rb', line 45

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.



45
46
47
# File 'lib/elastic_apm/transaction.rb', line 45

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.



45
46
47
# File 'lib/elastic_apm/transaction.rb', line 45

def trace_context
  @trace_context
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, Metrics/MethodLength



43
44
45
# File 'lib/elastic_apm/transaction.rb', line 43

def type
  @type
end

Instance Method Details

#add_response(*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



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

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

#done(result = nil, end_time: Util.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.



83
84
85
86
87
# File 'lib/elastic_apm/transaction.rb', line 83

def done(result = nil, end_time: Util.micros)
  stop end_time
  self.result = result if result
  self
end

#done?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)


60
61
62
# File 'lib/elastic_apm/transaction.rb', line 60

def done?
  stopped?
end

#ensure_parent_idObject

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.



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

def ensure_parent_id
  @parent_id ||= SecureRandom.hex(8)
  @parent_id
end

#idObject

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.



48
49
50
# File 'lib/elastic_apm/transaction.rb', line 48

def id
  trace_context.span_id
end

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



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

def inc_dropped_spans!
  @dropped_spans += 1
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



96
97
98
# File 'lib/elastic_apm/transaction.rb', line 96

def inc_started_spans!
  @started_spans += 1
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.



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

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

#max_spans_reached?(config) ⇒ 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)


104
105
106
# File 'lib/elastic_apm/transaction.rb', line 104

def max_spans_reached?(config)
  started_spans > config.transaction_max_spans
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)


52
53
54
# File 'lib/elastic_apm/transaction.rb', line 52

def sampled?
  @sampled
end

#start(timestamp = Util.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



72
73
74
75
# File 'lib/elastic_apm/transaction.rb', line 72

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

#stop(end_timestamp = Util.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.



77
78
79
80
81
# File 'lib/elastic_apm/transaction.rb', line 77

def stop(end_timestamp = Util.micros)
  raise 'Transaction not yet start' unless timestamp
  @duration = end_timestamp - timestamp
  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)


56
57
58
# File 'lib/elastic_apm/transaction.rb', line 56

def stopped?
  !!duration
end

#trace_idObject

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.



66
67
68
# File 'lib/elastic_apm/transaction.rb', line 66

def trace_id
  trace_context&.trace_id
end