Class: Zipkin::SpanContext
- Inherits:
-
Object
- Object
- Zipkin::SpanContext
- Defined in:
- lib/zipkin/span_context.rb
Overview
SpanContext holds the data for a span that gets inherited to child spans
Instance Attribute Summary collapse
-
#baggage ⇒ Object
readonly
Returns the value of attribute baggage.
-
#parent_id ⇒ Object
readonly
Returns the value of attribute parent_id.
-
#span_id ⇒ Object
readonly
Returns the value of attribute span_id.
-
#trace_id ⇒ Object
readonly
Returns the value of attribute trace_id.
Class Method Summary collapse
- .create_from_parent_context(span_context) ⇒ Object
- .create_parent_context(sampler = Samplers::Const.new(true)) ⇒ Object
Instance Method Summary collapse
-
#initialize(span_id:, parent_id: nil, trace_id:, sampled:, baggage: {}) ⇒ SpanContext
constructor
A new instance of SpanContext.
- #sampled? ⇒ Boolean
-
#to_h ⇒ Object
NOTE: This method is not defined in OpenTracing Ruby spec.
Constructor Details
#initialize(span_id:, parent_id: nil, trace_id:, sampled:, baggage: {}) ⇒ SpanContext
Returns a new instance of SpanContext.
23 24 25 26 27 28 29 |
# File 'lib/zipkin/span_context.rb', line 23 def initialize(span_id:, parent_id: nil, trace_id:, sampled:, baggage: {}) @span_id = span_id @parent_id = parent_id @trace_id = trace_id @sampled = sampled @baggage = baggage end |
Instance Attribute Details
#baggage ⇒ Object (readonly)
Returns the value of attribute baggage.
21 22 23 |
# File 'lib/zipkin/span_context.rb', line 21 def baggage @baggage end |
#parent_id ⇒ Object (readonly)
Returns the value of attribute parent_id.
21 22 23 |
# File 'lib/zipkin/span_context.rb', line 21 def parent_id @parent_id end |
#span_id ⇒ Object (readonly)
Returns the value of attribute span_id.
21 22 23 |
# File 'lib/zipkin/span_context.rb', line 21 def span_id @span_id end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id.
21 22 23 |
# File 'lib/zipkin/span_context.rb', line 21 def trace_id @trace_id end |
Class Method Details
.create_from_parent_context(span_context) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/zipkin/span_context.rb', line 12 def self.create_from_parent_context(span_context) new( span_id: TraceId.generate, parent_id: span_context.span_id, trace_id: span_context.trace_id, sampled: span_context.sampled? ) end |
.create_parent_context(sampler = Samplers::Const.new(true)) ⇒ Object
6 7 8 9 10 |
# File 'lib/zipkin/span_context.rb', line 6 def self.create_parent_context(sampler = Samplers::Const.new(true)) trace_id = TraceId.generate sampled = sampler.sample?(trace_id: trace_id) new(trace_id: trace_id, span_id: trace_id, sampled: sampled) end |
Instance Method Details
#sampled? ⇒ Boolean
31 32 33 |
# File 'lib/zipkin/span_context.rb', line 31 def sampled? @sampled end |
#to_h ⇒ Object
NOTE: This method is not defined in OpenTracing Ruby spec. Use with caution.
37 38 39 40 41 42 43 44 |
# File 'lib/zipkin/span_context.rb', line 37 def to_h { span_id: @span_id, parent_id: @parent_id, trace_id: @trace_id, sampled: @sampled } end |