Class: Maze::Api::Model::SpanSet
- Inherits:
-
Object
- Object
- Maze::Api::Model::SpanSet
- Defined in:
- lib/maze/api/model/span_set.rb
Overview
A collection of spans, typically representing one or more traces.
Class Method Summary collapse
-
.add_trace_hash(trace_hash, span_set) ⇒ Object
Adds spans from a trace hash to an existing SpanSet.
-
.from_trace_hash(trace_hash) ⇒ Object
Creates a new SpanSet from a trace hash.
Instance Method Summary collapse
- #add(span) ⇒ Object
-
#add_from_trace_hash(trace_hash) ⇒ Object
Add spans from a trace hash to the SpanSet.
-
#initialize ⇒ SpanSet
constructor
A new instance of SpanSet.
-
#names ⇒ Array<String>
List of span names in the SpanSet.
- #remove(span_id) ⇒ Object
-
#size ⇒ Integer
Number of spans in the SpanSet.
Constructor Details
#initialize ⇒ SpanSet
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.
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 |
Instance Method Details
#add(span) ⇒ Object
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.
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 |
#names ⇒ Array<String>
Returns 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
26 27 28 |
# File 'lib/maze/api/model/span_set.rb', line 26 def remove(span_id) @spans.delete(span_id) end |
#size ⇒ Integer
Returns Number of spans in the SpanSet.
31 32 33 |
# File 'lib/maze/api/model/span_set.rb', line 31 def size @spans.size end |