Class: StackTrace::Trace
- Inherits:
-
Object
- Object
- StackTrace::Trace
- 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
-
#spans ⇒ Object
readonly
Returns the value of attribute spans.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(span) ⇒ Object
- #add(trace_point) ⇒ Object
- #as_json ⇒ Object
-
#initialize ⇒ Trace
constructor
A new instance of Trace.
Constructor Details
#initialize ⇒ Trace
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
#spans ⇒ Object (readonly)
Returns the value of attribute spans.
35 36 37 |
# File 'lib/stack_trace/trace.rb', line 35 def spans @spans end |
#uuid ⇒ Object (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_json ⇒ Object
24 25 26 |
# File 'lib/stack_trace/trace.rb', line 24 def as_json current.as_json end |
.current ⇒ Object
20 21 22 |
# File 'lib/stack_trace/trace.rb', line 20 def current @current ||= new end |
.start ⇒ Object
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_json ⇒ Object
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 |