jcw 0.1.0

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: 47920cfcec226ff9785a16c1297f9a7aafc571db02c0d2a2b27f66440d6d874f
4
+ data.tar.gz: c90c9a5636ae6c7827074cd1b64329999f21a098d3c04b92fe3a5da085aaaad5
5
+ SHA512:
6
+ metadata.gz: 91dea8b748dbc92f865113b8066a57cf84fbf6ccea64ede2dedf9dcc02f2b33f6fe315182efcd209746c00f0889d863239ef86991adba8f946e9f27b8d536b0a
7
+ data.tar.gz: 6d8ed800f4b0a113f73546943d0f87bb2ca8ce9b71fc6e6c740c5411c266c94e94dab113e9944ef27db047b067d4dbe194ab782c329d9ac47fd5b99c3239bf58
@@ -0,0 +1,57 @@
1
+ name: Test
2
+
3
+ on: [push, pull_request]
4
+
5
+ env:
6
+ COVER: true
7
+
8
+ jobs:
9
+ full-check:
10
+ runs-on: ubuntu-latest
11
+
12
+ # We want to run on external PRs, but not on our own internal PRs as they'll be run on push event
13
+ if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'Cado-Labs/jcw'
14
+
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: 3.0.1
20
+ bundler-cache: true
21
+ - name: Run Linter
22
+ run: bundle exec rubocop
23
+ - name: Run specs
24
+ run: bundle exec rspec
25
+ - name: Audit
26
+ run: bundle exec bundle-audit
27
+ - name: Coveralls
28
+ uses: coverallsapp/github-action@master
29
+ with:
30
+ github-token: ${{ secrets.GITHUB_TOKEN }}
31
+ specs:
32
+ runs-on: ubuntu-latest
33
+ continue-on-error: ${{ matrix.experimental }}
34
+
35
+ env:
36
+ COVER: false
37
+
38
+ # We want to run on external PRs, but not on our own internal PRs as they'll be run on push event
39
+ if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'Cado-Labs/jcw'
40
+
41
+ strategy:
42
+ fail-fast: false
43
+ matrix:
44
+ ruby: [2.7, 2.7.4, 3.0.0, 3.0.1, 3.0.2]
45
+ experimental: [false]
46
+ include:
47
+ - ruby: head
48
+ experimental: true
49
+
50
+ steps:
51
+ - uses: actions/checkout@v2
52
+ - uses: ruby/setup-ruby@v1
53
+ with:
54
+ ruby-version: ${{ matrix.ruby }}
55
+ bundler-cache: true
56
+ - name: Run specs
57
+ run: bundle exec rspec
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ inherit_gem:
2
+ rubocop-config-umbrellio: lib/rubocop.yml
3
+
4
+ AllCops:
5
+ DisplayCopNames: true
6
+ TargetRubyVersion: 2.7
7
+
8
+ RSpec/EmptyLineAfterHook:
9
+ Enabled: false
10
+
11
+ Naming/RescuedExceptionsVariableName:
12
+ Enabled: false
13
+
14
+ Style/HashConversion:
15
+ Exclude:
16
+ - spec/**/*_spec.rb
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at aleksandr.sta@okwork.io. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,196 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jcw (0.1.0)
5
+ activesupport (>= 5.0)
6
+ httprb-opentracing (~> 0.4.0)
7
+ jaeger-client (~> 1.1.0)
8
+ rack-tracer (~> 0.9.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actionpack (6.1.4.1)
14
+ actionview (= 6.1.4.1)
15
+ activesupport (= 6.1.4.1)
16
+ rack (~> 2.0, >= 2.0.9)
17
+ rack-test (>= 0.6.3)
18
+ rails-dom-testing (~> 2.0)
19
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
20
+ actionview (6.1.4.1)
21
+ activesupport (= 6.1.4.1)
22
+ builder (~> 3.1)
23
+ erubi (~> 1.4)
24
+ rails-dom-testing (~> 2.0)
25
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
26
+ activesupport (6.1.4.1)
27
+ concurrent-ruby (~> 1.0, >= 1.0.2)
28
+ i18n (>= 1.6, < 2)
29
+ minitest (>= 5.1)
30
+ tzinfo (~> 2.0)
31
+ zeitwerk (~> 2.3)
32
+ addressable (2.8.0)
33
+ public_suffix (>= 2.0.2, < 5.0)
34
+ ast (2.4.2)
35
+ builder (3.2.4)
36
+ bundler-audit (0.8.0)
37
+ bundler (>= 1.2.0, < 3)
38
+ thor (~> 1.0)
39
+ coderay (1.1.3)
40
+ concurrent-ruby (1.1.9)
41
+ crass (1.0.6)
42
+ diff-lcs (1.4.4)
43
+ docile (1.4.0)
44
+ domain_name (0.5.20190701)
45
+ unf (>= 0.0.5, < 1.0.0)
46
+ erubi (1.10.0)
47
+ ffi (1.15.3)
48
+ ffi-compiler (1.0.1)
49
+ ffi (>= 1.0.0)
50
+ rake
51
+ http (5.0.1)
52
+ addressable (~> 2.3)
53
+ http-cookie (~> 1.0)
54
+ http-form_data (~> 2.2)
55
+ llhttp-ffi (~> 0.3.0)
56
+ http-cookie (1.0.4)
57
+ domain_name (~> 0.5)
58
+ http-form_data (2.3.0)
59
+ http-parser (1.2.3)
60
+ ffi-compiler (>= 1.0, < 2.0)
61
+ httprb-opentracing (0.4.0)
62
+ opentracing (~> 0.5.0)
63
+ i18n (1.8.10)
64
+ concurrent-ruby (~> 1.0)
65
+ jaeger-client (1.1.0)
66
+ opentracing (~> 0.3)
67
+ thrift
68
+ llhttp-ffi (0.3.1)
69
+ ffi-compiler (~> 1.0)
70
+ rake (~> 13.0)
71
+ loofah (2.12.0)
72
+ crass (~> 1.0.2)
73
+ nokogiri (>= 1.5.9)
74
+ method_source (1.0.0)
75
+ mini_portile2 (2.6.1)
76
+ minitest (5.14.4)
77
+ nokogiri (1.12.3)
78
+ mini_portile2 (~> 2.6.1)
79
+ racc (~> 1.4)
80
+ nokogiri (1.12.3-x86_64-darwin)
81
+ racc (~> 1.4)
82
+ nokogiri (1.12.3-x86_64-linux)
83
+ racc (~> 1.4)
84
+ opentracing (0.5.0)
85
+ parallel (1.20.1)
86
+ parser (3.0.2.0)
87
+ ast (~> 2.4.1)
88
+ pry (0.14.1)
89
+ coderay (~> 1.1)
90
+ method_source (~> 1.0)
91
+ public_suffix (4.0.6)
92
+ racc (1.5.2)
93
+ rack (2.2.3)
94
+ rack-test (1.1.0)
95
+ rack (>= 1.0, < 3)
96
+ rack-tracer (0.9.0)
97
+ opentracing (~> 0.4)
98
+ rails-dom-testing (2.0.3)
99
+ activesupport (>= 4.2.0)
100
+ nokogiri (>= 1.6)
101
+ rails-html-sanitizer (1.4.2)
102
+ loofah (~> 2.3)
103
+ railties (6.1.4.1)
104
+ actionpack (= 6.1.4.1)
105
+ activesupport (= 6.1.4.1)
106
+ method_source
107
+ rake (>= 0.13)
108
+ thor (~> 1.0)
109
+ rainbow (3.0.0)
110
+ rake (13.0.6)
111
+ regexp_parser (2.1.1)
112
+ rexml (3.2.5)
113
+ rspec (3.10.0)
114
+ rspec-core (~> 3.10.0)
115
+ rspec-expectations (~> 3.10.0)
116
+ rspec-mocks (~> 3.10.0)
117
+ rspec-core (3.10.1)
118
+ rspec-support (~> 3.10.0)
119
+ rspec-expectations (3.10.1)
120
+ diff-lcs (>= 1.2.0, < 2.0)
121
+ rspec-support (~> 3.10.0)
122
+ rspec-mocks (3.10.2)
123
+ diff-lcs (>= 1.2.0, < 2.0)
124
+ rspec-support (~> 3.10.0)
125
+ rspec-support (3.10.2)
126
+ rubocop (1.17.0)
127
+ parallel (~> 1.10)
128
+ parser (>= 3.0.0.0)
129
+ rainbow (>= 2.2.2, < 4.0)
130
+ regexp_parser (>= 1.8, < 3.0)
131
+ rexml
132
+ rubocop-ast (>= 1.7.0, < 2.0)
133
+ ruby-progressbar (~> 1.7)
134
+ unicode-display_width (>= 1.4.0, < 3.0)
135
+ rubocop-ast (1.11.0)
136
+ parser (>= 3.0.1.1)
137
+ rubocop-config-umbrellio (1.17.0.53)
138
+ rubocop (= 1.17.0)
139
+ rubocop-performance (= 1.10.0)
140
+ rubocop-rails (= 2.9.1)
141
+ rubocop-rake (= 0.5.1)
142
+ rubocop-rspec (= 2.2.0)
143
+ rubocop-sequel (= 0.2.0)
144
+ rubocop-performance (1.10.0)
145
+ rubocop (>= 0.90.0, < 2.0)
146
+ rubocop-ast (>= 0.4.0)
147
+ rubocop-rails (2.9.1)
148
+ activesupport (>= 4.2.0)
149
+ rack (>= 1.1)
150
+ rubocop (>= 0.90.0, < 2.0)
151
+ rubocop-rake (0.5.1)
152
+ rubocop
153
+ rubocop-rspec (2.2.0)
154
+ rubocop (~> 1.0)
155
+ rubocop-ast (>= 1.1.0)
156
+ rubocop-sequel (0.2.0)
157
+ rubocop (~> 1.0)
158
+ ruby-progressbar (1.11.0)
159
+ simplecov (0.21.2)
160
+ docile (~> 1.1)
161
+ simplecov-html (~> 0.11)
162
+ simplecov_json_formatter (~> 0.1)
163
+ simplecov-html (0.12.3)
164
+ simplecov-lcov (0.8.0)
165
+ simplecov_json_formatter (0.1.3)
166
+ thor (1.1.0)
167
+ thrift (0.14.2)
168
+ tzinfo (2.0.4)
169
+ concurrent-ruby (~> 1.0)
170
+ unf (0.1.4)
171
+ unf_ext
172
+ unf_ext (0.0.7.7)
173
+ unicode-display_width (2.0.0)
174
+ zeitwerk (2.4.2)
175
+
176
+ PLATFORMS
177
+ ruby
178
+ x86_64-darwin-18
179
+ x86_64-linux
180
+
181
+ DEPENDENCIES
182
+ bundler
183
+ bundler-audit
184
+ http
185
+ http-parser
186
+ jcw!
187
+ pry
188
+ railties
189
+ rake
190
+ rspec
191
+ rubocop-config-umbrellio
192
+ simplecov
193
+ simplecov-lcov
194
+
195
+ BUNDLED WITH
196
+ 2.2.15
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Aleksandr Starovojtov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # JCW &middot; [![Supporting](https://github.com/Cado-Labs/cado-labs-logos/blob/main/cado_labs_badge.png)](https://github.com/Cado-Labs/) &middot; [![Coverage Status](https://coveralls.io/repos/github/Cado-Labs/jcw/badge.svg?branch=gem-without-zeitwerk)](https://coveralls.io/github/Cado-Labs/jcw?branch=gem-without-zeitwerk)
2
+
3
+ Simple wrapper for the gem "jaeger-client" with simpler customization.
4
+
5
+ ---
6
+
7
+ <p>
8
+ <a href="https://github.com/Cado-Labs">
9
+ <img src="https://github.com/Cado-Labs/cado-labs-logos/blob/main/cado_labs_supporting.svg" alt="Supported by Cado Labs" />
10
+ </a>
11
+ </p>
12
+
13
+ ---
14
+
15
+ ## Installation
16
+
17
+ ```ruby
18
+ gem 'jcw'
19
+ ```
20
+
21
+ ```shell
22
+ bundle install
23
+ # --- or ---
24
+ gem install jcw
25
+ ```
26
+
27
+ ```ruby
28
+ require 'jcw'
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ Create new initializer for your rails app:
34
+
35
+ UDP Sender(default):
36
+ ```ruby
37
+ ::JCW::Wrapper.configure do |config|
38
+ config.service_name = "Service name"
39
+ config.connection = { protocol: :udp, host: "127.0.0.1", port: 6831 }
40
+ config.enabled = true
41
+ config.tags = {
42
+ hostname: "custom-hostname",
43
+ custom_tag: "custom-tag-value",
44
+ }
45
+ end
46
+
47
+ # Set middleware for wrapping all requests(gem RackTracer)
48
+ Rails.application.middleware.use(JCW::RackTracer)
49
+ ```
50
+
51
+ TCP Sender:
52
+ ```ruby
53
+ ::JCW::Wrapper.configure do |config|
54
+ config.service_name = "Service name"
55
+ config.enabled = true
56
+ config.subscribe_to = %w[process_action.action_controller start_processing.action_controller] # set ActiveSupport::Notifications namespaces
57
+ config.connection = { protocol: :tcp, url: "http://localhost:14268/api/traces", headers: { key: "value" } }
58
+ config.tags = {
59
+ hostname: "custom-hostname",
60
+ custom_tag: "custom-tag-value",
61
+ }
62
+ end
63
+
64
+ # Set middleware for wrapping all requests
65
+ Rails.application.middleware.use(JCW::RackTracer)
66
+
67
+ # If you need send all logs with spans set on_finish_span and extend JaegerLoggerExtension
68
+ # Not recommended for UDP sender, because default max packet size is 65,000 bytes.
69
+ Rails.application.config.tap do |config|
70
+ config.middleware.use(
71
+ ::JCW::RackTracer,
72
+ on_finish_span:
73
+ -> (span) { ::JCW::JaegerLogger.current.logs.each { |log| span.log_kv(**log) } },
74
+ )
75
+ config.logger.extend(::JCW::JaegerLoggerExtension)
76
+ end
77
+ ```
78
+ - `config.subscribe_to` - not recommended for UDP sender, because default max packet size is 65,000 bytes.
79
+
80
+ ### Contributing
81
+
82
+ - Fork it ( https://github.com/Cado-Labs/jcw )
83
+ - Create your feature branch (`git checkout -b feature/my-new-feature`)
84
+ - Commit your changes (`git commit -am '[feature_context] Add some feature'`)
85
+ - Push to the branch (`git push origin feature/my-new-feature`)
86
+ - Create new Pull Request
87
+
88
+ ## License
89
+
90
+ Released under MIT License.
91
+
92
+ ## Supporting
93
+
94
+ <a href="https://github.com/Cado-Labs">
95
+ <img src="https://github.com/Cado-Labs/cado-labs-logos/blob/main/cado_labs_logo.png" alt="Supported by Cado Labs" />
96
+ </a>
97
+
98
+ ## Authors
99
+
100
+ [Aleksandr Starovojtov](https://github.com/AS-AlStar)
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'jcw/wrapper'
6
+
7
+ require 'irb'
8
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
data/jcw.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/jcw/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "jcw"
7
+ spec.version = JCW::VERSION
8
+ spec.authors = ["Alexander Starovojtov"]
9
+ spec.email = ["starovojtov.alexander@gmail.com"]
10
+
11
+ spec.summary = "Wrapper for jaeger-client"
12
+ spec.description = "Wrapper for the gem 'jaeger-client' with simpler customization."
13
+ spec.homepage = "https://github.com/Cado-Labs/jcw"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
16
+
17
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "activesupport", ">= 5.0"
26
+ spec.add_dependency "httprb-opentracing", "~> 0.4.0"
27
+ spec.add_dependency "jaeger-client", "~> 1.1.0"
28
+ spec.add_dependency "rack-tracer", "~> 0.9.0"
29
+
30
+ spec.add_development_dependency "bundler"
31
+ spec.add_development_dependency "bundler-audit"
32
+ spec.add_development_dependency "http"
33
+ spec.add_development_dependency "http-parser"
34
+ spec.add_development_dependency "pry"
35
+ spec.add_development_dependency "railties"
36
+ spec.add_development_dependency "rake"
37
+ spec.add_development_dependency "rspec"
38
+ spec.add_development_dependency "rubocop-config-umbrellio"
39
+ spec.add_development_dependency "simplecov"
40
+ spec.add_development_dependency "simplecov-lcov"
41
+ end
data/lib/jcw/config.rb ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JCW
4
+ class Config
5
+ attr_writer :enabled,
6
+ :service_name,
7
+ :subscribe_to,
8
+ :connection,
9
+ :flush_interval,
10
+ :tags
11
+
12
+ def enabled
13
+ @enabled ||= false
14
+ end
15
+
16
+ alias enabled? enabled
17
+
18
+ def service_name
19
+ @service_name ||= "JCW service"
20
+ end
21
+
22
+ def subscribe_to
23
+ @subscribe_to ||= []
24
+ end
25
+
26
+ def connection
27
+ @connection ||= { protocol: :udp, host: "127.0.0.1", port: 6831 }
28
+ end
29
+
30
+ def flush_interval
31
+ @flush_interval ||= 10
32
+ end
33
+
34
+ def tags
35
+ @tags ||= {}
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Patch unless gem 'httprb-opentracing' not released PR#8
4
+ # :nocov:
5
+ module JCW
6
+ module HttpTracer
7
+ class << self
8
+ # rubocop:disable Metrics/MethodLength
9
+ def patch_perform
10
+ ::HTTP::Client.class_eval do
11
+ def perform_with_tracing(request, options)
12
+ if ::HTTP::Tracer.ignore_request.call(request, options)
13
+ res = perform_without_tracing(request, options)
14
+ else
15
+ path, host, port, verb = nil
16
+ path = request.uri.path if request.uri.respond_to?(:path)
17
+ host = request.uri.host if request.uri.respond_to?(:host)
18
+ port = request.uri.port if request.uri.respond_to?(:port)
19
+ verb = request.verb.to_s.upcase if request.respond_to?(:verb)
20
+
21
+ tags = {
22
+ "component" => "ruby-httprb",
23
+ "span.kind" => "client",
24
+ "http.method" => verb,
25
+ "http.url" => path,
26
+ "peer.host" => host,
27
+ "peer.port" => port,
28
+ }.compact
29
+
30
+ tracer = ::HTTP::Tracer.tracer
31
+
32
+ tracer.start_active_span("http.request", tags: tags) do |scope|
33
+ request.headers.merge!(options.headers)
34
+ OpenTracing.inject(scope.span.context, OpenTracing::FORMAT_RACK,
35
+ request.headers)
36
+
37
+ res = perform_without_tracing(request, options)
38
+
39
+ scope.span.set_tag("http.status_code", res.status)
40
+ scope.span.set_tag("error", true) if res.is_a?(StandardError)
41
+ end
42
+ end
43
+
44
+ res
45
+ end
46
+
47
+ alias_method :perform_without_tracing, :perform
48
+ alias_method :perform, :perform_with_tracing
49
+ end
50
+ end
51
+ # rubocop:enable Metrics/MethodLength
52
+ end
53
+ end
54
+ end
55
+ # :nocov:
data/lib/jcw/init.rb ADDED
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JCW
4
+ class Init
5
+ class << self
6
+ def call
7
+ init_jaeger_client
8
+ activate_subscribers
9
+ init_http_tracer
10
+ end
11
+
12
+ private
13
+
14
+ def init_jaeger_client
15
+ return unless config.enabled?
16
+
17
+ reporter = config.connection[:protocol] == :tcp ? tcp_reporter : nil
18
+
19
+ OpenTracing.global_tracer = Jaeger::Client.build(
20
+ service_name: config.service_name,
21
+ host: config.connection[:host],
22
+ port: config.connection[:port],
23
+ flush_interval: config.flush_interval,
24
+ reporter: reporter,
25
+ tags: config.tags,
26
+ )
27
+ end
28
+
29
+ def tcp_reporter
30
+ Jaeger::Reporters::RemoteReporter.new(
31
+ sender: Jaeger::HttpSender.new(
32
+ url: config.connection[:url],
33
+ headers: config.connection[:headers] || {},
34
+ encoder: Jaeger::Encoders::ThriftEncoder.new(
35
+ service_name: config.service_name,
36
+ tags: config.tags,
37
+ ),
38
+ ),
39
+ flush_interval: config.flush_interval,
40
+ )
41
+ end
42
+
43
+ def activate_subscribers
44
+ subscribers = config.subscribe_to
45
+ return if subscribers.blank?
46
+
47
+ Tracing.register_subscribers(subscribers)
48
+ Tracing.subscribe_tracing_events
49
+ end
50
+
51
+ def init_http_tracer
52
+ HTTP::Tracer.instrument
53
+ HTTP::Tracer.remove # remove after gem 'httprb-opentracing' released PR#8
54
+ HttpTracer.patch_perform # remove after gem 'httprb-opentracing' released PR#8
55
+ end
56
+
57
+ def config
58
+ Wrapper.config
59
+ end
60
+ end
61
+ end
62
+ end
data/lib/jcw/logger.rb ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JCW
4
+ class Logger
5
+ LEVELS = {
6
+ ::Logger::UNKNOWN => "unknown",
7
+ ::Logger::FATAL => "fatal",
8
+ ::Logger::ERROR => "error",
9
+ ::Logger::WARN => "warn",
10
+ ::Logger::INFO => "info",
11
+ ::Logger::DEBUG => "debug",
12
+ }.freeze
13
+
14
+ class << self
15
+ def current
16
+ Thread.current[:jaeger_logger] ||= new
17
+ end
18
+ end
19
+
20
+ def add(level, message, progname)
21
+ message ||= progname
22
+ logs << { level: LEVELS[level], message: message } unless message.to_s.empty?
23
+ end
24
+
25
+ def logs
26
+ @logs ||= []
27
+ end
28
+
29
+ def clear
30
+ @logs = []
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JCW
4
+ module LoggerExtension
5
+ def add(*args, &block)
6
+ super(*args, &block)
7
+
8
+ Logger.current.add(*args)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JCW
4
+ RackTracer = Class.new(Rack::Tracer)
5
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JCW
4
+ class Subscriber
5
+ class << self
6
+ def subscribe_to_event!(event_name)
7
+ ActiveSupport::Notifications.subscribe(event_name) do |*args|
8
+ (span = OpenTracing.scope_manager.active&.span) or next
9
+ event = ActiveSupport::Notifications::Event.new(*args)
10
+ span.log_kv(context: span_context(event))
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def span_context(event)
17
+ {
18
+ name: event.name,
19
+ time: event.time,
20
+ payload: event.payload.to_s,
21
+ transaction_id: event.transaction_id,
22
+ }.as_json
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JCW
4
+ module Tracing
5
+ class << self
6
+ attr_reader :subscribers
7
+
8
+ def register_subscribers(subscribers)
9
+ @subscribers = subscribers
10
+ end
11
+
12
+ def subscribe_tracing_events
13
+ subscribers.each { |subscriber| Subscriber.subscribe_to_event!(subscriber) }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JCW
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "config"
4
+
5
+ module JCW
6
+ module Wrapper
7
+ class << self
8
+ def config
9
+ @config ||= Config.new
10
+ end
11
+
12
+ def configure
13
+ yield config
14
+ Init.call
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ require_relative "tracing"
21
+ require_relative "init"
22
+ require_relative "subscriber"
23
+ require_relative "http_tracer"
24
+ require_relative "rack_tracer"
25
+ require_relative "logger"
26
+ require_relative "logger_extension"
data/lib/jcw.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rack/tracer"
4
+ require "jaeger/client"
5
+ require "active_support"
6
+ require "httprb-opentracing"
7
+ require_relative "jcw/wrapper"
metadata ADDED
@@ -0,0 +1,277 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jcw
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Starovojtov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httprb-opentracing
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.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.4.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: jaeger-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.1.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.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-tracer
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler-audit
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: http
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
+ - !ruby/object:Gem::Dependency
112
+ name: http-parser
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: railties
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rake
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rspec
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rubocop-config-umbrellio
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: simplecov
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: simplecov-lcov
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ description: Wrapper for the gem 'jaeger-client' with simpler customization.
224
+ email:
225
+ - starovojtov.alexander@gmail.com
226
+ executables: []
227
+ extensions: []
228
+ extra_rdoc_files: []
229
+ files:
230
+ - ".github/workflows/test.yml"
231
+ - ".gitignore"
232
+ - ".rspec"
233
+ - ".rubocop.yml"
234
+ - CODE_OF_CONDUCT.md
235
+ - Gemfile
236
+ - Gemfile.lock
237
+ - LICENSE.txt
238
+ - README.md
239
+ - Rakefile
240
+ - bin/console
241
+ - bin/setup
242
+ - jcw.gemspec
243
+ - lib/jcw.rb
244
+ - lib/jcw/config.rb
245
+ - lib/jcw/http_tracer.rb
246
+ - lib/jcw/init.rb
247
+ - lib/jcw/logger.rb
248
+ - lib/jcw/logger_extension.rb
249
+ - lib/jcw/rack_tracer.rb
250
+ - lib/jcw/subscriber.rb
251
+ - lib/jcw/tracing.rb
252
+ - lib/jcw/version.rb
253
+ - lib/jcw/wrapper.rb
254
+ homepage: https://github.com/Cado-Labs/jcw
255
+ licenses:
256
+ - MIT
257
+ metadata: {}
258
+ post_install_message:
259
+ rdoc_options: []
260
+ require_paths:
261
+ - lib
262
+ required_ruby_version: !ruby/object:Gem::Requirement
263
+ requirements:
264
+ - - ">="
265
+ - !ruby/object:Gem::Version
266
+ version: 2.7.0
267
+ required_rubygems_version: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ requirements: []
273
+ rubygems_version: 3.1.6
274
+ signing_key:
275
+ specification_version: 4
276
+ summary: Wrapper for jaeger-client
277
+ test_files: []