request_id 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -2
- data/lib/rack/request_id.rb +18 -1
- data/lib/request_id.rb +17 -0
- data/lib/request_id/configuration.rb +12 -0
- data/lib/request_id/version.rb +1 -1
- metadata +5 -4
data/README.md
CHANGED
@@ -14,7 +14,7 @@ Throughout the system. It includes:
|
|
14
14
|
Add this line to your application's Gemfile:
|
15
15
|
|
16
16
|
```ruby
|
17
|
-
gem 'request_id'
|
17
|
+
gem 'request_id'
|
18
18
|
```
|
19
19
|
|
20
20
|
## Usage
|
@@ -25,7 +25,6 @@ Add the rack middleware:
|
|
25
25
|
use Rack::RequestId
|
26
26
|
```
|
27
27
|
|
28
|
-
|
29
28
|
### If you're using Sidekiq
|
30
29
|
|
31
30
|
Add the client middleware.
|
data/lib/rack/request_id.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
1
3
|
module Rack
|
2
4
|
|
3
5
|
# Public: Rack middleware that stores the Heroku-Request-Id header in a
|
@@ -23,11 +25,26 @@ module Rack
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def call(env)
|
26
|
-
::RequestId.with_request_id(env
|
28
|
+
::RequestId.with_request_id(request_id(env)) do
|
27
29
|
status, headers, body = @app.call(env)
|
28
30
|
headers[RESPONSE_HEADER] ||= ::RequestId.request_id
|
29
31
|
[status, headers, body]
|
30
32
|
end
|
31
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def request_id(env)
|
38
|
+
env[REQUEST_HEADER] || generate
|
39
|
+
end
|
40
|
+
|
41
|
+
def generate
|
42
|
+
generate? && SecureRandom.hex(16)
|
43
|
+
end
|
44
|
+
|
45
|
+
def generate?
|
46
|
+
::RequestId.configuration.generate
|
47
|
+
end
|
48
|
+
|
32
49
|
end
|
33
50
|
end
|
data/lib/request_id.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'request_id/version'
|
2
2
|
|
3
3
|
module RequestId
|
4
|
+
autoload :Configuration, 'request_id/configuration'
|
5
|
+
|
4
6
|
class << self
|
5
7
|
|
6
8
|
# Public: Retrieve the current request_id, which is generally set by the
|
@@ -50,6 +52,21 @@ module RequestId
|
|
50
52
|
RequestId.request_id = last_request_id
|
51
53
|
end
|
52
54
|
|
55
|
+
def configuration
|
56
|
+
@configuration ||= Configuration.new
|
57
|
+
end
|
58
|
+
|
59
|
+
# Public: Configure RequestId.
|
60
|
+
#
|
61
|
+
# Examples
|
62
|
+
#
|
63
|
+
# RequestId.configure do |config|
|
64
|
+
# config.generate = false
|
65
|
+
# end
|
66
|
+
def configure
|
67
|
+
yield configuration
|
68
|
+
end
|
69
|
+
|
53
70
|
end
|
54
71
|
end
|
55
72
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module RequestId
|
2
|
+
class Configuration
|
3
|
+
# If set to true, the rack middleware will automatically generate a request
|
4
|
+
# id. Useful in development. Defaults to true if this is a rails app an
|
5
|
+
# we're in development.
|
6
|
+
attr_accessor :generate
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@generate = defined?(Rails) && Rails.env.development?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/request_id/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: request_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
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-09-
|
12
|
+
date: 2013-09-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- Rakefile
|
76
76
|
- lib/rack/request_id.rb
|
77
77
|
- lib/request_id.rb
|
78
|
+
- lib/request_id/configuration.rb
|
78
79
|
- lib/request_id/version.rb
|
79
80
|
- lib/sidekiq/middleware/client/request_id.rb
|
80
81
|
- lib/sidekiq/middleware/server/request_id.rb
|
@@ -100,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
101
|
version: '0'
|
101
102
|
segments:
|
102
103
|
- 0
|
103
|
-
hash:
|
104
|
+
hash: -4189853304360477906
|
104
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
106
|
none: false
|
106
107
|
requirements:
|
@@ -109,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
110
|
version: '0'
|
110
111
|
segments:
|
111
112
|
- 0
|
112
|
-
hash:
|
113
|
+
hash: -4189853304360477906
|
113
114
|
requirements: []
|
114
115
|
rubyforge_project:
|
115
116
|
rubygems_version: 1.8.23
|