Sha256: 8c46d6d52f704c19743abc96fe52946c1848fea7f2edf1fdc5b31e45041ddbd0

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

module OpenTelemetry
  module Instrumentation
    module Faraday
      # The Instrumentation class contains logic to detect and install the Faraday
      # instrumentation
      class Instrumentation < OpenTelemetry::Instrumentation::Base
        install do |_config|
          require_dependencies
          register_tracer_middleware
          use_middleware_by_default
        end

        present do
          defined?(::Faraday)
        end

        option :span_kind, default: :client, validate: %i[client internal]
        option :peer_service, default: nil, validate: :string

        private

        def require_dependencies
          require_relative 'middlewares/tracer_middleware'
          require_relative 'patches/connection'
          require_relative 'patches/rack_builder'
        end

        def register_tracer_middleware
          ::Faraday::Middleware.register_middleware(
            open_telemetry: Middlewares::TracerMiddleware
          )
        end

        def use_middleware_by_default
          if Gem::Version.new(::Faraday::VERSION) >= Gem::Version.new('1')
            ::Faraday::Connection.prepend(Patches::Connection)
          else
            ::Faraday::RackBuilder.prepend(Patches::RackBuilder)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-faraday-0.24.8 lib/opentelemetry/instrumentation/faraday/instrumentation.rb
opentelemetry-instrumentation-faraday-0.24.7 lib/opentelemetry/instrumentation/faraday/instrumentation.rb
opentelemetry-instrumentation-faraday-0.24.6 lib/opentelemetry/instrumentation/faraday/instrumentation.rb
opentelemetry-instrumentation-faraday-0.24.5 lib/opentelemetry/instrumentation/faraday/instrumentation.rb