Sha256: 20fd07dce61666222065329b6c7108922ae7f45584079aaa4ff6c2846aa19233

Contents?: true

Size: 969 Bytes

Versions: 3

Compression:

Stored size: 969 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|
              req['Elastic-Apm-Traceparent'] =
                transaction.traceparent.to_header(span_id: span.id)

              perform_without_apm(req, options)
            end
          end
        end
      end
      # rubocop:enable Metrics/MethodLength
    end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
elastic-apm-2.1.0 lib/elastic_apm/spies/http.rb
elastic-apm-2.0.1 lib/elastic_apm/spies/http.rb
elastic-apm-2.0.0 lib/elastic_apm/spies/http.rb