marlowe 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +5 -0
- data/README.rdoc +13 -3
- data/lib/marlowe.rb +1 -1
- data/lib/marlowe/middleware.rb +14 -4
- data/lib/marlowe/rails.rb +1 -1
- data/test/minitest_config.rb +0 -2
- data/test/test_marlowe.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8fe217abd7b34e70a4816265d375e11a9200421
|
4
|
+
data.tar.gz: 036330895f4d6518ebcccfc63eaee3b806a0556a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c17b2a005ef985a3c8303911c921ffb32f898595855ad74ea90c1c182b658f86e352876c5f92f95da82294898789cc92e1bc04064616e7d2130d597c3f222ef
|
7
|
+
data.tar.gz: c748d8e49920eef7aa26e74ab90d824c43d2c258392dcb58e17a6a54afae500f29ac9922fd100f92dbea45b9fbbde84be0813c3dffec7a0a92f2c6f19461e738
|
data/History.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -18,8 +18,18 @@ or add it into a Gemfile:
|
|
18
18
|
|
19
19
|
== Configuration
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
To configure the header where Marlowe looks for and puts the correlation id:
|
22
|
+
|
23
|
+
- In Rails, specify the header in your environment configuration:
|
24
|
+
|
25
|
+
config.marlowe_correlation_header = "My-Correlation-Id"
|
26
|
+
|
27
|
+
- If you are adding the middleware to a Rack application directly, pass it as an option:
|
28
|
+
|
29
|
+
use Marlowe::Middleware, correlation_header: "My-Correlation-Id"
|
30
|
+
|
31
|
+
(Note that HTTP headers are case insensitive. In the Rack `env`, this header name is actually
|
32
|
+
represented as `env['HTTP_MY_CORRELATION_ID']`.)
|
23
33
|
|
24
34
|
== Accesing the Correlation ID
|
25
35
|
|
@@ -36,7 +46,7 @@ are included.
|
|
36
46
|
|
37
47
|
# config/environments/development.rb
|
38
48
|
Rails.application.configure do
|
39
|
-
config.log_formatter =
|
49
|
+
config.log_formatter = Marlowe::SimpleFormatter.new
|
40
50
|
end
|
41
51
|
|
42
52
|
|
data/lib/marlowe.rb
CHANGED
data/lib/marlowe/middleware.rb
CHANGED
@@ -4,23 +4,33 @@ require 'securerandom'
|
|
4
4
|
|
5
5
|
module Marlowe
|
6
6
|
# Marlowe correlation id middleware. Including this into your
|
7
|
-
# middleware stack will add a
|
7
|
+
# middleware stack will add a correlation id header as an incoming
|
8
8
|
# request, and save that id in a request session variable.
|
9
9
|
|
10
|
+
# Name of the default header to look for and put the correlation id in.
|
11
|
+
CORRELATION_HEADER = 'Correlation-Id'.freeze
|
12
|
+
|
10
13
|
class Middleware
|
11
14
|
# Sets the the rack application to +app+
|
12
|
-
def initialize(app)
|
15
|
+
def initialize(app, opts={})
|
13
16
|
@app = app
|
17
|
+
@correlation_header = format_http_header(opts[:correlation_header] || Marlowe::CORRELATION_HEADER)
|
14
18
|
end
|
15
19
|
|
16
20
|
# Stores the incoming correlation id from the +env+ hash. If the correlation
|
17
21
|
# id has not been sent, a new UUID is generated and the +env+ is modified.
|
18
22
|
def call(env)
|
19
|
-
env[
|
20
|
-
RequestStore.store[:correlation_id] = env[
|
23
|
+
env[@correlation_header] ||= SecureRandom.uuid
|
24
|
+
RequestStore.store[:correlation_id] = env[@correlation_header]
|
21
25
|
|
22
26
|
@status, @headers, @response = @app.call(env)
|
23
27
|
[@status, @headers, @response]
|
24
28
|
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def format_http_header(header)
|
33
|
+
("HTTP_" + header.gsub(/-/, '_').upcase).freeze
|
34
|
+
end
|
25
35
|
end
|
26
36
|
end
|
data/lib/marlowe/rails.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Marlowe
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
initializer 'marlowe.configure_rails_initialization' do
|
4
|
-
app.middleware.insert_before Rails::Rack::Logger, Marlowe::Middleware
|
4
|
+
app.middleware.insert_before Rails::Rack::Logger, Marlowe::Middleware, correlation_header: Rails.application.config.try(:marlowe_correlation_header)
|
5
5
|
end
|
6
6
|
|
7
7
|
#:nodoc:
|
data/test/minitest_config.rb
CHANGED
data/test/test_marlowe.rb
CHANGED
@@ -16,4 +16,17 @@ class TestMarlowe < Minitest::Test
|
|
16
16
|
refute_empty @app.coordination_id
|
17
17
|
assert_equal 'testvalue', @app.coordination_id
|
18
18
|
end
|
19
|
+
|
20
|
+
def test_with_custom_no_header
|
21
|
+
@customized_middleware = Marlowe::Middleware.new(@app, correlation_header: "Custom-Header")
|
22
|
+
@customized_middleware.call({})
|
23
|
+
refute_empty @app.coordination_id
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_with_custom_header
|
27
|
+
@customized_middleware = Marlowe::Middleware.new(@app, correlation_header: "Custom-Header")
|
28
|
+
@customized_middleware.call({'HTTP_CUSTOM_HEADER' => 'testvalue'})
|
29
|
+
refute_empty @app.coordination_id
|
30
|
+
assert_equal 'testvalue', @app.coordination_id
|
31
|
+
end
|
19
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marlowe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trevor Oke
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-01-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: request_store
|