Class: Flare::TraceBlob
- Inherits:
-
Object
- Object
- Flare::TraceBlob
- Defined in:
- lib/flare/trace_blob.rb
Overview
Value object that turns a group of OTel span_data for a single trace into the Flare-JSON wire format the server expects:
{
"trace_id": "<hex>",
"trace_rule_id": <int|nil>,
"root_name": "<string>",
"started_at": "<iso8601>",
"duration_ms": <int>,
"spans": [
{ "id", "parent_id", "name", "started_at",
"duration_ms", "attributes" }
]
}
The trace_rule_id is read from any span carrying the ‘flare.rule_id` attribute (Path 1 sets it on the sampled root, Path 2 sets it on the rack owner span via WebMarkerSubscriber).
Constant Summary collapse
- ZERO_SPAN_ID =
("\x00".b * 8).freeze
- ROOT_NAME_LIMIT =
255
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(trace_id:, spans:) ⇒ TraceBlob
constructor
A new instance of TraceBlob.
- #to_h ⇒ Object
Constructor Details
#initialize(trace_id:, spans:) ⇒ TraceBlob
Returns a new instance of TraceBlob.
33 34 35 36 |
# File 'lib/flare/trace_blob.rb', line 33 def initialize(trace_id:, spans:) @trace_id = trace_id @spans = spans end |
Class Method Details
.build(trace_id:, spans:) ⇒ Object
28 29 30 31 |
# File 'lib/flare/trace_blob.rb', line 28 def self.build(trace_id:, spans:) return nil if spans.nil? || spans.empty? new(trace_id: trace_id, spans: spans) end |
Instance Method Details
#to_h ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/flare/trace_blob.rb', line 38 def to_h root = find_root { "trace_id" => hexify(@trace_id), "trace_rule_id" => rule_id_from_spans, "root_name" => root_name(root), "started_at" => iso(root&.), "duration_ms" => duration_ms(root), "spans" => @spans.map { |s| span_to_h(s) } } end |