Class: StackTrace::Trace

Inherits:
Object
  • Object
show all
Defined in:
lib/stack_trace/trace.rb

Constant Summary collapse

TRACE_START_EVENTS =
%i(call c_call).freeze
TRACE_END_EVENTS =
%i(return c_return).freeze
TRACE_RAISE_EVENT =
:raise

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTrace

Returns a new instance of Trace.



37
38
39
40
# File 'lib/stack_trace/trace.rb', line 37

def initialize
  @uuid = SecureRandom.uuid
  @spans = []
end

Instance Attribute Details

#spansObject (readonly)

Returns the value of attribute spans.



35
36
37
# File 'lib/stack_trace/trace.rb', line 35

def spans
  @spans
end

#uuidObject (readonly)

Returns the value of attribute uuid.



35
36
37
# File 'lib/stack_trace/trace.rb', line 35

def uuid
  @uuid
end

Class Method Details

.as_jsonObject



24
25
26
# File 'lib/stack_trace/trace.rb', line 24

def as_json
  current.as_json
end

.currentObject



20
21
22
# File 'lib/stack_trace/trace.rb', line 20

def current
  @current ||= new
end

.startObject



16
17
18
# File 'lib/stack_trace/trace.rb', line 16

def start
  @current = new
end

.track(trace_point) ⇒ Object



12
13
14
# File 'lib/stack_trace/trace.rb', line 12

def track(trace_point)
  current.add(trace_point) if trackable?(trace_point)
end

Instance Method Details

#<<(span) ⇒ Object



60
61
62
# File 'lib/stack_trace/trace.rb', line 60

def <<(span)
  spans << span
end

#add(trace_point) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/stack_trace/trace.rb', line 42

def add(trace_point)
  case trace_point.event
  when *TRACE_START_EVENTS
    create_new_span(trace_point)
  when *TRACE_END_EVENTS
    close_current_span(trace_point)
  else
    apply_exception_to_current_span(trace_point)
  end
end

#as_jsonObject



53
54
55
56
57
58
# File 'lib/stack_trace/trace.rb', line 53

def as_json
  {
    uuid: uuid,
    spans: spans.map(&:as_json)
  }
end