Class: Maze::Api::Model::SpanSet

Inherits:
Object
  • Object
show all
Defined in:
lib/maze/api/model/span_set.rb

Overview

A collection of spans, typically representing one or more traces.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSpanSet

Returns a new instance of SpanSet.



10
11
12
# File 'lib/maze/api/model/span_set.rb', line 10

def initialize
  @spans = {}
end

Class Method Details

.add_trace_hash(trace_hash, span_set) ⇒ Object

Adds spans from a trace hash to an existing SpanSet.

Parameters:



52
53
54
55
56
57
58
59
60
61
# File 'lib/maze/api/model/span_set.rb', line 52

def add_trace_hash(trace_hash, span_set)
  spans = trace_hash['resourceSpans'].flat_map { |r| r['scopeSpans'] }
                                     .flat_map { |s| s['spans'] }
                                     .select { |s| !s.nil? }

  spans.each do |span_hash|
    span = Maze::Api::Model::Span.from_hash(span_hash)
    span_set.add(span)
  end
end

.from_trace_hash(trace_hash) ⇒ Object

Creates a new SpanSet from a trace hash.

Parameters:

  • trace_hash (Hash)

    Trace request payload as a hash.



43
44
45
46
47
# File 'lib/maze/api/model/span_set.rb', line 43

def from_trace_hash(trace_hash)
  span_set = Maze::Api::Model::SpanSet.new
  add_trace_hash(trace_hash, span_set)
  span_set
end

Instance Method Details

#add(span) ⇒ Object

Parameters:



15
16
17
# File 'lib/maze/api/model/span_set.rb', line 15

def add(span)
  @spans[span.id] = span
end

#add_from_trace_hash(trace_hash) ⇒ Object

Add spans from a trace hash to the SpanSet.

Parameters:

  • trace_hash (Hash)

    Trace request payload as a hash.



21
22
23
# File 'lib/maze/api/model/span_set.rb', line 21

def add_from_trace_hash(trace_hash)
  SpanSet.add_trace_hash(trace_hash, self)
end

#namesArray<String>

Returns List of span names in the SpanSet.

Returns:

  • (Array<String>)

    List of span names in the SpanSet.



36
37
38
# File 'lib/maze/api/model/span_set.rb', line 36

def names
  @spans.values.map(&:name)
end

#remove(span_id) ⇒ Object

Parameters:

  • span_id (String)

    Id of the span to remove from the SpanSet.



26
27
28
# File 'lib/maze/api/model/span_set.rb', line 26

def remove(span_id)
  @spans.delete(span_id)
end

#sizeInteger

Returns Number of spans in the SpanSet.

Returns:

  • (Integer)

    Number of spans in the SpanSet.



31
32
33
# File 'lib/maze/api/model/span_set.rb', line 31

def size
  @spans.size
end