Sha256: a7c83b389be429aaf8e89aab35db5be9cb8f041582e49993fb6df75f69cc99bb

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

module Garage
  module Tracer
    extend self
    extend Forwardable

    def_delegators :tracer, :start, :inject_trace_context, :record_http_request, :record_http_response

    private

    def tracer
      Garage.configuration.tracer
    end

    # Any tracers must have `.start` to start tracing context and:
    #   - `#inject_trace_context` to add tracing context to the given request header.
    #   - `#record_http_request` to record http request in tracer.
    #   - `#record_http_response` to recrod http response in tracer.
    class NullTracer
      def self.start(&block)
        yield new
      end

      # @param [Hash] header
      # @return [Hash]
      def inject_trace_context(header)
        header
      end

      # @param [String] method
      # @param [String] url
      # @param [String] user_agent
      # @return [nil]
      def record_http_request(method, url, user_agent)
      end

      # @param [Integer] status
      # @param [Integer] content_length
      def record_http_response(status, content_length)
      end
    end

    class AwsXrayTracer
      class << self
        attr_accessor :service
      end

      def self.start(&block)
        yield new
      end

      def inject_trace_context(header)
        header.merge('X-Aws-Xray-Name' => self.class.service)
      end

      def record_http_request(method, url, user_agent)
      end

      def record_http_response(status, content_length)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
the_garage-2.4.3 lib/garage/tracer.rb
the_garage-2.4.2 lib/garage/tracer.rb