Sha256: d1b00d3d8b72671f9b68050c8a3526871e37863d1dc8ba8400bf4e526b88d8d7

Contents?: true

Size: 1018 Bytes

Versions: 2

Compression:

Stored size: 1018 Bytes

Contents

# frozen_string_literal: true

require 'net/http'
require 'typhoeus'

module Istio
  module NetHttp
    module ClassInterceptor
      def new(*options)
        o = super(*options)
        o
      end
    end
    module InstanceInterceptor
      def initialize(*options)
        super(*options)
      end

      def request(req, *args, &block)
        return super unless Context.exists_current?

        headers = Context.current.headers
        PROPAGATION_HEADERS.each do |h|
          req[h] = headers[h] if headers[h].present?
        end
        super
      end
    end
  end
end

::Net::HTTP.singleton_class.prepend Istio::NetHttp::ClassInterceptor
::Net::HTTP.prepend Istio::NetHttp::InstanceInterceptor

module Typhoeus
  Typhoeus.before do |req|
    return req unless Istio::Tracing::Context.exists_current?

    headers = Istio::Tracing::Context.current.headers
    Istio::Tracing::PROPAGATION_HEADERS.each do |h|
      req.options[:headers][h] = headers[h] unless headers[h]&.nil?
    end
    req
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ygrene_istio_tracing-1.0.1 lib/istio/tracing/http.rb
ygrene_istio_tracing-1.0.0 lib/istio/tracing/http.rb