marlowe 1.0.0

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: 291c85e33c000a88ba28cdccf0be187169ce7e05
4
+ data.tar.gz: 0a0f402e1d0a5a3870d265ef59ea596b008dfb1f
5
+ SHA512:
6
+ metadata.gz: 6f4822e623322547de37cb6fc94f61d7c937fc5712f48eea385678c9c9db4efaa1953a5ff97751a8ab6b0c504fdcda163ced9aa9538be94c331c8645cb9c7732
7
+ data.tar.gz: 1f40c48a8b2cf0f8fc78c50ff951be7aaa7c3b24bf0fce80c730c6c54714a0343cd5931bd70d1eefed08ae8a654034c64537a3e561f6aedb3164f3809bf3b7f6
@@ -0,0 +1,25 @@
1
+ # -*- ruby -*-
2
+
3
+ require "autotest/restart"
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.testlib = "minitest/unit"
7
+ #
8
+ # at.extra_files << "../some/external/dependency.rb"
9
+ #
10
+ # at.libs << ":../some/external"
11
+ #
12
+ # at.add_exception "vendor"
13
+ #
14
+ # at.add_mapping(/dependency.rb/) do |f, _|
15
+ # at.files_matching(/test_.*rb$/)
16
+ # end
17
+ #
18
+ # %w(TestA TestB).each do |klass|
19
+ # at.extra_class_map[klass] = "test/test_misc.rb"
20
+ # end
21
+ # end
22
+
23
+ # Autotest.add_hook :run_command do |at|
24
+ # system "rake build"
25
+ # end
@@ -0,0 +1,4 @@
1
+ === 1.0.0 / 2015-10-16
2
+
3
+ * Initial Commit
4
+
@@ -0,0 +1,27 @@
1
+ cence
2
+
3
+ This software is available under an MIT-style licence.
4
+
5
+ * Copyright 2015 Kinetic Cafe
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
8
+ this software and associated documentation files (the "Software"), to deal in
9
+ the Software without restriction, including without limitation the rights to
10
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
11
+ of the Software, and to permit persons to whom the Software is furnished to do
12
+ so, subject to the following conditions:
13
+
14
+ * The names of its contributors may not be used to endorse or promote
15
+ products derived from this software without specific prior written
16
+ permission.
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
@@ -0,0 +1,11 @@
1
+ .autotest
2
+ History.rdoc
3
+ Licence.rdoc
4
+ Manifest.txt
5
+ README.rdoc
6
+ Rakefile
7
+ lib/marlowe.rb
8
+ lib/marlowe/formatter.rb
9
+ lib/marlowe/middleware.rb
10
+ lib/marlowe/rails.rb
11
+ lib/marlowe/simple_formatter.rb
@@ -0,0 +1,99 @@
1
+ = marlowe
2
+
3
+ == Description
4
+
5
+ {marlowe}[https://github.com/KineticCafe/marlowe] provides a correlation id
6
+ header for Rails and Rack applications to correlate logs for a single request
7
+ across multiple services.
8
+
9
+ == Install
10
+
11
+ You can install it as a gem:
12
+
13
+ $ gem install marlowe
14
+
15
+ or add it into a Gemfile:
16
+
17
+ gem 'marlowe'
18
+
19
+ == Configuration
20
+
21
+ There is no configuration as of yet. Future plans include configuring the name
22
+ of the correlation id header.
23
+
24
+ == Accesing the Correlation ID
25
+
26
+ The correlation id can be accessed throughout the application by accessing the
27
+ {RequestStore}[https://github.com/steveklabnik/request_store] storage.
28
+
29
+ RequestStore[:correlation_id]
30
+
31
+ == Logging
32
+
33
+ For a rails application, you simply need to change the log formatter to one of
34
+ the provided ones. Correlated versions of both the SimpleFormatter and Formatter
35
+ are included.
36
+
37
+ # config/environments/development.rb
38
+ Rails.application.configure do
39
+ config.log_formatter = CorrelatedSimpleFormatter.new
40
+ end
41
+
42
+
43
+ To create your own formatter, you'll need to access the RequestStore storage.
44
+ You can use this pattern if you've rolled your own logger/formatter:
45
+
46
+ # lib/correlated_formatter.rb
47
+ require 'request_store'
48
+
49
+ class CorrelatedSimpleFormatter < ActiveSupport::Logger::SimpleFormatter
50
+ def call(severity, timestamp, progname, msg)
51
+ "[#{RequestStore.store[:correlation_id]}] #{super}"
52
+ end
53
+ end
54
+
55
+
56
+ == Clients
57
+
58
+ Catching and creating the correlation ID is a great all on its own, but to
59
+ really take advantage of the correlation in a service based architecture you'll
60
+ need to pass the id to the next service in the change.
61
+
62
+ Here's an example of a {Hurley}[https://github.com/lostisland/hurley] client:
63
+
64
+ # lib/correlated_client.rb
65
+
66
+ require 'hurley'
67
+ require 'request_store'
68
+
69
+ class Hurley::CorrelatedClient < Hurley::Client
70
+ def initialize(*args, &block)
71
+ super
72
+ header['Correlation-Id'] = ::RequestStore.store[:correlation_id]
73
+ end
74
+ end
75
+
76
+ If you have long-lived Hurley clients, it is also possible to use the Hurley {callback
77
+ machanism}[https://github.com/lostisland/hurley#client-callbacks] to add the
78
+ outgoing headers:
79
+
80
+ client.before_call do |request|
81
+ request.header['Correlation-Id'] = ::RequestStore.store[:correlation_id]
82
+ end
83
+
84
+ or
85
+
86
+ class Correlator
87
+ def name
88
+ :correlator
89
+ end
90
+
91
+ def call(request)
92
+ request.header['Correlation-Id'] = ::RequestStore.store[:correlation_id]
93
+ end
94
+ end
95
+
96
+ client.before_call(Correlator.new)
97
+
98
+
99
+
@@ -0,0 +1,19 @@
1
+ # -*- ruby -*-
2
+
3
+ require "rubygems"
4
+ require "hoe"
5
+
6
+ # Hoe.plugin :compiler
7
+ # Hoe.plugin :gem_prelude_sucks
8
+ # Hoe.plugin :inline
9
+ # Hoe.plugin :minitest
10
+ # Hoe.plugin :racc
11
+ # Hoe.plugin :rcov
12
+ # Hoe.plugin :rdoc
13
+
14
+ Hoe.spec "marlowe" do
15
+ developer("Trevor Oke", "toke@kineticcafe.com")
16
+ license "MIT"
17
+ end
18
+
19
+ # vim: syntax=ruby
@@ -0,0 +1,10 @@
1
+ # Marlowe, a correlation id injector.
2
+ module Marlowe
3
+ VERSION = '1.0.0' #:nodoc:
4
+
5
+ require 'marlowe/middleware'
6
+ require 'marlowe/rails' if defined? Rails::Railtie
7
+
8
+ autoload :Formatter, 'marlowe/formatter'
9
+ autoload :SimpleFormatter, 'marlowe/simple_formatter'
10
+ end
@@ -0,0 +1,14 @@
1
+ require 'request_store'
2
+
3
+ module Marlowe
4
+
5
+ # Marlowe::Formatter is a subclass of +ActiveSupport::Logger::Formatter+
6
+ # that adds a correlation id string to a rails log.
7
+ class Formatter < ActiveSupport::Logger::Formatter
8
+
9
+ # Overrides the formatter return to add the correlation id.
10
+ def call(severity, timestamp, progname, msg)
11
+ "[#{RequestStore.store[:correlation_id]}] #{super}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ require 'rack'
2
+ require 'request_store'
3
+ require 'securerandom'
4
+
5
+ module Marlowe
6
+ # Marlowe correlation id middleware. Including this into your
7
+ # middleware stack will add a 'Correlation-Id' header as an incoming
8
+ # request, and save that id in a request session variable.
9
+
10
+ class Middleware
11
+ # Sets the the rack application to +app+
12
+ def initialize(app)
13
+ @app = app
14
+ end
15
+
16
+ # Stores the incoming correlation id from the +env+ hash. If the correlation
17
+ # id has not been sent, a new UUID is generated and the +env+ is modified.
18
+ def call(env)
19
+ env['HTTP_CORRELATION_ID'] ||= SecureRandom.uuid
20
+ RequestStore.store[:correlation_id] = env['HTTP_CORRELATION_ID']
21
+
22
+ @status, @headers, @response = @app.call(env)
23
+ [@status, @headers, @response]
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ module Marlowe
2
+ class Railtie < Rails::Railtie
3
+ initializer 'marlowe.configure_rails_initialization' do
4
+ app.middleware.insert_before Rails::Rack::Logger, Marlowe::Middleware
5
+ end
6
+
7
+ #:nodoc:
8
+ def app
9
+ Rails.application
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ require 'request_store'
2
+
3
+ module Marlowe
4
+ # Marlowe::SimpleFormatter is a subclass of
5
+ # +ActiveSupport::Logger::SimpleFormatter+ that adds a correlation id
6
+ # string to a rails log.
7
+ class SimpleFormatter < ActiveSupport::Logger::SimpleFormatter
8
+
9
+ # Overrides the formatter return to add the correlation id.
10
+ def call(severity, timestamp, progname, msg)
11
+ "[#{RequestStore.store[:correlation_id]}] #{super}"
12
+ end
13
+ end
14
+ end
15
+
16
+
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: marlowe
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Trevor Oke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hoe
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.14'
41
+ description: "{marlowe}[https://github.com/KineticCafe/marlowe] provides a correlation
42
+ id \nheader for Rails and Rack applications to correlate logs for a single request
43
+ \nacross multiple services."
44
+ email:
45
+ - toke@kineticcafe.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files:
49
+ - History.rdoc
50
+ - Licence.rdoc
51
+ - Manifest.txt
52
+ - README.rdoc
53
+ files:
54
+ - ".autotest"
55
+ - History.rdoc
56
+ - Licence.rdoc
57
+ - Manifest.txt
58
+ - README.rdoc
59
+ - Rakefile
60
+ - lib/marlowe.rb
61
+ - lib/marlowe/formatter.rb
62
+ - lib/marlowe/middleware.rb
63
+ - lib/marlowe/rails.rb
64
+ - lib/marlowe/simple_formatter.rb
65
+ homepage:
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options:
71
+ - "--main"
72
+ - README.rdoc
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.4.8
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: "{marlowe}[https://github.com/KineticCafe/marlowe] provides a correlation
91
+ id header for Rails and Rack applications to correlate logs for a single request
92
+ \ across multiple services."
93
+ test_files: []