Skip to content

Commit

Permalink
Backport fixes of running instrumentation with the NewRelic test harness
Browse files Browse the repository at this point in the history
After porting the instrumentation to be merged inside the NewRelic rpm
it was possible to run already existing functional testing for HTTP
client instrumentation which uncovered some failed expectations.

This commit backports those fixes.

See newrelic/newrelic-ruby-agent#249
  • Loading branch information
Tiago Sousa committed Aug 18, 2016
1 parent e9be75e commit 7a27bc0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 0 additions & 2 deletions lib/newrelic_httprb/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def perform_with_newrelic_trace(request, options)

response = nil
::NewRelic::Agent::CrossAppTracing.tl_trace_http_request(wrapped_request) do
# RUBY-1244 Disable further tracing in request to avoid double
# counting if connection wasn't started (which calls request again).
response = perform_without_newrelic_trace(request, options)
::NewRelicHTTP::HTTPResponse.new(response)
end
Expand Down
29 changes: 24 additions & 5 deletions lib/newrelic_httprb/wrappers.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
module NewRelicHTTP
HTTPResponse = NewRelic::Agent::HTTPClients::HTTPClientResponse
class HTTPResponse
attr_reader :response

def initialize(response)
@response = response
end

def [](key)
_, value = response.headers.find { |k,_| key.downcase == k.downcase }
value unless value.nil?
end

def to_hash
response.headers
end
end

class HTTPRequest
attr_reader :request, :uri
Expand All @@ -13,12 +28,16 @@ def type
"http.rb"
end

def method
request.verb
def host
if hostname = self['host']
hostname.split(':').first
else
request.host
end
end

def host
request.socket_host
def method
request.verb.upcase
end

def [](key)
Expand Down

0 comments on commit 7a27bc0

Please sign in to comment.