Sha256: fb7263f21d2bcfc382c1358db8ed6cecf0742d4fc571627e26aabe8e29d0fc98

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

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

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

        present do
          defined?(::Faraday)
        end

        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

2 entries across 2 versions & 1 rubygems

Version Path
opentelemetry-adapters-faraday-0.4.0 lib/opentelemetry/adapters/faraday/adapter.rb
opentelemetry-adapters-faraday-0.3.0 lib/opentelemetry/adapters/faraday/adapter.rb