rack-instruments 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack/instruments.rb +13 -2
- metadata +2 -2
data/lib/rack/instruments.rb
CHANGED
@@ -4,13 +4,14 @@ require "slides"
|
|
4
4
|
module Rack
|
5
5
|
class Instruments
|
6
6
|
UUID_PATTERN =
|
7
|
-
/\A[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}\Z/
|
7
|
+
/\A([a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}|[a-f0-9]{32})\Z/
|
8
8
|
|
9
9
|
def initialize(app, options={})
|
10
10
|
@app = app
|
11
11
|
|
12
12
|
@context = options[:context]
|
13
13
|
@header_request_ids = options.fetch(:header_request_ids, true)
|
14
|
+
@heroku_request_id = options.fetch(:heroku_request_id, true)
|
14
15
|
@ignore_extensions = options.fetch(:ignore_extensions,
|
15
16
|
%w{css gif ico jpg js jpeg pdf png})
|
16
17
|
@request_id_generator = options.fetch(:request_id_generator,
|
@@ -24,7 +25,7 @@ module Rack
|
|
24
25
|
env["REQUEST_PATH"] =~ /\.#{ext}$/
|
25
26
|
}
|
26
27
|
|
27
|
-
request_ids = [
|
28
|
+
request_ids = [current_request_id(env)]
|
28
29
|
status, headers, response = nil, nil, nil
|
29
30
|
|
30
31
|
# make ID of the request accessible to consumers down the stack
|
@@ -64,5 +65,15 @@ module Rack
|
|
64
65
|
end
|
65
66
|
request_ids
|
66
67
|
end
|
68
|
+
|
69
|
+
# uses Heroku-Request-Id or falls back to a generator
|
70
|
+
def current_request_id(env)
|
71
|
+
if @heroku_request_id && env["HTTP_HEROKU_REQUEST_ID"] &&
|
72
|
+
env["HTTP_HEROKU_REQUEST_ID"] =~ @request_id_pattern
|
73
|
+
env["HTTP_HEROKU_REQUEST_ID"]
|
74
|
+
else
|
75
|
+
@request_id_generator.call
|
76
|
+
end
|
77
|
+
end
|
67
78
|
end
|
68
79
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-instruments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: slides
|