Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 8002d50755fc25ed7338de0f33dbc8a98cb94020 0 parents
twinturbo authored
17 .gitignore
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
4 Gemfile
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in newrelic-middleware.gemspec
+gemspec
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 twinturbo
+
+MIT License
+
+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:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+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.
36 README.md
@@ -0,0 +1,36 @@
+# New Relic: Middleware
+
+Use this middleware to see how long your app is spending in middleware.
+
+It does not track per middleware.
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'newrelic-middleware'
+
+And then execute:
+
+ $ bundle
+
+Or install it yourself as:
+
+ $ gem install newrelic-middleware
+
+## Usage
+
+```ruby
+use NewRelicMiddleware::TrackingSupport
+run MyApp
+```
+
+No integration is required for Rails. It will add itself.
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Added some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
10 Rakefile
@@ -0,0 +1,10 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
+
+require 'rake/testtask'
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'test'
+ test.pattern = 'test/**/*_test.rb'
+end
+
+task :default => :test
14 lib/newrelic-middleware.rb
@@ -0,0 +1,14 @@
+require "newrelic-middleware/version"
+
+module NewRelicMiddleware
+ class TrackingSupport
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ env["HTTP_X_MIDDLEWARE_START"] = "t=#{(Time.now.to_f * 1000000).to_i}"
+ @app.call env
+ end
+ end
+end
7 lib/newrelic-middleware/railtie.rb
@@ -0,0 +1,7 @@
+module NewRelicMiddleware
+ class Engine < ::Rails::Engine
+ initializer "newrelic.middleware-tracking" do |app|
+ app.config.middleware.insert 0, TrackingSupport
+ end
+ end
+end
3  lib/newrelic-middleware/version.rb
@@ -0,0 +1,3 @@
+module NewRelicMiddleware
+ VERSION = "1.0.0"
+end
20 newrelic-middleware.gemspec
@@ -0,0 +1,20 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/newrelic-middleware/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["twinturbo"]
+ gem.email = ["me@broadcastingadam.com"]
+ gem.description = %q{TODO: Write a gem description}
+ gem.summary = %q{TODO: Write a gem summary}
+ gem.homepage = ""
+
+ gem.files = `git ls-files`.split($\)
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
+ gem.name = "newrelic-middleware"
+ gem.require_paths = ["lib"]
+ gem.version = NewRelicMiddleware::VERSION
+
+ gem.add_development_dependency "rails"
+ gem.add_development_dependency "rack-test"
+end
15 test/middleware_test.rb
@@ -0,0 +1,15 @@
+require 'test_helper'
+
+class MiddlewareTest < MiniTest::Unit::TestCase
+ include Rack::Test::Methods
+
+ def app
+ TestApp
+ end
+
+ def test_adds_a_start_time_header
+ get '/'
+ assert last_response.ok?
+ assert last_response.headers['HTTP_X_MIDDLEWARE_START']
+ end
+end
8 test/rails_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class RailsIntegrationTest < MiniTest::Unit::TestCase
+ def test_loads_middleware
+ middleware = TestRailsApp.config.middleware
+ assert_equal NewRelicMiddleware::TrackingSupport, middleware.first.klass
+ end
+end
32 test/test_helper.rb
@@ -0,0 +1,32 @@
+require 'simplecov'
+SimpleCov.start
+
+require 'newrelic-middleware'
+
+require 'minitest/unit'
+require 'minitest/pride'
+require 'minitest/autorun'
+
+require 'rack/test'
+
+class HelloWorld
+ def self.call(env)
+ [200, env.slice('HTTP_X_MIDDLEWARE_START'), ["Hi"]]
+ end
+end
+
+TestApp = Rack::Builder.new do
+ use NewRelicMiddleware::TrackingSupport
+ run HelloWorld
+end
+
+ENV['RAILS_ENV'] = "test"
+
+require 'rails'
+require 'action_controller/railtie'
+require 'newrelic-middleware/railtie'
+
+class TestRailsApp < Rails::Application
+ config.active_support.deprecation = proc { |message, stack| }
+ initialize!
+end
Please sign in to comment.
Something went wrong with that request. Please try again.