Class: Gruf::Zipkin::Headers

Inherits:
Object
  • Object
show all
Defined in:
lib/gruf/zipkin/headers.rb

Overview

Abstraction accessor class for B3 propagation headers across GRPC ActiveCall objects

Constant Summary collapse

ZIPKIN_KEYS =
{
    parent_span_id: %w(x-b3-parentspanid X-B3-ParentSpanId HTTP_X_B3_PARENTSPANID),
    span_id: %w(x-b3-spanid X-B3-SpanId HTTP_X_B3_SPANID),
    trace_id: %w(x-b3-traceid X-B3-TraceId HTTP_X_B3_TRACEID),
    sampled: %w(x-b3-sampled X-B3-Sampled HTTP_X_B3_SAMPLED),
    flags: %w(x-b3-flags X-B3-Flags HTTP_X_B3_FLAGS)
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(active_call) ⇒ Headers

Returns a new instance of Headers

Parameters:

  • active_call (GRPC::ActiveCall)

39
40
41
# File 'lib/gruf/zipkin/headers.rb', line 39

def initialize(active_call)
  @active_call = active_call
end

Instance Attribute Details

#active_callObject (readonly)

Returns the value of attribute active_call


23
24
25
# File 'lib/gruf/zipkin/headers.rb', line 23

def active_call
  @active_call
end

Instance Method Details

#value(key) ⇒ String|NilClass

Return a B3 propagation header if present

Parameters:

  • key (Symbol)

Returns:

  • (String|NilClass)

49
50
51
52
53
54
55
# File 'lib/gruf/zipkin/headers.rb', line 49

def value(key)
  return nil unless ZIPKIN_KEYS.key?(key)
  ZIPKIN_KEYS[key].each do |k|
    return @active_call.[k] if @active_call..key?(k)
  end
  nil
end