Class: Atatus::Transaction Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
ChildDurations::Methods
Defined in:
lib/atatus/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'
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, sampled: true, sample_rate: 1, context: nil, config:, 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



33
34
35
36
37
38
39
40
41
42
43
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
# File 'lib/atatus/transaction.rb', line 33

def initialize(
  name = nil,
  type = nil,
  sampled: true,
  sample_rate: 1,
  context: nil,
  config:,
  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.



79
80
81
# File 'lib/atatus/transaction.rb', line 79

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.



79
80
81
# File 'lib/atatus/transaction.rb', line 79

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.



79
80
81
# File 'lib/atatus/transaction.rb', line 79

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.



79
80
81
# File 'lib/atatus/transaction.rb', line 79

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.



79
80
81
# File 'lib/atatus/transaction.rb', line 79

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.



79
80
81
# File 'lib/atatus/transaction.rb', line 79

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



77
78
79
# File 'lib/atatus/transaction.rb', line 77

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.



79
80
81
# File 'lib/atatus/transaction.rb', line 79

def notifications
  @notifications
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



77
78
79
# File 'lib/atatus/transaction.rb', line 77

def result
  @result
end

#ruby_timeObject

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



77
78
79
# File 'lib/atatus/transaction.rb', line 77

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



79
80
81
# File 'lib/atatus/transaction.rb', line 79

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.



79
80
81
# File 'lib/atatus/transaction.rb', line 79

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.



79
80
81
# File 'lib/atatus/transaction.rb', line 79

def span_frames_min_duration
  @span_frames_min_duration
end

#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



77
78
79
# File 'lib/atatus/transaction.rb', line 77

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



79
80
81
# File 'lib/atatus/transaction.rb', line 79

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.



79
80
81
# File 'lib/atatus/transaction.rb', line 79

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.



79
80
81
# File 'lib/atatus/transaction.rb', line 79

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.



79
80
81
# File 'lib/atatus/transaction.rb', line 79

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



77
78
79
# File 'lib/atatus/transaction.rb', line 77

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



143
144
145
# File 'lib/atatus/transaction.rb', line 143

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.



122
123
124
125
126
# File 'lib/atatus/transaction.rb', line 122

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



130
131
132
133
134
135
136
137
138
139
# File 'lib/atatus/transaction.rb', line 130

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.



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

def inspect
  "<Atatus::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)


98
99
100
# File 'lib/atatus/transaction.rb', line 98

def sampled?
  @sampled
end

#set_company(company) ⇒ 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.



151
152
153
# File 'lib/atatus/transaction.rb', line 151

def set_company(company)
  context.company = Context::Company.infer(@config, company)
end

#set_response_body(response_body) ⇒ 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.



155
156
157
# File 'lib/atatus/transaction.rb', line 155

def set_response_body(response_body)
  context.response_body = response_body
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.



147
148
149
# File 'lib/atatus/transaction.rb', line 147

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



108
109
110
111
112
# File 'lib/atatus/transaction.rb', line 108

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.



114
115
116
117
118
119
120
# File 'lib/atatus/transaction.rb', line 114

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)


102
103
104
# File 'lib/atatus/transaction.rb', line 102

def stopped?
  !!duration
end