class LightStep::Propagation::LightStepPropagator
Constants
- CARRIER_BAGGAGE_PREFIX
- CARRIER_SAMPLED
- CARRIER_SPAN_ID
- CARRIER_TRACER_STATE_PREFIX
- CARRIER_TRACE_ID
Public Instance Methods
extract(format, carrier)
click to toggle source
Extract a SpanContext
from a carrier @param format [OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY, OpenTracing::FORMAT_RACK] @param carrier [Carrier] A carrier object of the type dictated by the specified `format` @return [SpanContext] the extracted SpanContext
or nil if none could be found
# File lib/lightstep/propagation/lightstep_propagator.rb, line 34 def extract(format, carrier) case format when OpenTracing::FORMAT_TEXT_MAP extract_from_text_map(carrier) when OpenTracing::FORMAT_BINARY warn 'Binary join format not yet implemented' nil when OpenTracing::FORMAT_RACK extract_from_rack(carrier) else warn 'Unknown join format' nil end end
inject(span_context, format, carrier)
click to toggle source
Inject a SpanContext
into the given carrier
@param spancontext [SpanContext] @param format [OpenTracing::FORMAT_TEXT_MAP, OpenTracing::FORMAT_BINARY] @param carrier [Carrier] A carrier object of the type dictated by the specified `format`
# File lib/lightstep/propagation/lightstep_propagator.rb, line 17 def inject(span_context, format, carrier) case format when OpenTracing::FORMAT_TEXT_MAP inject_to_text_map(span_context, carrier) when OpenTracing::FORMAT_BINARY warn 'Binary inject format not yet implemented' when OpenTracing::FORMAT_RACK inject_to_rack(span_context, carrier) else warn 'Unknown inject format' end end
Private Instance Methods
extract_from_rack(env)
click to toggle source
# File lib/lightstep/propagation/lightstep_propagator.rb, line 102 def extract_from_rack(env) extract_from_text_map(env.reduce({}){|memo, (raw_header, value)| header = raw_header.to_s.gsub(/^HTTP_/, '') header.tr!('_', '-') header.downcase! memo[header] = value if header.start_with?(self.class::CARRIER_TRACER_STATE_PREFIX, self.class::CARRIER_BAGGAGE_PREFIX) memo }) end
extract_from_text_map(carrier)
click to toggle source
# File lib/lightstep/propagation/lightstep_propagator.rb, line 63 def extract_from_text_map(carrier) # If the carrier does not have both the span_id and trace_id key # skip the processing and just return a normal span if !carrier.has_key?(self.class::CARRIER_SPAN_ID) || !carrier.has_key?(self.class::CARRIER_TRACE_ID) return nil end baggage = carrier.reduce({}) do |baggage, (key, value)| if key.start_with?(self.class::CARRIER_BAGGAGE_PREFIX) plain_key = key.to_s[self.class::CARRIER_BAGGAGE_PREFIX.length..key.to_s.length] baggage[plain_key] = value end baggage end SpanContext.new( id: carrier[self.class::CARRIER_SPAN_ID], trace_id: carrier[self.class::CARRIER_TRACE_ID], sampled: sampled_flag_from_carrier(carrier), baggage: baggage, ) end
inject_to_rack(span_context, carrier)
click to toggle source
# File lib/lightstep/propagation/lightstep_propagator.rb, line 86 def inject_to_rack(span_context, carrier) if trace_id = trace_id_from_ctx(span_context) carrier[self.class::CARRIER_TRACE_ID] = trace_id end carrier[self.class::CARRIER_SPAN_ID] = span_context.id carrier[self.class::CARRIER_SAMPLED] = sampled_flag_from_ctx(span_context) span_context.baggage.each do |key, value| if key =~ /[^A-Za-z0-9\-_]/ # TODO: log the error internally next end carrier[self.class::CARRIER_BAGGAGE_PREFIX + key] = value end end
inject_to_text_map(span_context, carrier)
click to toggle source
# File lib/lightstep/propagation/lightstep_propagator.rb, line 51 def inject_to_text_map(span_context, carrier) if trace_id = trace_id_from_ctx(span_context) carrier[self.class::CARRIER_TRACE_ID] = trace_id end carrier[self.class::CARRIER_SPAN_ID] = span_context.id carrier[self.class::CARRIER_SAMPLED] = sampled_flag_from_ctx(span_context) span_context.baggage.each do |key, value| carrier[self.class::CARRIER_BAGGAGE_PREFIX + key] = value end end
sampled_flag_from_carrier(_)
click to toggle source
# File lib/lightstep/propagation/lightstep_propagator.rb, line 122 def sampled_flag_from_carrier(_) true end
sampled_flag_from_ctx(_)
click to toggle source
# File lib/lightstep/propagation/lightstep_propagator.rb, line 118 def sampled_flag_from_ctx(_) 'true' end
trace_id_from_ctx(ctx)
click to toggle source
# File lib/lightstep/propagation/lightstep_propagator.rb, line 114 def trace_id_from_ctx(ctx) ctx.trace_id end