Sha256: 860b19810c9a620cb357ded5006e4bf2e3ec9aff6fb2c7b7f5051d619e1a9fcc

Contents?: true

Size: 971 Bytes

Versions: 1

Compression:

Stored size: 971 Bytes

Contents

module RequestTracer
  module Integration
    module Base
      B3_REQUIRED_FIELDS = %w(trace_id parent_span_id span_id)
      B3_REQUIRED_FIELDS_FROM_SHORT_NAMES = B3_REQUIRED_FIELDS.map {|f| [f.gsub("_", ""), f] }.to_h
      B3_REQUIRED_HEADERS = B3_REQUIRED_FIELDS.map {|f| "HTTP_X_B3_#{f.gsub("_", "").upcase}" }
      B3_REQUIRED_FIELD_HEADER_MAP = B3_REQUIRED_FIELDS.zip(B3_REQUIRED_HEADERS).to_h
      B3_REQUIRED_HEADER_FIELD_MAP = B3_REQUIRED_HEADERS.zip(B3_REQUIRED_FIELDS).to_h
      B3_OPT_HEADERS = %w[HTTP_X_B3_FLAGS]
      def extract_fields_from_headers(header_hash)
        header_hash.map do |k,v|
          special_header = /HTTP_X_B3_(.*)/.match(k)
          special_header && [B3_REQUIRED_FIELDS_FROM_SHORT_NAMES[special_header[1].downcase], v]
        end.compact.to_h
      end
      def extract_headers_from_fields(field_hash)
        B3_REQUIRED_FIELDS.map {|f| ["X_B3_" + f.gsub("_", "").upcase, field_hash[f]]}.to_h
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
request-tracer-0.5.2 lib/request_tracer/integration/base.rb