kafka-opentracing 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +11 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +41 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/kafka-opentracing.gemspec +44 -0
- data/lib/kafka/tracer/version.rb +7 -0
- data/lib/kafka/tracer.rb +252 -0
- data/lib/kafka-opentracing.rb +1 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eff7c932049d6bd768047eb6d3fbc5134be04748
|
4
|
+
data.tar.gz: a83b0a917ca2b5cfa2ab326fb078559ae716cde0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 28c340450683ee46ebbddd28f756905f89c105dba3f3f5d29537fdae7b2203e7dfdadd6500cace2d422959b13c4a46843b1b484864a4d8eb583a38c6ff8d7736
|
7
|
+
data.tar.gz: c3357b95766f1920a7ad93a4c687d00ca540ac790275487a701ab4b549083bec16bdfe3eed6dd9b0b575833e8b6d0bcdb2d970539a77e5529345c22d36c5e9d9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 ben.fischer.810@gmail.com. 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 [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
kafka-opentracing (0.1.0)
|
5
|
+
opentracing (~> 0.5.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.3)
|
11
|
+
digest-crc (0.4.1)
|
12
|
+
opentracing (0.5.0)
|
13
|
+
rake (10.5.0)
|
14
|
+
rspec (3.8.0)
|
15
|
+
rspec-core (~> 3.8.0)
|
16
|
+
rspec-expectations (~> 3.8.0)
|
17
|
+
rspec-mocks (~> 3.8.0)
|
18
|
+
rspec-core (3.8.2)
|
19
|
+
rspec-support (~> 3.8.0)
|
20
|
+
rspec-expectations (3.8.4)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-mocks (3.8.1)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.8.0)
|
26
|
+
rspec-support (3.8.2)
|
27
|
+
ruby-kafka (0.7.6.beta2)
|
28
|
+
digest-crc
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
bundler (~> 2.0)
|
35
|
+
kafka-opentracing!
|
36
|
+
rake (~> 10.0)
|
37
|
+
rspec (~> 3.0)
|
38
|
+
ruby-kafka (>= 0.7.0)
|
39
|
+
|
40
|
+
BUNDLED WITH
|
41
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Ben Fischer
|
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,54 @@
|
|
1
|
+
# Kafka Opentracing
|
2
|
+
|
3
|
+
Open Tracing instrumentation for the [kafka gem](https://github.com/zendesk/ruby-kafka). By default it starts a new span for every message written to kafka and propogates the span context when any consumer consumes the message. It follows the open tracing tagging [semantic conventions](https://opentracing.io/specification/conventions)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'kafka-opentracing'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install kafka-opentracing
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
First load the opentracing (Note: this won't automatically instrument the http gem)
|
23
|
+
```
|
24
|
+
require "kafka-opentracing"
|
25
|
+
```
|
26
|
+
|
27
|
+
If you have setup `OpenTracing.global_tracer` you can turn on spans for all requests with just:
|
28
|
+
```
|
29
|
+
Kafka::Tracer.instrument
|
30
|
+
```
|
31
|
+
|
32
|
+
If you need more control over the tracer or which requests get their own span you can configure both settings like:
|
33
|
+
```
|
34
|
+
Kafka::Tracer.instrument(
|
35
|
+
tracer: tracer,
|
36
|
+
ignore_message: ->(value, key, headers, topic, partition, partition_key) { topic == 'testing' }
|
37
|
+
)
|
38
|
+
```
|
39
|
+
|
40
|
+
## Development
|
41
|
+
|
42
|
+
After checking out the repo, run `bundle install` to install dependencies. Then, run `rspec` to run the tests.
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/benedictfischer09/ruby-kafka-instrumentation. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
51
|
+
|
52
|
+
## Code of Conduct
|
53
|
+
|
54
|
+
Everyone interacting in the project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/benedictfischer09/ruby-kafka-instrumentation/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ruby/kafka/tracer"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "kafka/tracer/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "kafka-opentracing"
|
8
|
+
spec.version = Kafka::Tracer::VERSION
|
9
|
+
spec.authors = ["Ben Fischer"]
|
10
|
+
spec.email = ["ben.fischer.810@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Instruments the ruby-kafka gem for opentracing}
|
13
|
+
spec.description = %q{Instruments the ruby-kafka gem for opentracing}
|
14
|
+
spec.homepage = "https://github.com/benedictfischer09/ruby-kafka-instrumentation"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
|
22
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
spec.metadata["source_code_uri"] = "https://github.com/benedictfischer09/ruby-kafka-instrumentation"
|
24
|
+
spec.metadata["changelog_uri"] = "https://github.com/benedictfischer09/ruby-kafka-instrumentation/master/CHANGELOG.md"
|
25
|
+
else
|
26
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
"public gem pushes."
|
28
|
+
end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = "exe"
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_dependency "opentracing", "~> 0.5.0"
|
40
|
+
spec.add_development_dependency "ruby-kafka", ">= 0.7.0"
|
41
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
42
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
43
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
44
|
+
end
|
data/lib/kafka/tracer.rb
ADDED
@@ -0,0 +1,252 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'kafka/tracer/version'
|
4
|
+
require 'opentracing'
|
5
|
+
|
6
|
+
module Kafka
|
7
|
+
module Tracer
|
8
|
+
class IncompatibleGemVersion < StandardError; end;
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :ignore_message, :tracer
|
12
|
+
|
13
|
+
IngoreMessage = ->(_value, _key, _headers, _topic, _partition, _partition_key) { false }
|
14
|
+
|
15
|
+
def instrument(tracer: OpenTracing.global_tracer, ignore_message: IngoreMessage)
|
16
|
+
raise IncompatibleGemVersion unless compatible_version?
|
17
|
+
|
18
|
+
@ignore_message = ignore_message
|
19
|
+
@tracer = tracer
|
20
|
+
patch_producer_produce
|
21
|
+
patch_client_deliver_message
|
22
|
+
patch_client_each_message
|
23
|
+
patch_consumer_each_message
|
24
|
+
end
|
25
|
+
|
26
|
+
def compatible_version?
|
27
|
+
# https://github.com/zendesk/ruby-kafka/pull/604
|
28
|
+
Gem::Version.new(Kafka::VERSION) >= Gem::Version.new("0.7.0")
|
29
|
+
end
|
30
|
+
|
31
|
+
def remove
|
32
|
+
if ::Kafka::Producer.method_defined?(:produce_original)
|
33
|
+
::Kafka::Producer.class_eval do
|
34
|
+
remove_method :produce
|
35
|
+
alias_method :produce, :produce_original
|
36
|
+
remove_method :produce_original
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
if ::Kafka::Client.method_defined?(:deliver_message_original)
|
41
|
+
::Kafka::Client.class_eval do
|
42
|
+
remove_method :deliver_message
|
43
|
+
alias_method :deliver_message, :deliver_message_original
|
44
|
+
remove_method :deliver_message_original
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
if ::Kafka::Client.method_defined?(:each_message_original)
|
49
|
+
::Kafka::Client.class_eval do
|
50
|
+
remove_method :each_message
|
51
|
+
alias_method :each_message, :each_message_original
|
52
|
+
remove_method :each_message_original
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
if ::Kafka::Consumer.method_defined?(:each_message_original)
|
57
|
+
::Kafka::Consumer.class_eval do
|
58
|
+
remove_method :each_message
|
59
|
+
alias_method :each_message, :each_message_original
|
60
|
+
remove_method :each_message_original
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# used to send sync messages
|
66
|
+
def patch_client_deliver_message
|
67
|
+
::Kafka::Client.class_eval do
|
68
|
+
alias_method :deliver_message_original, :deliver_message
|
69
|
+
|
70
|
+
def deliver_message(value, key: nil, headers: {}, topic:, partition: nil, partition_key: nil, retries: 1)
|
71
|
+
if ::Kafka::Tracer.ignore_message.call(value, key, headers, topic, partition, partition_key)
|
72
|
+
result = deliver_message_original(value,
|
73
|
+
key: key,
|
74
|
+
headers: headers,
|
75
|
+
topic: topic,
|
76
|
+
partition: partition,
|
77
|
+
partition_key: partition_key,
|
78
|
+
retries: retries)
|
79
|
+
else
|
80
|
+
tags = {
|
81
|
+
'component' => 'ruby-kafka',
|
82
|
+
'span.kind' => 'producer',
|
83
|
+
'message_bus.partition' => partition,
|
84
|
+
'message_bus.partition_key' => partition_key,
|
85
|
+
'message_bus.destination' => topic,
|
86
|
+
'message_bus.pending_message' => false
|
87
|
+
}
|
88
|
+
|
89
|
+
tracer = ::Kafka::Tracer.tracer
|
90
|
+
|
91
|
+
tracer.start_active_span('kafka.producer', tags: tags) do |scope|
|
92
|
+
OpenTracing.inject(scope.span.context, OpenTracing::FORMAT_TEXT_MAP, headers)
|
93
|
+
|
94
|
+
begin
|
95
|
+
result = deliver_message_original(value,
|
96
|
+
key: key,
|
97
|
+
headers: headers,
|
98
|
+
topic: topic,
|
99
|
+
partition: partition,
|
100
|
+
partition_key: partition_key,
|
101
|
+
retries: retries)
|
102
|
+
rescue Kafka::Error => e
|
103
|
+
scope.span.set_tag('error', true)
|
104
|
+
raise
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
result
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# used to send a batch of messages
|
115
|
+
def patch_producer_produce
|
116
|
+
::Kafka::Producer.class_eval do
|
117
|
+
alias_method :produce_original, :produce
|
118
|
+
|
119
|
+
def produce(value, key: nil, headers: {}, topic:, partition: nil, partition_key: nil, create_time: Time.now)
|
120
|
+
|
121
|
+
if ::Kafka::Tracer.ignore_message.call(value, key, headers, topic, partition, partition_key)
|
122
|
+
result = produce_original(
|
123
|
+
value,
|
124
|
+
key: key,
|
125
|
+
headers: headers,
|
126
|
+
topic: topic,
|
127
|
+
partition: partition,
|
128
|
+
partition_key: partition_key,
|
129
|
+
create_time: create_time
|
130
|
+
)
|
131
|
+
|
132
|
+
else
|
133
|
+
tags = {
|
134
|
+
'component' => 'ruby-kafka',
|
135
|
+
'span.kind' => 'producer',
|
136
|
+
'message_bus.partition' => partition,
|
137
|
+
'message_bus.partition_key' => partition_key,
|
138
|
+
'message_bus.destination' => topic,
|
139
|
+
'message_bus.pending_message' => true
|
140
|
+
}
|
141
|
+
|
142
|
+
tracer = ::Kafka::Tracer.tracer
|
143
|
+
|
144
|
+
tracer.start_active_span('kafka.producer', tags: tags) do |scope|
|
145
|
+
OpenTracing.inject(scope.span.context, OpenTracing::FORMAT_TEXT_MAP, headers)
|
146
|
+
|
147
|
+
begin
|
148
|
+
result = produce_original(
|
149
|
+
value,
|
150
|
+
key: key,
|
151
|
+
headers: headers,
|
152
|
+
topic: topic,
|
153
|
+
partition: partition,
|
154
|
+
partition_key: partition_key,
|
155
|
+
create_time: create_time
|
156
|
+
)
|
157
|
+
rescue Kafka::Error => e
|
158
|
+
scope.span.set_tag('error', true)
|
159
|
+
raise
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
result
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# TODO
|
170
|
+
def patch_deliver_messages; end
|
171
|
+
|
172
|
+
def patch_client_each_message
|
173
|
+
::Kafka::Client.class_eval do
|
174
|
+
alias_method :each_message_original, :each_message
|
175
|
+
|
176
|
+
def each_message(topic:, start_from_beginning: true, max_wait_time: 5, min_bytes: 1, max_bytes: 1_048_576, &block)
|
177
|
+
tracer = ::Kafka::Tracer.tracer
|
178
|
+
|
179
|
+
wrapped_block = lambda { |message|
|
180
|
+
context = tracer.extract(OpenTracing::FORMAT_TEXT_MAP, message.headers)
|
181
|
+
|
182
|
+
tags = {
|
183
|
+
'component' => 'ruby-kafka',
|
184
|
+
'span.kind' => 'consumer',
|
185
|
+
'message_bus.partition' => message.partition,
|
186
|
+
'message_bus.destination' => message.topic,
|
187
|
+
'message_bus.pre_fetched_in_batch' => true
|
188
|
+
}
|
189
|
+
|
190
|
+
tracer.start_active_span('kafka.consumer', child_of: context, tags: tags) do |scope|
|
191
|
+
begin
|
192
|
+
block.call(message)
|
193
|
+
rescue StandardError
|
194
|
+
scope.span.set_tag('error', true)
|
195
|
+
raise
|
196
|
+
end
|
197
|
+
end
|
198
|
+
}
|
199
|
+
|
200
|
+
each_message_original(
|
201
|
+
topic: topic,
|
202
|
+
start_from_beginning: start_from_beginning,
|
203
|
+
max_wait_time: max_wait_time,
|
204
|
+
min_bytes: min_bytes,
|
205
|
+
max_bytes: max_bytes,
|
206
|
+
&wrapped_block
|
207
|
+
)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def patch_consumer_each_message
|
213
|
+
::Kafka::Consumer.class_eval do
|
214
|
+
alias_method :each_message_original, :each_message
|
215
|
+
|
216
|
+
def each_message(min_bytes: 1, max_bytes: 10485760, max_wait_time: 1, automatically_mark_as_processed: true)
|
217
|
+
tracer = ::Kafka::Tracer.tracer
|
218
|
+
|
219
|
+
wrapped_block = lambda { |message|
|
220
|
+
context = tracer.extract(OpenTracing::FORMAT_TEXT_MAP, message.headers)
|
221
|
+
|
222
|
+
tags = {
|
223
|
+
'component' => 'ruby-kafka',
|
224
|
+
'span.kind' => 'consumer',
|
225
|
+
'message_bus.partition' => message.partition,
|
226
|
+
'message_bus.destination' => message.topic,
|
227
|
+
'message_bus.pre_fetched_in_batch' => true
|
228
|
+
}
|
229
|
+
|
230
|
+
tracer.start_active_span('kafka.consumer', child_of: context, tags: tags) do |scope|
|
231
|
+
begin
|
232
|
+
yield message
|
233
|
+
rescue StandardError
|
234
|
+
scope.span.set_tag('error', true)
|
235
|
+
raise
|
236
|
+
end
|
237
|
+
end
|
238
|
+
}
|
239
|
+
|
240
|
+
each_message_original(
|
241
|
+
min_bytes: min_bytes,
|
242
|
+
max_bytes: max_bytes,
|
243
|
+
max_wait_time: max_wait_time,
|
244
|
+
automatically_mark_as_processed: automatically_mark_as_processed,
|
245
|
+
&wrapped_block
|
246
|
+
)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'kafka/tracer'
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kafka-opentracing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Fischer
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: opentracing
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.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: 0.5.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby-kafka
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.7.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.7.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: Instruments the ruby-kafka gem for opentracing
|
84
|
+
email:
|
85
|
+
- ben.fischer.810@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CHANGELOG.md
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- kafka-opentracing.gemspec
|
103
|
+
- lib/kafka-opentracing.rb
|
104
|
+
- lib/kafka/tracer.rb
|
105
|
+
- lib/kafka/tracer/version.rb
|
106
|
+
homepage: https://github.com/benedictfischer09/ruby-kafka-instrumentation
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata:
|
110
|
+
allowed_push_host: https://rubygems.org
|
111
|
+
homepage_uri: https://github.com/benedictfischer09/ruby-kafka-instrumentation
|
112
|
+
source_code_uri: https://github.com/benedictfischer09/ruby-kafka-instrumentation
|
113
|
+
changelog_uri: https://github.com/benedictfischer09/ruby-kafka-instrumentation/master/CHANGELOG.md
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.5.2.3
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Instruments the ruby-kafka gem for opentracing
|
134
|
+
test_files: []
|