heroku-request-id 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 82a2faf66bd7a74a8491db5c8c829b73b703fdde
4
+ data.tar.gz: 35486a3a476614e2944d2cb6dbc10603dccc4586
5
+ SHA512:
6
+ metadata.gz: 285cfc49dfe52fe0d60bd8dccb478c925c86e0a93627db65648cf8fef5cc72159d2ac75ca571ca95988d6a647984a37c04d390d8b08d76ecdc9477e4c4aa6a43
7
+ data.tar.gz: bf01e0150a1d42f4e36043ad3f09c52cb62451a2491e5b4e81dfa93e59c4197d12ebb5b28f8a70c48e3690bf0770431eb6ce16b660222ed393c3b9c367739e3d
@@ -36,7 +36,7 @@ module HerokuRequestId
36
36
  end
37
37
 
38
38
  def call(env)
39
- @start = Time.now
39
+ @env = env
40
40
  @request_id = env['HTTP_HEROKU_REQUEST_ID']
41
41
  env["HTTP_X_REQUEST_ID"] = @request_id if self.class.x_request_id_replication
42
42
  @status, @headers, @response = @app.call(env)
@@ -44,16 +44,26 @@ module HerokuRequestId
44
44
  end
45
45
 
46
46
  def each(&block)
47
- @stop = Time.now
48
- @elapsed = @stop - @start
47
+ msg = build_msg
49
48
  if self.class.html_comment && @headers["Content-Type"] && @headers["Content-Type"].include?("text/html")
50
- block.call("<!-- Heroku request id : #{@request_id} - Elapsed time : #{@elapsed} -->\n")
49
+ block.call("<!-- #{msg} -->\n")
51
50
  end
52
51
  if self.class.log_line
53
- $stdout.puts("heroku-request-id=#{@request_id} measure=\"rack-request\" elapsed=#{@elapsed}")
52
+ $stdout.puts(msg)
54
53
  end
55
54
  @response.each(&block)
56
55
  end
