newrelic_httprb 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +50 -0
- data/Gemfile +3 -0
- data/README.md +30 -0
- data/Rakefile +9 -0
- data/lib/newrelic/httprb.rb +2 -0
- data/lib/newrelic_httprb/instrumentation.rb +32 -0
- data/lib/newrelic_httprb/version.rb +3 -0
- data/lib/newrelic_httprb/wrappers.rb +51 -0
- data/newrelic_httprb.gemspec +23 -0
- data/test/instrumentation_test.rb +49 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a5ce358b2b7c0674e95e4016e203f2bdae2a26b7
|
4
|
+
data.tar.gz: c3e8633406f8ca4060f5835dfaee977044510350
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e1fb2c7a4b36fb9c7ae2d09add0721ac61aed9f4f64244d05dc6b25bafcd1c18bfa6a424e5e89e769908b55ddc5e51ee694c0ad2318ae825c81bd17218fd3554
|
7
|
+
data.tar.gz: 9e9d326c0d4c66d82e6872ca38bc2f0161c97002fba30f9d3bfb29296aaf9efd06e9b4410e5e9b650667deb47bc541e3afa336443820e71d2ac571fb29098ad7
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# newrelic_httprb
|
2
|
+
|
3
|
+
New Relic instrumentation for http, the gem! (http.rb)
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
* [newrelic_rpm](newrelic/rpm)
|
8
|
+
* [http.rb](httprb/http)
|
9
|
+
|
10
|
+
## Install
|
11
|
+
|
12
|
+
Just add the gem to your Gemfile
|
13
|
+
|
14
|
+
For optional requires, use:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
require 'newrelic/httprb'
|
18
|
+
```
|
19
|
+
|
20
|
+
## License
|
21
|
+
|
22
|
+
(The MIT License)
|
23
|
+
|
24
|
+
Copyright (c) 2016 Tiago Sousa
|
25
|
+
|
26
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
27
|
+
|
28
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
29
|
+
|
30
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
DependencyDetection.defer do
|
2
|
+
named :http_rb
|
3
|
+
|
4
|
+
depends_on do
|
5
|
+
defined?(HTTP) && defined?(HTTP::Client)
|
6
|
+
end
|
7
|
+
|
8
|
+
executes do
|
9
|
+
::NewRelic::Agent.logger.info 'Installing http.rb instrumentation'
|
10
|
+
require 'new_relic/agent/cross_app_tracing'
|
11
|
+
require 'newrelic_httprb/wrappers'
|
12
|
+
end
|
13
|
+
|
14
|
+
executes do
|
15
|
+
class HTTP::Client
|
16
|
+
def perform_with_newrelic_trace(request, options)
|
17
|
+
wrapped_request = ::NewRelicHTTP::HTTPRequest.new(request)
|
18
|
+
|
19
|
+
response = nil
|
20
|
+
::NewRelic::Agent::CrossAppTracing.tl_trace_http_request(wrapped_request) do
|
21
|
+
response = perform_without_newrelic_trace(request, options)
|
22
|
+
::NewRelicHTTP::HTTPResponse.new(response)
|
23
|
+
end
|
24
|
+
|
25
|
+
response
|
26
|
+
end
|
27
|
+
|
28
|
+
alias perform_without_newrelic_trace perform
|
29
|
+
alias perform perform_with_newrelic_trace
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module NewRelicHTTP
|
2
|
+
class HTTPResponse
|
3
|
+
attr_reader :response
|
4
|
+
|
5
|
+
def initialize(response)
|
6
|
+
@response = response
|
7
|
+
end
|
8
|
+
|
9
|
+
def [](key)
|
10
|
+
_, value = response.headers.find { |k,_| key.downcase == k.downcase }
|
11
|
+
value unless value.nil?
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_hash
|
15
|
+
response.headers
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class HTTPRequest
|
20
|
+
attr_reader :request, :uri
|
21
|
+
|
22
|
+
def initialize(request)
|
23
|
+
@request = request
|
24
|
+
@uri = request.uri
|
25
|
+
end
|
26
|
+
|
27
|
+
def type
|
28
|
+
"http.rb"
|
29
|
+
end
|
30
|
+
|
31
|
+
def host
|
32
|
+
if hostname = self['host']
|
33
|
+
hostname.split(':').first
|
34
|
+
else
|
35
|
+
request.host
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def method
|
40
|
+
request.verb.upcase
|
41
|
+
end
|
42
|
+
|
43
|
+
def [](key)
|
44
|
+
request.headers[key]
|
45
|
+
end
|
46
|
+
|
47
|
+
def []=(key, value)
|
48
|
+
request.headers[key] = value
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../lib/newrelic_httprb/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Tiago Sousa"]
|
5
|
+
gem.email = ["tiago.joao@gmail.com"]
|
6
|
+
gem.description = %q{New Relic instrumentation for http.rb}
|
7
|
+
gem.summary = %q{New Relic instrumentation for http.rb}
|
8
|
+
gem.homepage = "https://github.com/Talkdesk/newrelic_httprb"
|
9
|
+
gem.license = "MIT"
|
10
|
+
|
11
|
+
gem.name = "newrelic_httprb"
|
12
|
+
gem.require_paths = ["lib"]
|
13
|
+
gem.version = NewRelicHTTP::VERSION
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
|
18
|
+
gem.add_dependency 'newrelic_rpm', '~> 3.11'
|
19
|
+
gem.add_dependency 'http'
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rake'
|
22
|
+
gem.add_development_dependency 'test-unit'
|
23
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "http"
|
2
|
+
require "test/unit"
|
3
|
+
require "newrelic_rpm"
|
4
|
+
require "newrelic/httprb"
|
5
|
+
|
6
|
+
class HTTPTest < Test::Unit::TestCase
|
7
|
+
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
8
|
+
|
9
|
+
URL = "http://www.google.com/index.html"
|
10
|
+
|
11
|
+
def setup
|
12
|
+
NewRelic::Agent.manual_start
|
13
|
+
@engine = NewRelic::Agent.instance.stats_engine
|
14
|
+
@engine.clear_stats
|
15
|
+
end
|
16
|
+
|
17
|
+
def assert_metrics(*m)
|
18
|
+
m.each do |x|
|
19
|
+
assert @engine.get_stats_no_scope(x), "#{x} not in metrics"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_get
|
24
|
+
response = HTTP.get URL
|
25
|
+
|
26
|
+
assert_match /<head>/i, response.body
|
27
|
+
assert_metrics "External/all",
|
28
|
+
"External/www.google.com/http.rb/GET",
|
29
|
+
"External/allOther",
|
30
|
+
"External/www.google.com/all"
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_post
|
34
|
+
HTTP.post URL
|
35
|
+
|
36
|
+
assert_metrics "External/all",
|
37
|
+
"External/www.google.com/http.rb/POST",
|
38
|
+
"External/allOther",
|
39
|
+
"External/www.google.com/all"
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_ignore
|
43
|
+
NewRelic::Agent.disable_all_tracing do
|
44
|
+
HTTP.get URL
|
45
|
+
end
|
46
|
+
|
47
|
+
assert_empty @engine.to_h
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: newrelic_httprb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tiago Sousa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: newrelic_rpm
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.11'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: http
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: test-unit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: New Relic instrumentation for http.rb
|
70
|
+
email:
|
71
|
+
- tiago.joao@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- lib/newrelic/httprb.rb
|
81
|
+
- lib/newrelic_httprb/instrumentation.rb
|
82
|
+
- lib/newrelic_httprb/version.rb
|
83
|
+
- lib/newrelic_httprb/wrappers.rb
|
84
|
+
- newrelic_httprb.gemspec
|
85
|
+
- test/instrumentation_test.rb
|
86
|
+
homepage: https://github.com/Talkdesk/newrelic_httprb
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.5.1
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: New Relic instrumentation for http.rb
|
110
|
+
test_files:
|
111
|
+
- test/instrumentation_test.rb
|