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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a7fdda3d50c8438774a6685320096f240248134
4
- data.tar.gz: c15b495dd3826cf26c1ee626cc203e61a84f2576
3
+ metadata.gz: e8fe217abd7b34e70a4816265d375e11a9200421
4
+ data.tar.gz: 036330895f4d6518ebcccfc63eaee3b806a0556a
5
5
  SHA512:
6
- metadata.gz: 4d902634019be7e55e40ce4078477a78dc6fd9c78867f2b1c78f562a72170ee989adc1e6d64273b5f23cc18685530007e89a88991f66a8b39947146f88e90ecd
7
- data.tar.gz: 24a7328086863aa5b74f77e2213a3a149519613e858bce9716fa7dd4999eed30c324b44758d63ff458b4fb249335e71751d86d2becd96e322d6351944a7787b8
6
+ metadata.gz: 9c17b2a005ef985a3c8303911c921ffb32f898595855ad74ea90c1c182b658f86e352876c5f92f95da82294898789cc92e1bc04064616e7d2130d597c3f222ef
7
+ data.tar.gz: c748d8e49920eef7aa26e74ab90d824c43d2c258392dcb58e17a6a54afae500f29ac9922fd100f92dbea45b9fbbde84be0813c3dffec7a0a92f2c6f19461e738
@@ -1,3 +1,8 @@
1
+ === 1.0.3 / 2016-01-15
2
+
3
+ * Update Readme example of using available formatted subclass
4
+ * Make the correlation header name configurable
5
+
1
6
  === 1.0.2 / 2015-11-24
2
7
 
3
8
  * Add documentation for using Marlowe with {lograge}[https://github.com/roidrage/lograge]
@@ -18,8 +18,18 @@ or add it into a Gemfile:
18
18
 
19
19
  == Configuration
20
20
 
21
- There is no configuration as of yet. Future plans include configuring the name
22
- of the correlation id header.
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 = CorrelatedSimpleFormatter.new
49
+ config.log_formatter = Marlowe::SimpleFormatter.new
40
50
  end
41
51
 
42
52
 
@@ -1,6 +1,6 @@
1
1
  # Marlowe, a correlation id injector.
2
2
  module Marlowe
3
- VERSION = '1.0.2' #:nodoc:
3
+ VERSION = '1.0.3' #:nodoc:
4
4
 
5
5
  require 'marlowe/middleware'
6
6
  require 'marlowe/rails' if defined? Rails::Railtie
@@ -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 'Correlation-Id' header as an incoming
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['HTTP_CORRELATION_ID'] ||= SecureRandom.uuid
20
- RequestStore.store[:correlation_id] = env['HTTP_CORRELATION_ID']
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
@@ -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:
@@ -4,9 +4,7 @@ gem 'minitest'
4
4
 
5
5
  require 'rack/test'
6
6
  require 'rack/mock'
7
- require 'pry'
8
7
  require 'minitest/autorun'
9
- require 'minitest/pretty_diff'
10
8
  require 'minitest/focus'
11
9
  require 'minitest/moar'
12
10
  require 'minitest/bisect'
@@ -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.2
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: 2015-11-25 00:00:00.000000000 Z
12
+ date: 2016-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: request_store