56
+
57
+ def build_msg
58
+ elapsed = @env['X-Runtime']
59
+ msg = %[Heroku request id : #{@request_id}]
60
+ if elapsed && elapsed.strip != ""
61
+ msg += %[ - Elapsed time (from Rack::Runtime) : #{elapsed}]
62
+ else
63
+ msg += %[ - Runtime info not available. (Use Rack::Runtime)]
64
+ end
65
+ msg
66
+ end
57
67
 
58
68
  end
59
69
  end
@@ -1,7 +1,7 @@
1
1
  module HerokuRequestId
2
2
  class Railtie < Rails::Railtie
3
3
  initializer 'heroku_request_id.add_middleware' do |app|
4
- app.config.middleware.insert 0, "HerokuRequestId::Middleware"
4
+ app.config.middleware.insert_before "Rack::Runtime", "HerokuRequestId::Middleware"
5
5
  end
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module HerokuRequestId
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -10,19 +10,33 @@ describe HerokuRequestId::Middleware do
10
10
 
11
11
  let(:app) { HerokuRequestId::Middleware.new(inner_app) }
12
12
 
13
- subject do
14
- capture_stdout { get("/", {}, { "HTTP_HEROKU_REQUEST_ID" => "the_id_string" }) }
13
+ let(:request_without_rack_runtime)do
14
+ capture_stdout{ get("/", {}, {"HTTP_HEROKU_REQUEST_ID" => "the_id_string"}) }
15
+ end
16
+
17
+ let(:request_with_rack_runtime)do
18
+ capture_stdout{ get("/", {}, {"HTTP_HEROKU_REQUEST_ID" => "the_id_string","X-Runtime" => "42"}) }
15
19
  end
16
20
 
17
21
  it "prints the request id to stdout by default" do
18
- output = subject
19
- output.should match("heroku-request-id")
22
+ output = request_without_rack_runtime
23
+ output.should match("Heroku request id")
20
24
  output.should match("the_id_string")
21
25
  end
22
26
 
27
+ it "Does not include runtime information if the 'X-Runtime' header is not present" do
28
+ output = request_without_rack_runtime
29
+ output.should match("Runtime info not available")
30
+ end
31
+
32
+ it "Does include runtime information if the 'X-Runtime' header is present" do
33
+ output = request_with_rack_runtime
34
+ output.should match("Elapsed time")
35
+ end
36
+
23
37
  it "does not print the request id to stdout if log_line == false" do
24
38
  HerokuRequestId::Middleware.log_line = false
25
- output = subject
39
+ output = request_without_rack_runtime
26
40
  output.should_not match("heroku-request-id")
27
41
  output.should_not match("the_id_string")
28
42
  # reset html_comment so that random test order works
@@ -30,14 +44,14 @@ describe HerokuRequestId::Middleware do
30
44
  end
31
45
 
32
46
  it "does not add a comment with the Heroku request id by default" do
33
- subject
47
+ request_without_rack_runtime
34
48
  last_response.body.should_not match("Heroku request id")
35
49
  last_response.body.should_not match("the_id_string")
36
50
  end
37
51
 
38
52
  it "does add a comment with the Heroku request id if html_comment == true" do
39
53
  HerokuRequestId::Middleware.html_comment = true
40
- subject
54
+ request_without_rack_runtime
41
55
  last_response.body.should match("Heroku request id")
42
56
  last_response.body.should match("the_id_string")
43
57
  # reset html_comment so that random test order works
@@ -45,7 +59,7 @@ describe HerokuRequestId::Middleware do
45
59
  end
46
60
 
47
61
  it "makes no change to response status" do
48
- subject
62
+ request_without_rack_runtime
49
63
  last_response.should be_ok
50
64
  end
51
65
 
@@ -60,6 +74,9 @@ describe HerokuRequestId::Middleware do
60
74
  }
61
75
  end
62
76
  let(:app){ HerokuRequestId::Middleware.new(inner_app) }
77
+ subject do
78
+ capture_stdout { get("/", {}, { "HTTP_HEROKU_REQUEST_ID" => "the_id_string" }) }
79
+ end
63
80
  context "by default" do
64
81
  it "does not replicate the heroku header into rails header" do
65
82
  subject
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku-request-id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
5
- prerelease:
4
+ version: 0.0.8
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jeremy Green
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-31 00:00:00.000000000 Z
11
+ date: 2013-06-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,49 +27,43 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rack-test
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  description: Simple Rack middleware to log the heroku request id and write it to the
@@ -100,33 +91,26 @@ files:
100
91
  homepage: https://github.com/Octo-Labs/heroku-request-id
101
92
  licenses:
102
93
  - MIT
94
+ metadata: {}
103
95
  post_install_message:
104
96
  rdoc_options: []
105
97
  require_paths:
106
98
  - lib
107
99
  required_ruby_version: !ruby/object:Gem::Requirement
108
- none: false
109
100
  requirements:
110
- - - ! '>='
101
+ - - '>='
111
102
  - !ruby/object:Gem::Version
112
103
  version: '0'
113
- segments:
114
- - 0
115
- hash: 2380672724000137210
116
104
  required_rubygems_version: !ruby/object:Gem::Requirement
117
- none: false
118
105
  requirements:
119
- - - ! '>='
106
+ - - '>='
120
107
  - !ruby/object:Gem::Version
121
108
  version: '0'
122
- segments:
123
- - 0
124
- hash: 2380672724000137210
125
109
  requirements: []
126
110
  rubyforge_project:
127
- rubygems_version: 1.8.25
111
+ rubygems_version: 2.0.3
128
112
  signing_key:
129
- specification_version: 3
113
+ specification_version: 4
130
114
  summary: Simple Rack middleware to log the heroku request id and write it to the end
131
115
  of html requests. Both optionally, of course.
132
116
  test_files: