Class: Startback::Audit::Span

Inherits:
Object
  • Object
show all
Defined in:
lib/startback/audit/span.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributesObject (readonly)

Returns the value of attribute attributes.



14
15
16
# File 'lib/startback/audit/span.rb', line 14

def attributes
  @attributes
end

#errorObject (readonly)

Returns the value of attribute error.



14
15
16
# File 'lib/startback/audit/span.rb', line 14

def error
  @error
end

#parent_idObject (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_idObject (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

#statusObject (readonly)

Returns the value of attribute status.



14
15
16
# File 'lib/startback/audit/span.rb', line 14

def status
  @status
end

#timingObject (readonly)

Returns the value of attribute timing.



14
15
16
# File 'lib/startback/audit/span.rb', line 14

def timing
  @timing
end

#trace_idObject (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


20
21
22
# File 'lib/startback/audit/span.rb', line 20

def success?
  @status == 'success'
end

#to_hObject



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