lib/elastic_apm/injectors/net_http.rb
# frozen_string_literal: true module ElasticAPM # @api private module Injectors # @api private class NetHTTPInjector # rubocop:disable Metrics/MethodLength def install Net::HTTP.class_eval do alias request_without_apm request def request(req, body = nil, &block) unless ElasticAPM.current_transaction return request_without_apm(req, body, &block) end host, = req['host'] && req['host'].split(':') method = req.method host ||= address name = "#{method} #{host}" type = "ext.net_http.#{method}" ElasticAPM.span name, type do request_without_apm(req, body, &block) end end end end # rubocop:enable Metrics/MethodLength end register 'Net::HTTP', 'net/http', NetHTTPInjector.new end end