Class: Startback::Audit::Span
- Inherits:
-
Object
- Object
- Startback::Audit::Span
- Defined in:
- lib/startback/audit/span.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#parent_id ⇒ Object
readonly
Returns the value of attribute parent_id.
-
#span_id ⇒ Object
readonly
Returns the value of attribute span_id.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#timing ⇒ Object
readonly
Returns the value of attribute timing.
-
#trace_id ⇒ Object
readonly
Returns the value of attribute trace_id.
Instance Method Summary collapse
- #error? ⇒ Boolean
- #finish(timing, error = nil) ⇒ Object
- #finished? ⇒ Boolean
- #fork(attributes = {}) ⇒ Object
-
#initialize(trace_id, parent_id, attributes = {}, span_id = SecureRandom.uuid) ⇒ Span
constructor
A new instance of Span.
- #success? ⇒ Boolean
- #to_h ⇒ Object
- #to_json(*args, &block) ⇒ Object
Constructor Details
#initialize(trace_id, parent_id, attributes = {}, span_id = SecureRandom.uuid) ⇒ Span
Returns a new instance of Span.
5 6 7 8 9 10 11 12 13 |
# File 'lib/startback/audit/span.rb', line 5 def initialize(trace_id, parent_id, attributes = {}, span_id = SecureRandom.uuid) @trace_id, @parent_id = trace_id, parent_id @span_id = span_id @attributes = attributes @status = 'unknown' @at = (Time.now.to_f*1000).to_i @timing = nil @error = nil end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
14 15 16 |
# File 'lib/startback/audit/span.rb', line 14 def attributes @attributes end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
14 15 16 |
# File 'lib/startback/audit/span.rb', line 14 def error @error end |
#parent_id ⇒ Object (readonly)
Returns the value of attribute parent_id.
14 15 16 |
# File 'lib/startback/audit/span.rb', line 14 def parent_id @parent_id end |
#span_id ⇒ Object (readonly)
Returns the value of attribute span_id.
14 15 16 |
# File 'lib/startback/audit/span.rb', line 14 def span_id @span_id end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
14 15 16 |
# File 'lib/startback/audit/span.rb', line 14 def status @status end |
#timing ⇒ Object (readonly)
Returns the value of attribute timing.
14 15 16 |
# File 'lib/startback/audit/span.rb', line 14 def timing @timing end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id.
14 15 16 |
# File 'lib/startback/audit/span.rb', line 14 def trace_id @trace_id end |
Instance Method Details
#error? ⇒ Boolean
24 25 26 |
# File 'lib/startback/audit/span.rb', line 24 def error? @status == 'error' end |
#finish(timing, error = nil) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/startback/audit/span.rb', line 32 def finish(timing, error = nil) @timing = timing @status = error ? 'error' : 'success' @error = error self end |
#finished? ⇒ Boolean
16 17 18 |
# File 'lib/startback/audit/span.rb', line 16 def finished? @status != 'unknown' end |
#fork(attributes = {}) ⇒ Object
28 29 30 |
# File 'lib/startback/audit/span.rb', line 28 def fork(attributes = {}) Span.new(@trace_id, @span_id, attributes) end |
#success? ⇒ Boolean
20 21 22 |
# File 'lib/startback/audit/span.rb', line 20 def success? @status == 'success' end |
#to_h ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/startback/audit/span.rb', line 39 def to_h { :spanId => span_id, :traceId => trace_id, :parentId => parent_id, :status => status, :timing => timing_to_h, :attributes => attributes, :error => error, }.compact end |
#to_json(*args, &block) ⇒ Object
60 61 62 |
# File 'lib/startback/audit/span.rb', line 60 def to_json(*args, &block) to_h.to_json(*args, &block) end |