newrelic-middleware 1.0.0

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in newrelic-middleware.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 twinturbo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # New Relic: Middleware
2
+
3
+ Use this middleware to see how long your app is spending in middleware.
4
+
5
+ It does not track per middleware.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'newrelic-middleware'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install newrelic-middleware
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ use NewRelicMiddleware::TrackingSupport
25
+ run MyApp
26
+ ```
27
+
28
+ No integration is required for Rails. It will add itself.
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'test'
7
+ test.pattern = 'test/**/*_test.rb'
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ require "newrelic-middleware/version"
2
+
3
+ module NewRelicMiddleware
4
+ class TrackingSupport
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ env["HTTP_X_MIDDLEWARE_START"] = "t=#{(Time.now.to_f * 1000000).to_i}"
11
+ @app.call env
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ module NewRelicMiddleware
2
+ class Engine < ::Rails::Engine
3
+ initializer "newrelic.middleware-tracking" do |app|
4
+ app.config.middleware.insert 0, TrackingSupport
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module NewRelicMiddleware
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/newrelic-middleware/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["twinturbo"]
6
+ gem.email = ["me@broadcastingadam.com"]
7
+ gem.description = %q{Track time spent your middleware stack with New Relic}
8
+ gem.summary = %q{}
9
+ gem.homepage = "https://github.com/twinturbo/newrelic-middleware"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "newrelic-middleware"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = NewRelicMiddleware::VERSION
17
+
18
+ gem.add_development_dependency "rails"
19
+ gem.add_development_dependency "rack-test"
20
+ end
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+
3
+ class MiddlewareTest < MiniTest::Unit::TestCase
4
+ include Rack::Test::Methods
5
+
6
+ def app
7
+ TestApp
8
+ end
9
+
10
+ def test_adds_a_start_time_header
11
+ get '/'
12
+ assert last_response.ok?
13
+ assert last_response.headers['HTTP_X_MIDDLEWARE_START']
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class RailsIntegrationTest < MiniTest::Unit::TestCase
4
+ def test_loads_middleware
5
+ middleware = TestRailsApp.config.middleware
6
+ assert_equal NewRelicMiddleware::TrackingSupport, middleware.first.klass
7
+ end
8
+ end
@@ -0,0 +1,32 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'newrelic-middleware'
5
+
6
+ require 'minitest/unit'
7
+ require 'minitest/pride'
8
+ require 'minitest/autorun'
9
+
10
+ require 'rack/test'
11
+
12
+ class HelloWorld
13
+ def self.call(env)
14
+ [200, env.slice('HTTP_X_MIDDLEWARE_START'), ["Hi"]]
15
+ end
16
+ end
17
+
18
+ TestApp = Rack::Builder.new do
19
+ use NewRelicMiddleware::TrackingSupport
20
+ run HelloWorld
21
+ end
22
+
23
+ ENV['RAILS_ENV'] = "test"
24
+
25
+ require 'rails'
26
+ require 'action_controller/railtie'
27
+ require 'newrelic-middleware/railtie'
28
+
29
+ class TestRailsApp < Rails::Application
30
+ config.active_support.deprecation = proc { |message, stack| }
31
+ initialize!
32
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: newrelic-middleware
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - twinturbo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &70156941959980 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70156941959980
25
+ - !ruby/object:Gem::Dependency
26
+ name: rack-test
27
+ requirement: &70156941959560 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70156941959560
36
+ description: Track time spent your middleware stack with New Relic
37
+ email:
38
+ - me@broadcastingadam.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - LICENSE
46
+ - README.md
47
+ - Rakefile
48
+ - lib/newrelic-middleware.rb
49
+ - lib/newrelic-middleware/railtie.rb
50
+ - lib/newrelic-middleware/version.rb
51
+ - newrelic-middleware.gemspec
52
+ - test/middleware_test.rb
53
+ - test/rails_test.rb
54
+ - test/test_helper.rb
55
+ homepage: https://github.com/twinturbo/newrelic-middleware
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ segments:
68
+ - 0
69
+ hash: 2035928544990081540
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ segments:
77
+ - 0
78
+ hash: 2035928544990081540
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.11
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: ''
85
+ test_files:
86
+ - test/middleware_test.rb
87
+ - test/rails_test.rb
88
+ - test/test_helper.rb