Sha256: 8d0766919742961a37ac07c675034a6a91041c5174ca5b58e190f31c911d195d

Contents?: true

Size: 1.43 KB

Versions: 11

Compression:

Stored size: 1.43 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

module ::Excon
  class Connection
    def newrelic_connection_params
      (@connection || @data)
    end

    def newrelic_resolved_request_params(request_params)
      resolved = newrelic_connection_params.merge(request_params)
      resolved[:headers] = resolved[:headers].merge(request_params[:headers] || {})
      resolved
    end

    def request_with_newrelic_trace(params, &block)
      resolved_params = newrelic_resolved_request_params(params)
      wrapped_request = ::NewRelic::Agent::HTTPClients::ExconHTTPRequest.new(resolved_params)
      segment = NewRelic::Agent::Transaction.start_external_request_segment(
        library: wrapped_request.type,
        uri: wrapped_request.uri,
        procedure: wrapped_request.method
      )

      begin
        response = nil
        segment.add_request_headers wrapped_request

        response = request_without_newrelic_trace(resolved_params, &block)

        wrapped_response = ::NewRelic::Agent::HTTPClients::ExconHTTPResponse.new(response)
        segment.read_response_headers wrapped_response

        response
      ensure
        segment.finish if segment
      end
    end

    def self.install_newrelic_instrumentation
      alias request_without_newrelic_trace request
      alias request request_with_newrelic_trace
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
newrelic_rpm-5.7.0.350 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-5.6.0.349 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-5.5.0.348 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-5.4.0.347 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-5.3.0.346 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-5.2.0.345 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-5.1.0.344 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-5.0.0.342 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-4.8.0.341 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-4.7.1.340 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-4.7.0.339 lib/new_relic/agent/instrumentation/excon/connection.rb