Sha256: bd72a7cc5bc35ed1c8a03c9a621cfd638c3097a745d5f205fcc904872f214ba4

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 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/rack_builder'
        end

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

        def use_middleware_by_default
          ::Faraday::RackBuilder.prepend(Patches::RackBuilder)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-faraday-0.24.4 lib/opentelemetry/instrumentation/faraday/instrumentation.rb
opentelemetry-instrumentation-faraday-0.24.2 lib/opentelemetry/instrumentation/faraday/instrumentation.rb
opentelemetry-instrumentation-faraday-0.24.1 lib/opentelemetry/instrumentation/faraday/instrumentation.rb
opentelemetry-instrumentation-faraday-0.24.0 lib/opentelemetry/instrumentation/faraday/instrumentation.rb