faraday-zipkin 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDY4YWE5Y2M1NTA1Mzg3ZDUzN2U1MmJkNDU3ZDQ1YjNiYjBiZGFjOQ==
5
+ data.tar.gz: !binary |-
6
+ MWFmOTVjMWIyOGEwZjRkODc2MDQ5YTY0ZWNiMWVmZTFmMDRlMDZhNA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NjhiMzE5YWRlNzE3ZWVjODU3ZWYzZTI0ZTg4ZjIwMzQ0NDZmODI1YzVmMzVj
10
+ NWY2MmYyZTJjMDM4NDI4MmZmNjMzN2I2YjZiMmU5OWI2ODRkMGJiY2QxYTkx
11
+ NmEwN2ViNzQwM2I2OGVkOTQ5ZGZmNzZkOWJjYzNhMmVjMjUwZTQ=
12
+ data.tar.gz: !binary |-
13
+ MTAxZTc4NDEzNzgyZTVjNmM4NWVlZWUzYTBmNzQ1ZTI5YjZhNjhhNjIyOWJm
14
+ MTBiZjI0Y2FlODE5Y2U3NzViNDE1M2Y2MDE2NTZhM2ZmZWUzM2FjOWZkNDA0
15
+ YjM4MjQ2MzhkYjM1ZDkyNDU3ZTViZGU5ZDU5OTcyZWFkNmMzNGU=
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in faraday-zipkin.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ariel Salomon
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Faraday::Zipkin
2
+
3
+ Faraday middleware to generate Zipkin tracing headers.
4
+
5
+ Note that you should also be using the zipkin-tracer Rack middleware
6
+ to generate trace IDs around your requests:
7
+ https://github.com/twitter/zipkin/tree/master/zipkin-gems/zipkin-tracer
8
+
9
+ Zipkin tracing headers are documented at
10
+ https://github.com/twitter/zipkin/blob/master/doc/collector-api.md
11
+
12
+ ## Usage
13
+
14
+ Include Faraday::Zipkin::TraceHeaders as a Faraday middleware:
15
+
16
+ require 'faraday'
17
+ require 'faraday/zipkin'
18
+
19
+ conn = Faraday.new(:url => 'http://localhost:9292/') do |faraday|
20
+ faraday.use Faraday::Zipkin::TraceHeaders
21
+ # default Faraday stack
22
+ faraday.request :url_encoded
23
+ faraday.adapter Faraday.default_adapter
24
+ end
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it ( https://github.com/[my-github-username]/faraday-zipkin/fork )
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'faraday/zipkin/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "faraday-zipkin"
8
+ spec.version = Faraday::Zipkin::VERSION
9
+ spec.authors = ["Ariel Salomon"]
10
+ spec.email = ["asalomon@lookout.com"]
11
+ spec.summary = %q{Faraday middleware to generate Zipkin tracing headers.}
12
+ spec.description = %q{Faraday middleware to generate Zipkin tracing headers.}
13
+ spec.homepage = "https://github.com/Oscil8/faraday-zipkin"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "faraday", ">= 0.8"
22
+ spec.add_dependency "thrift", "~> 0.9.0"
23
+ spec.add_dependency "finagle-thrift", "~> 1.3.0"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "thin" # required for finagle-thrift
29
+ end
@@ -0,0 +1,5 @@
1
+ module Faraday
2
+ module Zipkin
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ require 'faraday'
2
+ require 'finagle-thrift'
3
+ require 'finagle-thrift/trace'
4
+
5
+ require "faraday/zipkin/version"
6
+
7
+ module Faraday
8
+ module Zipkin
9
+ class TraceHeaders < ::Faraday::Middleware
10
+ B3_HEADERS = {
11
+ :trace_id => "X-B3-TraceId",
12
+ :parent_id => "X-B3-ParentSpanId",
13
+ :span_id => "X-B3-SpanId",
14
+ :sampled => "X-B3-Sampled",
15
+ :flags => "X-B3-Flags"
16
+ }.freeze
17
+
18
+ def initialize(app)
19
+ @app = app
20
+ end
21
+
22
+ def call(env)
23
+ trace_id = ::Trace.id
24
+ B3_HEADERS.each do |method, header|
25
+ env[:request_headers][header] = trace_id.send(method).to_s
26
+ end
27
+ @app.call(env)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,80 @@
1
+ require 'faraday/zipkin'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
6
+ # file to always be loaded, without a need to explicitly require it in any files.
7
+ #
8
+ # Given that it is always loaded, you are encouraged to keep this file as
9
+ # light-weight as possible. Requiring heavyweight dependencies from this file
10
+ # will add to the boot time of your test suite on EVERY test run, even for an
11
+ # individual file that may not need all of that loaded. Instead, make a
12
+ # separate helper file that requires this one and then use it only in the specs
13
+ # that actually need it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # The settings below are suggested to provide a good initial experience
21
+ # with RSpec, but feel free to customize to your heart's content.
22
+ =begin
23
+ # These two settings work together to allow you to limit a spec run
24
+ # to individual examples or groups you care about by tagging them with
25
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
26
+ # get run.
27
+ config.filter_run :focus
28
+ config.run_all_when_everything_filtered = true
29
+
30
+ # Many RSpec users commonly either run the entire suite or an individual
31
+ # file, and it's useful to allow more verbose output when running an
32
+ # individual spec file.
33
+ if config.files_to_run.one?
34
+ # Use the documentation formatter for detailed output,
35
+ # unless a formatter has already been configured
36
+ # (e.g. via a command-line flag).
37
+ config.default_formatter = 'doc'
38
+ end
39
+
40
+ # Print the 10 slowest examples and example groups at the
41
+ # end of the spec run, to help surface which specs are running
42
+ # particularly slow.
43
+ config.profile_examples = 10
44
+
45
+ # Run specs in random order to surface order dependencies. If you find an
46
+ # order dependency and want to debug it, you can fix the order by providing
47
+ # the seed, which is printed after each run.
48
+ # --seed 1234
49
+ config.order = :random
50
+
51
+ # Seed global randomization in this process using the `--seed` CLI option.
52
+ # Setting this allows you to use `--seed` to deterministically reproduce
53
+ # test failures related to randomization by passing the same `--seed` value
54
+ # as the one that triggered the failure.
55
+ Kernel.srand config.seed
56
+
57
+ # rspec-expectations config goes here. You can use an alternate
58
+ # assertion/expectation library such as wrong or the stdlib/minitest
59
+ # assertions if you prefer.
60
+ config.expect_with :rspec do |expectations|
61
+ # Enable only the newer, non-monkey-patching expect syntax.
62
+ # For more details, see:
63
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
64
+ expectations.syntax = :expect
65
+ end
66
+
67
+ # rspec-mocks config goes here. You can use an alternate test double
68
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
69
+ config.mock_with :rspec do |mocks|
70
+ # Enable only the newer, non-monkey-patching expect syntax.
71
+ # For more details, see:
72
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
73
+ mocks.syntax = :expect
74
+
75
+ # Prevents you from mocking or stubbing a method that does not exist on
76
+ # a real object. This is generally recommended.
77
+ mocks.verify_partial_doubles = true
78
+ end
79
+ =end
80
+ end
@@ -0,0 +1,29 @@
1
+ describe Faraday::Zipkin::TraceHeaders do
2
+ let(:middleware) { described_class.new(lambda{|env| env}) }
3
+
4
+ def process(body, headers={})
5
+ env = {
6
+ :body => body,
7
+ :request_headers => Faraday::Utils::Headers.new(headers),
8
+ }
9
+ middleware.call(env)
10
+ end
11
+
12
+ context 'request' do
13
+ context 'with tracing id' do
14
+ let(:trace_id) { ::Trace::TraceId.new(1, 2, 3, true, ::Trace::Flags::EMPTY) }
15
+
16
+ it 'sets the X-B3 request headers' do
17
+ result = nil
18
+ ::Trace.push(trace_id) do
19
+ result = process('')
20
+ end
21
+ expect(result[:request_headers]['X-B3-TraceId']).to eq('0000000000000001')
22
+ expect(result[:request_headers]['X-B3-ParentSpanId']).to eq('0000000000000002')
23
+ expect(result[:request_headers]['X-B3-SpanId']).to eq('0000000000000003')
24
+ expect(result[:request_headers]['X-B3-Sampled']).to eq('true')
25
+ expect(result[:request_headers]['X-B3-Flags']).to eq('0')
26
+ end
27
+ end
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faraday-zipkin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ariel Salomon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thrift
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: finagle-thrift
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.3.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: thin
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Faraday middleware to generate Zipkin tracing headers.
112
+ email:
113
+ - asalomon@lookout.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - faraday-zipkin.gemspec
125
+ - lib/faraday/zipkin.rb
126
+ - lib/faraday/zipkin/version.rb
127
+ - spec/spec_helper.rb
128
+ - spec/zipkin_trace_headers_spec.rb
129
+ homepage: https://github.com/Oscil8/faraday-zipkin
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.2.2
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Faraday middleware to generate Zipkin tracing headers.
153
+ test_files:
154
+ - spec/spec_helper.rb
155
+ - spec/zipkin_trace_headers_spec.rb