lib/jaeger/client/span_context.rb in jaeger-client-0.4.2 vs lib/jaeger/client/span_context.rb in jaeger-client-0.5.0

- old
+ new

@@ -1,18 +1,21 @@ +# frozen_string_literal: true + module Jaeger module Client # SpanContext holds the data for a span that gets inherited to child spans class SpanContext module Flags + NONE = 0x00 SAMPLED = 0x01 DEBUG = 0x02 end - def self.create_parent_context + def self.create_parent_context(sampler = Samplers::Const.new(true)) trace_id = TraceId.generate span_id = TraceId.generate - flags = Flags::SAMPLED + flags = sampler.sample?(trace_id) ? Flags::SAMPLED : Flags::NONE new(trace_id: trace_id, span_id: span_id, flags: flags) end def self.create_from_parent_context(span_context) trace_id = span_context.trace_id @@ -28,9 +31,17 @@ @span_id = span_id @parent_id = parent_id @trace_id = trace_id @baggage = baggage @flags = flags + end + + def sampled? + @flags & Flags::SAMPLED == Flags::SAMPLED + end + + def debug? + @flags & Flags::DEBUG == Flags::DEBUG end def inspect to_s end