heroku-request-id 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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
18
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in heroku-request-id.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jeremy Green
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,29 @@
1
+ # Heroku::Request::Id
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'heroku-request-id'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install heroku-request-id
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'heroku-request-id/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "heroku-request-id"
8
+ spec.version = HerokuRequestId::VERSION
9
+ spec.authors = ["Jeremy Green"]
10
+ spec.email = ["jeremy@octolabs.com"]
11
+ spec.description = %q{Simple Rack middleware to log the heroku request id and write it to the end of html requests. Both optionally, of course.}
12
+ spec.summary = %q{Simple Rack middleware to log the heroku request id and write it to the end of html requests. Both optionally, of course.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "rack-test"
25
+ end
@@ -0,0 +1,7 @@
1
+ require "heroku-request-id/version"
2
+ require "heroku-request-id/middleware"
3
+ require "heroku-request-id/railtie" if defined?(Rails::Railtie)
4
+
5
+ module HerokuRequestId
6
+
7
+ end
@@ -0,0 +1,50 @@
1
+ module HerokuRequestId
2
+ class Middleware
3
+
4
+ def initialize(app)
5
+ @app = app
6
+ html_comment = true
7
+ end
8
+
9
+ @@html_comment = true
10
+
11
+ def self.html_comment
12
+ @@html_comment
13
+ end
14
+
15
+ def self.html_comment= hc
16
+ @@html_comment = hc
17
+ end
18
+
19
+ @@log_line = false
20
+
21
+ def self.log_line
22
+ @@log_line
23
+ end
24
+
25
+ def self.log_line= hc
26
+ @@log_line = hc
27
+ end
28
+
29
+ def call(env)
30
+ @start = Time.now
31
+ @request_id = env['HTTP_HEROKU_REQUEST_ID']
32
+ @status, @headers, @response = @app.call(env)
33
+ @stop = Time.now
34
+ @elapsed = @stop - @start
35
+ if self.class.log_line
36
+ $stdout.puts("heroku-request-id=#{env['HTTP_HEROKU_REQUEST_ID']} measure=\"rack-request\" elapsed=#{@elapsed}")
37
+ end
38
+ [@status, @headers, self]
39
+ end
40
+
41
+ def each(&block)
42
+ puts "html_comment = #{self.class.html_comment}"
43
+ if self.class.html_comment && @headers["Content-Type"].include?("text/html")
44
+ block.call("<!-- Heroku request id : #{@request_id} - Elapsed time : #{@elapsed} -->\n")
45
+ end
46
+ @response.each(&block)
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,7 @@
1
+ module HerokuRequestId
2
+ class Railtie < Rails::Railtie
3
+ initializer 'heroku_request_id.add_middleware' do |app|
4
+ app.config.middleware.insert_after 'Rack::Lock', "HerokuRequestId::Middleware"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module HerokuRequestId
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe HerokuRequestId::Middleware do
4
+
5
+ include Rack::Test::Methods
6
+
7
+ let(:inner_app) do
8
+ lambda { |env| [200, {'Content-Type' => 'text/html'}, ['<body>All good!</body>']] }
9
+ end
10
+
11
+ let(:app) { HerokuRequestId::Middleware.new(inner_app) }
12
+
13
+ it "prints the request id to stdout if log_line == true" do
14
+ HerokuRequestId::Middleware.log_line = true
15
+ output = capture_stdout { get "/" }
16
+ output.should match("heroku-request-id")
17
+ # reset html_comment so that random test order works
18
+ HerokuRequestId::Middleware.log_line = false
19
+ end
20
+
21
+ it "does not print the request id to stdout by default" do
22
+ output = capture_stdout { get "/" }
23
+ output.should_not match("heroku-request-id")
24
+ end
25
+
26
+ it "adds a comment with the Heroku request id" do
27
+ capture_stdout { get "/" }
28
+ last_response.body.should match("Heroku request id")
29
+ end
30
+
31
+ it "does not add a comment with the Heroku request id if html_comment == false" do
32
+ HerokuRequestId::Middleware.html_comment = false
33
+ capture_stdout { get "/" }
34
+ last_response.body.should_not match("Heroku request id")
35
+ # reset html_comment so that random test order works
36
+ HerokuRequestId::Middleware.html_comment = true
37
+ end
38
+
39
+ it "makes no change to response status" do
40
+ capture_stdout { get "/" }
41
+ last_response.should be_ok
42
+ end
43
+
44
+ end
@@ -0,0 +1,22 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require "#{File.dirname(__FILE__)}/../lib/heroku-request-id"
9
+ require "#{File.dirname(__FILE__)}/support/capture_stdout"
10
+ require 'rack/test'
11
+
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ config.order = 'random'
22
+ end
@@ -0,0 +1,10 @@
1
+ def capture_stdout(&block)
2
+ original_stdout = $stdout
3
+ $stdout = fake = StringIO.new
4
+ begin
5
+ yield
6
+ ensure
7
+ $stdout = original_stdout
8
+ end
9
+ fake.string
10
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heroku-request-id
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeremy Green
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rack-test
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Simple Rack middleware to log the heroku request id and write it to the
79
+ end of html requests. Both optionally, of course.
80
+ email:
81
+ - jeremy@octolabs.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - .rspec
88
+ - Gemfile
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - heroku-request-id.gemspec
93
+ - lib/heroku-request-id.rb
94
+ - lib/heroku-request-id/middleware.rb
95
+ - lib/heroku-request-id/railtie.rb
96
+ - lib/heroku-request-id/version.rb
97
+ - spec/heroku-request-id/middleware_spec.rb
98
+ - spec/spec_helper.rb
99
+ - spec/support/capture_stdout.rb
100
+ homepage: ''
101
+ licenses:
102
+ - MIT
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ segments:
114
+ - 0
115
+ hash: 1702138710006759316
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ segments:
123
+ - 0
124
+ hash: 1702138710006759316
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 1.8.24
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: Simple Rack middleware to log the heroku request id and write it to the end
131
+ of html requests. Both optionally, of course.
132
+ test_files:
133
+ - spec/heroku-request-id/middleware_spec.rb
134
+ - spec/spec_helper.rb
135
+ - spec/support/capture_stdout.rb