Class: Watchforge::Span

Inherits:
Object
  • Object
show all
Defined in:
lib/watchforge/tracing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(op, description = "", parent_span_id: nil, data: nil) ⇒ Span

Returns a new instance of Span.



11
12
13
14
15
16
17
18
19
20
# File 'lib/watchforge/tracing.rb', line 11

def initialize(op, description = "", parent_span_id: nil, data: nil)
  @span_id = SecureRandom.uuid
  @op = op
  @description = description
  @parent_span_id = parent_span_id
  @data = data || {}
  @tags = {}
  @start_timestamp = (Time.now.to_f * 1000).to_i
  @status = "ok"
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/watchforge/tracing.rb', line 8

def data
  @data
end

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'lib/watchforge/tracing.rb', line 8

def description
  @description
end

#duration_msObject

Returns the value of attribute duration_ms.



9
10
11
# File 'lib/watchforge/tracing.rb', line 9

def duration_ms
  @duration_ms
end

#finish_timestampObject

Returns the value of attribute finish_timestamp.



9
10
11
# File 'lib/watchforge/tracing.rb', line 9

def finish_timestamp
  @finish_timestamp
end

#opObject (readonly)

Returns the value of attribute op.



8
9
10
# File 'lib/watchforge/tracing.rb', line 8

def op
  @op
end

#parent_span_idObject (readonly)

Returns the value of attribute parent_span_id.



8
9
10
# File 'lib/watchforge/tracing.rb', line 8

def parent_span_id
  @parent_span_id
end

#span_idObject (readonly)

Returns the value of attribute span_id.



8
9
10
# File 'lib/watchforge/tracing.rb', line 8

def span_id
  @span_id
end

#statusObject

Returns the value of attribute status.



9
10
11
# File 'lib/watchforge/tracing.rb', line 9

def status
  @status
end

#status_codeObject

Returns the value of attribute status_code.



9
10
11
# File 'lib/watchforge/tracing.rb', line 9

def status_code
  @status_code
end

#tagsObject (readonly)

Returns the value of attribute tags.



8
9
10
# File 'lib/watchforge/tracing.rb', line 8

def tags
  @tags
end

Instance Method Details

#finish(status = "ok", status_code: nil) ⇒ Object



22
23
24
25
26
27
# File 'lib/watchforge/tracing.rb', line 22

def finish(status = "ok", status_code: nil)
  @status = status
  @status_code = status_code
  @finish_timestamp = (Time.now.to_f * 1000).to_i
  @duration_ms = @finish_timestamp - @start_timestamp
end

#to_hObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/watchforge/tracing.rb', line 29

def to_h
  {
    span_id: span_id,
    parent_span_id: parent_span_id,
    op: op,
    description: description,
    start_timestamp: Time.at(@start_timestamp / 1000.0).utc.iso8601,
    finish_timestamp: finish_timestamp ? Time.at(finish_timestamp / 1000.0).utc.iso8601 : nil,
    duration_ms: duration_ms,
    status: status,
    status_code: status_code,
    data: data,
    tags: tags,
    timestamp: Time.at(@start_timestamp / 1000.0).utc.iso8601
  }
end