Sha256: 1353ab964ae1b52f7c9cf4a3e810008fb5d4f38c6a70f5e2f5102161ddebce26

Contents?: true

Size: 1003 Bytes

Versions: 14

Compression:

Stored size: 1003 Bytes

Contents

# frozen_string_literal: true

module ElasticAPM
  # @api private
  module Spies
    # @api private
    class HTTPSpy
      # rubocop:disable Metrics/MethodLength
      def install
        ::HTTP::Client.class_eval do
          alias perform_without_apm perform

          def perform(req, options)
            unless (transaction = ElasticAPM.current_transaction)
              return perform_without_apm(req, options)
            end

            method = req.verb.to_s.upcase
            host = req.uri.host

            name = "#{method} #{host}"
            type = "ext.http_rb.#{method}"

            ElasticAPM.with_span name, type do |span|
              trace_context = span&.trace_context || transaction.trace_context
              req['Elastic-Apm-Traceparent'] = trace_context.to_header
              perform_without_apm(req, options)
            end
          end
        end
      end
      # rubocop:enable Metrics/MethodLength
    end

    register 'HTTP', 'http', HTTPSpy.new
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
elastic-apm-2.10.1 lib/elastic_apm/spies/http.rb
elastic-apm-2.10.0 lib/elastic_apm/spies/http.rb
elastic-apm-2.9.1 lib/elastic_apm/spies/http.rb
elastic-apm-2.9.0 lib/elastic_apm/spies/http.rb
elastic-apm-2.8.1 lib/elastic_apm/spies/http.rb
elastic-apm-2.8.0 lib/elastic_apm/spies/http.rb
elastic-apm-2.7.0 lib/elastic_apm/spies/http.rb
elastic-apm-2.6.1 lib/elastic_apm/spies/http.rb
elastic-apm-2.6.0 lib/elastic_apm/spies/http.rb
elastic-apm-2.5.0 lib/elastic_apm/spies/http.rb
elastic-apm-2.4.0 lib/elastic_apm/spies/http.rb
elastic-apm-2.3.1 lib/elastic_apm/spies/http.rb
elastic-apm-2.3.0 lib/elastic_apm/spies/http.rb
elastic-apm-2.2.0 lib/elastic_apm/spies/http.rb