Class: StackifyRubyAPM::Transaction Private

Inherits:
Object
  • Object
show all
Defined in:
lib/stackify_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'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instrumenter, name = nil, type = nil, context: nil) {|_self| ... } ⇒ 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.

Returns a new instance of Transaction.

Yields:

  • (_self)

Yield Parameters:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/stackify_apm/transaction.rb', line 12

def initialize(instrumenter, name = nil,
               type = nil, context: nil)
  # puts "Loads transaction new initialize
  # instrumenter, name = nil, type = nil, context: nil"
  @id = SecureRandom.uuid
  @instrumenter = instrumenter
  @name = name
  @type = type || DEFAULT_TYPE
  @timestamp = Time.now.to_f * 1000

  @spans = []
  @span_id_ticker = -1
  @dropped_spans = 0

  @notifications = [] # for AS::Notifications
  @context = context || Context.new
  @exceptions = []

  yield self if block_given?
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.



34
35
36
# File 'lib/stackify_apm/transaction.rb', line 34

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.



34
35
36
# File 'lib/stackify_apm/transaction.rb', line 34

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.



34
35
36
# File 'lib/stackify_apm/transaction.rb', line 34

def duration
  @duration
end

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



35
36
37
# File 'lib/stackify_apm/transaction.rb', line 35

def exceptions
  @exceptions
end

#http_statusObject

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.



33
34
35
# File 'lib/stackify_apm/transaction.rb', line 33

def http_status
  @http_status
end

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



34
35
36
# File 'lib/stackify_apm/transaction.rb', line 34

def id
  @id
end

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



34
35
36
# File 'lib/stackify_apm/transaction.rb', line 34

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



33
34
35
# File 'lib/stackify_apm/transaction.rb', line 33

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.



35
36
37
# File 'lib/stackify_apm/transaction.rb', line 35

def notifications
  @notifications
end

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



35
36
37
# File 'lib/stackify_apm/transaction.rb', line 35

def result
  @result
end

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



35
36
37
# File 'lib/stackify_apm/transaction.rb', line 35

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



35
36
37
# File 'lib/stackify_apm/transaction.rb', line 35

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



33
34
35
# File 'lib/stackify_apm/transaction.rb', line 33

def type
  @type
end

Instance Method Details

#add_exception(exception) ⇒ 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.



37
38
39
# File 'lib/stackify_apm/transaction.rb', line 37

def add_exception(exception)
  @exceptions << exception
end

#current_spanObject

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.



85
86
87
# File 'lib/stackify_apm/transaction.rb', line 85

def current_span
  spans.reverse.lazy.find(&:running?)
end

#done(result = nil) ⇒ 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.



45
46
47
48
49
50
51
# File 'lib/stackify_apm/transaction.rb', line 45

def done(result = nil)
  @duration = Time.now.to_f * 1000
  @result = result
  @http_status = 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)


53
54
55
# File 'lib/stackify_apm/transaction.rb', line 53

def done?
  !@duration.nil?
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.



89
90
91
92
93
94
# File 'lib/stackify_apm/transaction.rb', line 89

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

#releaseObject

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.



41
42
43
# File 'lib/stackify_apm/transaction.rb', line 41

def release
  @instrumenter.current_transaction = nil
end

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

This method is being used in unit testing



68
69
70
# File 'lib/stackify_apm/transaction.rb', line 68

def running_spans
  spans.select(&:running?)
end

#span(name, type = nil, backtrace: nil, context: nil) ⇒ 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.



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/stackify_apm/transaction.rb', line 72

def span(name, type = nil, backtrace: nil, context: nil)
  span = build_and_start_span(name, type, context, backtrace)
  return span unless block_given?

  begin
    result = yield span
  ensure
    span.done
  end

  result
end

#submit(result = nil, status: nil, headers: {}) ⇒ 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.



57
58
59
60
61
62
63
64
65
# File 'lib/stackify_apm/transaction.rb', line 57

def submit(result = nil, status: nil, headers: {})
  done result unless duration
  context.response = Context::Response.new(status, headers: headers) if status

  release
  @instrumenter.submit_transaction self

  self
end