rails_distributed_tracing 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,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 69fd5cb81a640cea786690e9d8bf4dc7284e08b0289e93d797fde7851fd36381
4
+ data.tar.gz: 0e9b942df72816af28e35588ac79c53b304193cf3c279f37db02d72039fc860a
5
+ SHA512:
6
+ metadata.gz: 42c81c54a82559fc0b023c7aca86763ca256d910c1d18f4680cdb04d8a73783a9c0da0f9af5c3344a6dd40f57fc284d532a6c8f181eaccde6779dbd4c6cfefc0
7
+ data.tar.gz: 7d853b27c618c90302296846d195fcdd1bae0bfd44f73410ae2683398f05ec476fb403974de664ca8794487223f93da9e1c1df00530f8a5f9e3bcbda9b7cb4c0
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .idea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gem 'rspec'
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.3)
5
+ rspec (3.8.0)
6
+ rspec-core (~> 3.8.0)
7
+ rspec-expectations (~> 3.8.0)
8
+ rspec-mocks (~> 3.8.0)
9
+ rspec-core (3.8.0)
10
+ rspec-support (~> 3.8.0)
11
+ rspec-expectations (3.8.1)
12
+ diff-lcs (>= 1.2.0, < 2.0)
13
+ rspec-support (~> 3.8.0)
14
+ rspec-mocks (3.8.0)
15
+ diff-lcs (>= 1.2.0, < 2.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-support (3.8.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ rspec
24
+
25
+ BUNDLED WITH
26
+ 1.16.1
@@ -0,0 +1,2 @@
1
+ project_root = File.dirname(File.absolute_path(__FILE__))
2
+ Dir.glob(project_root + '/rails_distributed_tracing/**/*.rb', &method(:require))
@@ -0,0 +1,18 @@
1
+ require_relative './request_id_store'
2
+
3
+ module DistributedTracing
4
+ def self.request_id_tag
5
+ lambda do |request|
6
+ request_id = request.headers['Request-ID'] || request.request_id
7
+ RequestIDStore.request_id = request_id
8
+ end
9
+ end
10
+
11
+ def self.request_id_header
12
+ {'Request-ID' => RequestIDStore.request_id}
13
+ end
14
+
15
+ def self.current_request_id
16
+ RequestIDStore.request_id
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module DistributedTracing
2
+ class RequestIDStore
3
+ def self.request_id=(id)
4
+ @request_id = id
5
+ end
6
+
7
+ def self.request_id
8
+ @request_id
9
+ end
10
+
11
+ def self.clear!
12
+ @request_id = nil
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module DistributedTracing
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require_relative './lib/rails_distributed_tracing/version.rb'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'rails_distributed_tracing'
8
+ s.version = DistributedTracing::VERSION
9
+ s.summary = "Microservices distributed tracing\nThe gem generates a request id which can be added as a tag in rails logs.\nChild services will reuse this tag with the help of this gem."
10
+ s.authors = ['Ajit Singh']
11
+ s.email = 'jeetsingh.ajit@gamil.com'
12
+ s.license = 'MIT'
13
+ s.homepage = 'https://github.com/ajitsing/rails_distributed_tracing'
14
+
15
+ s.files = `git ls-files -z`.split("\x0")
16
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency "bundler", "~> 1.5"
21
+ s.add_development_dependency 'rspec'
22
+ end
@@ -0,0 +1,48 @@
1
+ describe DistributedTracing do
2
+ describe '#request_id_tag' do
3
+ it 'should return request id from request object' do
4
+ request = double('request')
5
+ request_id = 'f914eb91-c550-48c4-af35-d14db95bd49f'
6
+
7
+ expect(request).to receive(:request_id).and_return(request_id)
8
+ expect(request).to receive(:headers).and_return({})
9
+
10
+ expect(DistributedTracing.request_id_tag.call(request)).to eq(request_id)
11
+ end
12
+
13
+ it 'should return request id from header' do
14
+ request = double('request')
15
+ request_id = '00bfc934-b429-4606-b0c8-318ffa82e884'
16
+
17
+ expect(request).to receive(:headers).and_return({'Request-ID' => request_id})
18
+
19
+ expect(DistributedTracing.request_id_tag.call(request)).to eq(request_id)
20
+ end
21
+ end
22
+
23
+ describe '#current_request_id' do
24
+ it 'should return current request id' do
25
+ request = double('request')
26
+ request_id = '00bfc934-b429-4606-b0c8-318ffa82e884'
27
+
28
+ expect(request).to receive(:headers).and_return({'Request-ID' => request_id})
29
+
30
+ DistributedTracing.request_id_tag.call(request)
31
+
32
+ expect(DistributedTracing.current_request_id).to eq(request_id)
33
+ end
34
+ end
35
+
36
+ describe '#request_id_header' do
37
+ it 'should return request id in a header' do
38
+ request = double('request')
39
+ request_id = '00bfc934-b429-4606-b0c8-318ffa82e884'
40
+
41
+ expect(request).to receive(:headers).and_return({'Request-ID' => request_id})
42
+
43
+ DistributedTracing.request_id_tag.call(request)
44
+
45
+ expect(DistributedTracing.request_id_header).to eq({'Request-ID' => request_id})
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,103 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+
17
+ require './lib/rails_distributed_tracing'
18
+
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
44
+ # have no way to turn it off -- the option exists only for backwards
45
+ # compatibility in RSpec 3). It causes shared context metadata to be
46
+ # inherited by the metadata hash of host groups and examples, rather than
47
+ # triggering implicit auto-inclusion in groups with matching metadata.
48
+ config.shared_context_metadata_behavior = :apply_to_host_groups
49
+
50
+ # The settings below are suggested to provide a good initial experience
51
+ # with RSpec, but feel free to customize to your heart's content.
52
+ =begin
53
+ # This allows you to limit a spec run to individual examples or groups
54
+ # you care about by tagging them with `:focus` metadata. When nothing
55
+ # is tagged with `:focus`, all examples get run. RSpec also provides
56
+ # aliases for `it`, `describe`, and `context` that include `:focus`
57
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
58
+ config.filter_run_when_matching :focus
59
+
60
+ # Allows RSpec to persist some state between runs in order to support
61
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
62
+ # you configure your source control system to ignore this file.
63
+ config.example_status_persistence_file_path = "spec/examples.txt"
64
+
65
+ # Limits the available syntax to the non-monkey patched syntax that is
66
+ # recommended. For more details, see:
67
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
68
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
69
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
70
+ config.disable_monkey_patching!
71
+
72
+ # This setting enables warnings. It's recommended, but in some cases may
73
+ # be too noisy due to issues in dependencies.
74
+ config.warnings = true
75
+
76
+ # Many RSpec users commonly either run the entire suite or an individual
77
+ # file, and it's useful to allow more verbose output when running an
78
+ # individual spec file.
79
+ if config.files_to_run.one?
80
+ # Use the documentation formatter for detailed output,
81
+ # unless a formatter has already been configured
82
+ # (e.g. via a command-line flag).
83
+ config.default_formatter = "doc"
84
+ end
85
+
86
+ # Print the 10 slowest examples and example groups at the
87
+ # end of the spec run, to help surface which specs are running
88
+ # particularly slow.
89
+ config.profile_examples = 10
90
+
91
+ # Run specs in random order to surface order dependencies. If you find an
92
+ # order dependency and want to debug it, you can fix the order by providing
93
+ # the seed, which is printed after each run.
94
+ # --seed 1234
95
+ config.order = :random
96
+
97
+ # Seed global randomization in this process using the `--seed` CLI option.
98
+ # Setting this allows you to use `--seed` to deterministically reproduce
99
+ # test failures related to randomization by passing the same `--seed` value
100
+ # as the one that triggered the failure.
101
+ Kernel.srand config.seed
102
+ =end
103
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_distributed_tracing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ajit Singh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email: jeetsingh.ajit@gamil.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".gitignore"
48
+ - ".rspec"
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - lib/rails_distributed_tracing.rb
52
+ - lib/rails_distributed_tracing/distributed_tracing.rb
53
+ - lib/rails_distributed_tracing/request_id_store.rb
54
+ - lib/rails_distributed_tracing/version.rb
55
+ - rails_distributed_tracing.gemspec
56
+ - spec/lib/distributed_tracing_spec.rb
57
+ - spec/spec_helper.rb
58
+ homepage: https://github.com/ajitsing/rails_distributed_tracing
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.7.6
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Microservices distributed tracing The gem generates a request id which can
82
+ be added as a tag in rails logs. Child services will reuse this tag with the help
83
+ of this gem.
84
+ test_files:
85
+ - spec/lib/distributed_tracing_spec.rb
86
+ - spec/spec_helper.rb