Sha256: 9356e56591f782b69ff88fe9e7564f02d44c6598ff5c13371e5b244faa14476c

Contents?: true

Size: 1.43 KB

Versions: 10

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::Tracer.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

10 entries across 10 versions & 1 rubygems

Version Path
newrelic_rpm-6.9.0.363 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-6.8.0.360 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-6.7.0.359 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-6.6.0.358 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-6.5.0.357 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-6.4.0.356 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-6.3.0.355 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-6.2.0.354 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-6.1.0.352 lib/new_relic/agent/instrumentation/excon/connection.rb
newrelic_rpm-6.0.0.351 lib/new_relic/agent/instrumentation/excon/connection.rb