honeykiq 1.1.0.pre → 1.4.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 +4 -4
- data/.circleci/config.yml +14 -45
- data/.gitignore +2 -3
- data/CHANGELOG.md +30 -1
- data/Gemfile +1 -1
- data/README.md +84 -35
- data/Rakefile +4 -3
- data/honeykiq.gemspec +18 -26
- data/lib/honeykiq/beeline_span.rb +59 -0
- data/lib/honeykiq/client_middleware.rb +9 -0
- data/lib/honeykiq/libhoney_span.rb +37 -0
- data/lib/honeykiq/periodic_reporter.rb +15 -15
- data/lib/honeykiq/server_middleware.rb +39 -40
- data/lib/honeykiq/version.rb +1 -1
- data/lib/honeykiq.rb +6 -3
- metadata +40 -54
- data/.rubocop.yml +0 -3
- data/CONTRIBUTORS.txt +0 -3
- data/Gemfile.lock +0 -106
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b58704c1073bcabb4c4604e1b2859fe2c5e12441ff9a6147a04ba91b81502a51
|
4
|
+
data.tar.gz: 996f68a12ea08d129d1f824301b8b555222ce1627eb31bfd9061f0310c0b2a15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ea76eb835772915a56f91f9441369f5d1cdfa5ab8c08782116e3a9d7ce65737fb4c4ce83ad4130708993b5c0a5ae03c51aaba756525249139b1752176231652
|
7
|
+
data.tar.gz: 59a504ebcf7c30ddb427717bd4f92a1a77f4d412ff6a0cf48c2380fbc5e2f86a7d9b8e36589a2f234bd9101f1c11fce5de4481a27fdce87ee71f364ac3a0a8d6
|
data/.circleci/config.yml
CHANGED
@@ -1,54 +1,23 @@
|
|
1
|
-
|
2
|
-
image: carwow/ruby-ci:2.6
|
3
|
-
|
4
|
-
version: 2
|
1
|
+
version: 2.1
|
5
2
|
|
6
3
|
jobs:
|
7
|
-
|
8
|
-
|
4
|
+
test:
|
5
|
+
parameters:
|
6
|
+
ruby:
|
7
|
+
type: string
|
9
8
|
docker:
|
10
|
-
-
|
9
|
+
- image: 'cimg/ruby:<< parameters.ruby >>'
|
11
10
|
steps:
|
12
11
|
- checkout
|
13
|
-
-
|
14
|
-
|
15
|
-
|
16
|
-
- bundle-
|
17
|
-
- run: |
|
18
|
-
bundle config --local path vendor/bundle &&
|
19
|
-
bundle check || bundle install --jobs=4 --retry=3
|
20
|
-
- save_cache:
|
21
|
-
key: bundle-{{ checksum "Gemfile.lock" }}
|
22
|
-
paths: [~/honeykiq/vendor/bundle]
|
23
|
-
- persist_to_workspace:
|
24
|
-
root: '~'
|
25
|
-
paths: [honeykiq]
|
26
|
-
|
27
|
-
rubocop:
|
28
|
-
working_directory: ~/honeykiq
|
29
|
-
docker:
|
30
|
-
- *ruby
|
31
|
-
steps:
|
32
|
-
- attach_workspace:
|
33
|
-
at: '~'
|
34
|
-
- run: bundle exec rubocop
|
35
|
-
|
36
|
-
tests:
|
37
|
-
working_directory: ~/honeykiq
|
38
|
-
docker:
|
39
|
-
- *ruby
|
40
|
-
steps:
|
41
|
-
- attach_workspace:
|
42
|
-
at: '~'
|
43
|
-
- run: |
|
44
|
-
bundle exec rspec
|
12
|
+
- run: bundle install
|
13
|
+
- run: bundle exec rspec
|
14
|
+
- run: bundle exec standardrb
|
45
15
|
|
46
16
|
workflows:
|
47
17
|
version: 2
|
48
|
-
|
18
|
+
test:
|
49
19
|
jobs:
|
50
|
-
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
requires: [bundle]
|
20
|
+
- test:
|
21
|
+
matrix:
|
22
|
+
parameters:
|
23
|
+
ruby: ["2.7", "2.6"]
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,32 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
|
+
|
9
|
+
## [1.4.0]
|
10
|
+
### Added
|
11
|
+
- Support for `:child_trace` mode (#19)
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
- Support sidekiq v6.2.2 (#23)
|
15
|
+
- Link events respect beeline sampling (#17)
|
16
|
+
WARNING: This is technically a breaking change since it now sends
|
17
|
+
`meta.annotation_type` field instead of `meta.span_type` for the link event,
|
18
|
+
but `meta.span_type` is deprecated for annotation events since it already has
|
19
|
+
another use case which the beeline uses. I believe no one is actually using
|
20
|
+
link events anyway. If you run into problems and need help, open an issue.
|
21
|
+
|
22
|
+
## [1.3.0]
|
23
|
+
### Added
|
24
|
+
- Allow beeline tracing to be configured (#11)
|
25
|
+
|
26
|
+
## [1.2.0]
|
27
|
+
### Added
|
28
|
+
- Allow extra_fields to be invoked with job (#16)
|
29
|
+
|
30
|
+
## [1.1.0]
|
31
|
+
### Added
|
32
|
+
- Honeycomb beeline support (#9)
|
33
|
+
|
8
34
|
## [1.0.0]
|
9
35
|
### Added
|
10
36
|
- CODE_OF_CONDUCT.md
|
@@ -28,7 +54,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
28
54
|
### Removed
|
29
55
|
- `Honeykiq.periodic_reporter`. (Use `Honeykiq::PeriodicReporter.new` instead.)
|
30
56
|
|
31
|
-
[Unreleased]: https://github.com/carwow/honeykiq/compare/v1.
|
57
|
+
[Unreleased]: https://github.com/carwow/honeykiq/compare/v1.2.0...HEAD
|
58
|
+
[1.3.0]: https://github.com/carwow/honeykiq/compare/v1.2.0...v1.3.0
|
59
|
+
[1.2.0]: https://github.com/carwow/honeykiq/compare/v1.1.0...v1.2.0
|
60
|
+
[1.1.0]: https://github.com/carwow/honeykiq/compare/v1.0.0...v1.1.0
|
32
61
|
[1.0.0]: https://github.com/carwow/honeykiq/compare/v0.3.1...v1.0.0
|
33
62
|
[0.3.1]: https://github.com/carwow/honeykiq/compare/v0.3.0...v0.3.1
|
34
63
|
[0.3.0]: https://github.com/carwow/honeykiq/compare/v0.2.0...v0.3.0
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -15,14 +15,67 @@ gem 'honeykiq'
|
|
15
15
|
|
16
16
|
## Usage
|
17
17
|
|
18
|
-
The library provides
|
18
|
+
The library provides three use cases:
|
19
19
|
|
20
|
+
- [`Honeykiq::ClientMiddleware`]
|
20
21
|
- [`Honeykiq::ServerMiddleware`]
|
21
22
|
- [`Honeykiq::PeriodicReporter`]
|
22
23
|
|
24
|
+
[`Honeykiq::ClientMiddleware`]: #HoneykiqClientMiddleware
|
23
25
|
[`Honeykiq::ServerMiddleware`]: #HoneykiqServerMiddleware
|
24
26
|
[`Honeykiq::PeriodicReporter`]: #HoneykiqPeriodicReporter
|
25
27
|
|
28
|
+
### Honeykiq::ClientMiddleware
|
29
|
+
|
30
|
+
Add Honeykiq to your Sidekiq client middleware chain. It will propagate tracing
|
31
|
+
fields when used in combination with `Honeykiq::ServerMiddleware`.
|
32
|
+
|
33
|
+
This middleware is **only** configured to work with the `Honeycomb` beeline gem,
|
34
|
+
not with a custom `Libhoney` client.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
# Configure Honeycomb beeline
|
38
|
+
Honeycomb.configure do |config|
|
39
|
+
config.write_key = ENV.fetch('HONEYCOMB_WRITE_KEY')
|
40
|
+
config.dataset = ENV.fetch('HONEYCOMB_DATASET')
|
41
|
+
end
|
42
|
+
|
43
|
+
# Add the middleware to Sidekiq chain
|
44
|
+
Sidekiq.configure_client do |config|
|
45
|
+
config.client_middleware do |chain|
|
46
|
+
chain.add Honeykiq::ClientMiddleware
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Also add it to the server client chain
|
51
|
+
Sidekiq.configure_server do |config|
|
52
|
+
# Configure the server client, used when a worker enqueues a job itself.
|
53
|
+
config.client_middleware do |chain|
|
54
|
+
chain.add Honeykiq::ClientMiddleware
|
55
|
+
end
|
56
|
+
|
57
|
+
# Configure ServerMiddleware with a tracing mode
|
58
|
+
config.server_middleware do |chain|
|
59
|
+
# tracing_mode: options are nil (default), :child, :child_trace, :link
|
60
|
+
#
|
61
|
+
# - nil (default) starts a span and trace when the job executes.
|
62
|
+
#
|
63
|
+
# - :child starts a span as a child of the enqueuing trace,
|
64
|
+
# requires ClientMiddleware to be configured when enqueuing the job.
|
65
|
+
#
|
66
|
+
# - :child_trace (experimental) starts a span and a trace
|
67
|
+
# with trace.parent_id set to the enqueuing trace id,
|
68
|
+
# requires ClientMiddleware to be configured when enqueuing the job.
|
69
|
+
#
|
70
|
+
# - :link (experimental) starts a span and trace
|
71
|
+
# with a link event that points to the enqueuing trace,
|
72
|
+
# requires ClientMiddleware to be configured when enqueuing the job.
|
73
|
+
# https://docs.honeycomb.io/getting-data-in/tracing/send-trace-data/#links
|
74
|
+
chain.add Honeykiq::ServerMiddleware, tracing_mode: :child
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
26
79
|
### Honeykiq::ServerMiddleware
|
27
80
|
|
28
81
|
Add Honeykiq to your Sidekiq server middleware chain. It will send an event to
|
@@ -32,11 +85,13 @@ to see what kind of information it sends.
|
|
32
85
|
[server_middleware.rb]: https://github.com/carwow/honeykiq/blob/master/lib/honeykiq/server_middleware.rb
|
33
86
|
|
34
87
|
```ruby
|
35
|
-
# Configure Honeycomb
|
88
|
+
# Configure Honeycomb beeline
|
36
89
|
Honeycomb.configure do |config|
|
37
|
-
config.
|
90
|
+
config.write_key = ENV.fetch('HONEYCOMB_WRITE_KEY')
|
38
91
|
config.dataset = ENV.fetch('HONEYCOMB_DATASET')
|
39
92
|
end
|
93
|
+
|
94
|
+
# Add the middleware to Sidekiq chain
|
40
95
|
Sidekiq.configure_server do |config|
|
41
96
|
config.server_middleware do |chain|
|
42
97
|
chain.add Honeykiq::ServerMiddleware
|
@@ -47,8 +102,8 @@ end
|
|
47
102
|
Sidekiq.configure_server do |config|
|
48
103
|
config.server_middleware do |chain|
|
49
104
|
chain.add Honeykiq::ServerMiddleware,
|
50
|
-
|
51
|
-
|
105
|
+
libhoney: Libhoney::Client.new(
|
106
|
+
write_key: ENV.fetch('HONEYCOMB_WRITE_KEY'),
|
52
107
|
dataset: ENV.fetch('HONEYCOMB_DATASET')
|
53
108
|
)
|
54
109
|
end
|
@@ -56,13 +111,13 @@ end
|
|
56
111
|
```
|
57
112
|
|
58
113
|
You can add your own data or functions to the Honeycomb event by subclassing
|
59
|
-
`Honeykiq::ServerMiddleware`, and overriding the
|
114
|
+
`Honeykiq::ServerMiddleware`, and overriding the `extra_fields` method with
|
60
115
|
your own hash. The contents will be serialized into individual items in the
|
61
116
|
event:
|
62
117
|
|
63
118
|
```ruby
|
64
119
|
class MyServerMiddleware < Honeykiq::ServerMiddleware
|
65
|
-
def extra_fields
|
120
|
+
def extra_fields(job) # Sidekiq::Job instance
|
66
121
|
{
|
67
122
|
my_data: 'evaluated and added to the event after the job has finished/errored',
|
68
123
|
my_function: -> { Time.now }
|
@@ -72,16 +127,16 @@ end
|
|
72
127
|
|
73
128
|
Sidekiq.configure_server do |config|
|
74
129
|
config.server_middleware do |chain|
|
75
|
-
chain.add MyServerMiddleware
|
76
|
-
|
130
|
+
chain.add MyServerMiddleware
|
131
|
+
end
|
132
|
+
end
|
77
133
|
```
|
78
134
|
|
79
135
|
**Note:** If you have long running jobs, an event is only sent to Honeycomb
|
80
136
|
when the job finishes. Therefore, it may appear as though no jobs are currently
|
81
137
|
running. Additionally, if the process receives a `SIGKILL` then no event is
|
82
138
|
sent about that job, and the job may keep retrying without appearing in
|
83
|
-
Honeycomb. The `PeriodicReporter`
|
84
|
-
a nicer approach.
|
139
|
+
Honeycomb. The `PeriodicReporter` provides visibility for these cases.
|
85
140
|
|
86
141
|
### Honeykiq::PeriodicReporter
|
87
142
|
|
@@ -98,44 +153,38 @@ type.
|
|
98
153
|
|
99
154
|
A setup using [clockwork] to report every 30 seconds would look like this:
|
100
155
|
|
101
|
-
|
102
156
|
```ruby
|
157
|
+
require 'honeycomb-beeline'
|
103
158
|
require 'clockwork'
|
104
|
-
require 'libhoney'
|
105
159
|
require 'honeykiq'
|
106
160
|
|
107
|
-
|
108
|
-
|
161
|
+
Honeycomb.configure do |config|
|
162
|
+
config.write_key = ENV.fetch('HONEYCOMB_WRITE_KEY')
|
163
|
+
config.dataset = ENV.fetch('HONEYCOMB_DATASET')
|
109
164
|
end
|
110
165
|
|
111
|
-
module
|
112
|
-
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
def self.reporter
|
117
|
-
@reporter ||= Honeykiq::PeriodicReporter.new(honey_client: honey_client)
|
118
|
-
end
|
119
|
-
|
120
|
-
def self.honey_client
|
121
|
-
Libhoney::Client.new(
|
122
|
-
writekey: ENV.fetch('HONEYCOMB_WRITE_KEY'),
|
123
|
-
dataset: ENV.fetch('HONEYCOMB_DATASET')
|
124
|
-
)
|
166
|
+
module Clockwork
|
167
|
+
every(30, 'Honeykiq::PeriodicReporter') do
|
168
|
+
Honeykiq::PeriodicReporter.new.report
|
125
169
|
end
|
126
170
|
end
|
127
171
|
```
|
128
172
|
|
173
|
+
[clockwork]: https://github.com/Rykian/clockwork
|
174
|
+
|
129
175
|
## Contributing
|
130
176
|
|
131
|
-
[Pull requests]
|
177
|
+
[Pull requests] are very welcome!
|
132
178
|
|
133
|
-
Please report bugs in a [new issue]
|
179
|
+
Please report bugs in a [new issue].
|
134
180
|
|
135
|
-
[
|
181
|
+
Everyone is expected to follow the [code of conduct].
|
136
182
|
|
137
|
-
|
183
|
+
[Pull requests]: https://github.com/carwow/honeykiq/pulls
|
184
|
+
[new issue]: https://github.com/carwow/honeykiq/issues/new
|
185
|
+
[code of conduct]: https://github.com/carwow/honeykiq/tree/master/CODE_OF_CONDUCT.md
|
138
186
|
|
139
|
-
|
187
|
+
## License
|
140
188
|
|
141
|
-
|
189
|
+
The gem is available as open source under the terms of the
|
190
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
data/honeykiq.gemspec
CHANGED
@@ -1,35 +1,27 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require 'honeykiq/version'
|
1
|
+
require_relative "lib/honeykiq/version"
|
4
2
|
|
5
3
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.authors
|
9
|
-
spec.email
|
10
|
-
spec.summary
|
11
|
-
spec.description
|
12
|
-
spec.homepage
|
13
|
-
spec.license
|
4
|
+
spec.name = "honeykiq"
|
5
|
+
spec.version = Honeykiq::VERSION
|
6
|
+
spec.authors = ["carwow Developers"]
|
7
|
+
spec.email = ["developers@carwow.co.uk"]
|
8
|
+
spec.summary = "Sidekiq → Honeycomb 🐝"
|
9
|
+
spec.description = "Send Sidekiq related events to Honeycomb."
|
10
|
+
spec.homepage = "https://github.com/carwow/honeykiq"
|
11
|
+
spec.license = "MIT"
|
14
12
|
|
15
|
-
|
16
|
-
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
17
|
-
else
|
18
|
-
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
19
|
-
'public gem pushes.'
|
20
|
-
end
|
13
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
14
|
|
22
15
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(
|
16
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|example)/}) }
|
24
17
|
end
|
25
|
-
spec.require_paths = [
|
18
|
+
spec.require_paths = ["lib"]
|
26
19
|
|
27
|
-
spec.add_dependency
|
20
|
+
spec.add_dependency "sidekiq", "~> 6.2.2"
|
28
21
|
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency 'rspec'
|
22
|
+
spec.add_development_dependency "honeycomb-beeline", "~> 2.6"
|
23
|
+
spec.add_development_dependency "pry", "~> 0.14"
|
24
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.10"
|
26
|
+
spec.add_development_dependency "standard", "~> 0.13"
|
35
27
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Honeykiq
|
2
|
+
class BeelineSpan
|
3
|
+
def initialize(tracing_mode)
|
4
|
+
@tracing_mode = tracing_mode
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(name:, serialized_trace:, &block)
|
8
|
+
case tracing_mode
|
9
|
+
when :link then link_span(name, serialized_trace, &block)
|
10
|
+
when :child then child_span(name, serialized_trace, &block)
|
11
|
+
when :child_trace then child_trace(name, serialized_trace, &block)
|
12
|
+
else Honeycomb.start_span(name: name, &block)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :tracing_mode
|
19
|
+
|
20
|
+
def link_span(name, serialized_trace)
|
21
|
+
Honeycomb.start_span(name: name) do |event|
|
22
|
+
link_to_enqueuing_trace(event, serialized_trace)
|
23
|
+
|
24
|
+
yield event
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def link_to_enqueuing_trace(current, serialized_trace)
|
29
|
+
return unless serialized_trace
|
30
|
+
|
31
|
+
trace_id, parent_span_id, = TraceParser.parse(serialized_trace)
|
32
|
+
|
33
|
+
Honeycomb.start_span(
|
34
|
+
name: "link",
|
35
|
+
'trace.link.trace_id': trace_id,
|
36
|
+
'trace.link.span_id': parent_span_id,
|
37
|
+
'meta.annotation_type': "link",
|
38
|
+
'trace.parent_id': current.id,
|
39
|
+
'trace.trace_id': current.trace.id
|
40
|
+
).send
|
41
|
+
end
|
42
|
+
|
43
|
+
def child_span(name, serialized_trace, &block)
|
44
|
+
Honeycomb.start_span(name: name, serialized_trace: serialized_trace, &block)
|
45
|
+
end
|
46
|
+
|
47
|
+
def child_trace(name, serialized_trace, &block)
|
48
|
+
parent_trace_id, = TraceParser.parse(serialized_trace)
|
49
|
+
|
50
|
+
Honeycomb.start_span(name: name, 'parent.trace_id': parent_trace_id, &block)
|
51
|
+
end
|
52
|
+
|
53
|
+
if defined?(Honeycomb)
|
54
|
+
class TraceParser
|
55
|
+
extend Honeycomb::PropagationParser
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Honeykiq
|
2
|
+
class LibhoneySpan
|
3
|
+
def initialize(libhoney)
|
4
|
+
@libhoney = libhoney
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(*)
|
8
|
+
libhoney.event.tap do |event|
|
9
|
+
duration_ms(event) { yield event }
|
10
|
+
ensure
|
11
|
+
event.send
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :libhoney
|
18
|
+
|
19
|
+
def duration_ms(event)
|
20
|
+
start_time = now
|
21
|
+
yield
|
22
|
+
ensure
|
23
|
+
duration = now - start_time
|
24
|
+
event.add_field(:duration_ms, duration * 1000)
|
25
|
+
end
|
26
|
+
|
27
|
+
if defined?(Process::CLOCK_MONOTONIC)
|
28
|
+
def now
|
29
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
def now
|
33
|
+
Time.now
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require "sidekiq/api"
|
2
2
|
|
3
3
|
module Honeykiq
|
4
4
|
class PeriodicReporter
|
5
|
-
def initialize(honey_client:)
|
6
|
-
@
|
5
|
+
def initialize(libhoney: nil, honey_client: nil)
|
6
|
+
@libhoney = libhoney || honey_client || Honeycomb.libhoney
|
7
7
|
end
|
8
8
|
|
9
9
|
def report(&extra)
|
@@ -14,10 +14,10 @@ module Honeykiq
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
attr_reader :
|
17
|
+
attr_reader :libhoney
|
18
18
|
|
19
19
|
def send_instance_event(&extra)
|
20
|
-
|
20
|
+
libhoney.event.add(
|
21
21
|
type: :instance,
|
22
22
|
**instance_stats,
|
23
23
|
**redis_stats,
|
@@ -42,33 +42,33 @@ module Honeykiq
|
|
42
42
|
redis_info = fetch_redis_info
|
43
43
|
|
44
44
|
{
|
45
|
-
'redis.connections': redis_info[
|
46
|
-
'redis.memory_used': redis_info[
|
45
|
+
'redis.connections': redis_info["connected_clients"].to_i,
|
46
|
+
'redis.memory_used': redis_info["used_memory"].to_i
|
47
47
|
}
|
48
48
|
end
|
49
49
|
|
50
50
|
def fetch_redis_info
|
51
51
|
Sidekiq.redis do |redis|
|
52
|
-
redis.pipelined
|
52
|
+
redis.pipelined {
|
53
53
|
redis.info :clients
|
54
54
|
redis.info :memory
|
55
|
-
|
55
|
+
}.reduce(&:merge)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
def send_process_event(process, &extra)
|
60
|
-
|
60
|
+
libhoney.event.add(
|
61
61
|
type: :process,
|
62
|
-
'meta.dyno': process[
|
63
|
-
'meta.process_id': process[
|
64
|
-
'process.concurrency': process[
|
65
|
-
'process.busy': process[
|
62
|
+
'meta.dyno': process["hostname"],
|
63
|
+
'meta.process_id': process["pid"],
|
64
|
+
'process.concurrency': process["concurrency"],
|
65
|
+
'process.busy': process["busy"],
|
66
66
|
**(extra&.call(:process, process) || {})
|
67
67
|
).send
|
68
68
|
end
|
69
69
|
|
70
70
|
def send_queue_event(queue, &extra)
|
71
|
-
|
71
|
+
libhoney.event.add(
|
72
72
|
type: :queue,
|
73
73
|
'queue.name': queue.name,
|
74
74
|
'queue.latency_sec': queue.latency.to_f,
|
@@ -1,53 +1,53 @@
|
|
1
|
-
require
|
1
|
+
require "sidekiq/api"
|
2
2
|
|
3
3
|
module Honeykiq
|
4
4
|
class ServerMiddleware
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(libhoney: nil, honey_client: nil, tracing_mode: nil)
|
6
|
+
@libhoney = libhoney || honey_client
|
7
|
+
@tracing_mode = tracing_mode
|
7
8
|
end
|
8
9
|
|
9
10
|
def call(_worker, msg, queue_name)
|
10
|
-
job = Sidekiq::
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
on_error(event, error)
|
16
|
-
raise
|
17
|
-
ensure
|
18
|
-
event&.add(extra_fields)
|
11
|
+
job = Sidekiq::JobRecord.new(msg, queue_name)
|
12
|
+
queue = Sidekiq::Queue.new(queue_name)
|
13
|
+
|
14
|
+
span_builder.call(name: job.display_class, serialized_trace: msg["serialized_trace"]) do |event|
|
15
|
+
call_with_event(event, job, queue) { yield }
|
19
16
|
end
|
20
17
|
end
|
21
18
|
|
22
|
-
def extra_fields
|
19
|
+
def extra_fields(_job = nil)
|
23
20
|
{}
|
24
21
|
end
|
25
22
|
|
26
23
|
private
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
ensure
|
33
|
-
event.send
|
34
|
-
end
|
35
|
-
else
|
36
|
-
Honeycomb.start_span(name: name) { |event| yield event }
|
37
|
-
end
|
25
|
+
attr_reader :libhoney, :tracing_mode
|
26
|
+
|
27
|
+
def libhoney?
|
28
|
+
!!libhoney
|
38
29
|
end
|
39
30
|
|
40
|
-
def
|
41
|
-
|
31
|
+
def span_builder
|
32
|
+
@span_builder ||= libhoney? ? LibhoneySpan.new(libhoney) : BeelineSpan.new(tracing_mode)
|
33
|
+
end
|
34
|
+
|
35
|
+
def call_with_event(event, job, queue)
|
36
|
+
event.add(default_fields(job, queue))
|
42
37
|
yield
|
43
|
-
event.add_field(:'job.status',
|
38
|
+
event.add_field(:'job.status', "finished")
|
39
|
+
rescue => error
|
40
|
+
on_error(event, error)
|
41
|
+
raise
|
42
|
+
ensure
|
43
|
+
event.add(call_extra_fields(job))
|
44
44
|
end
|
45
45
|
|
46
|
-
def default_fields(job,
|
46
|
+
def default_fields(job, queue)
|
47
47
|
{
|
48
48
|
type: :job,
|
49
49
|
**job_fields(job),
|
50
|
-
**queue_fields(
|
50
|
+
**queue_fields(queue),
|
51
51
|
'meta.thread_id': Thread.current.object_id
|
52
52
|
}
|
53
53
|
end
|
@@ -55,11 +55,11 @@ module Honeykiq
|
|
55
55
|
def job_fields(job)
|
56
56
|
{
|
57
57
|
'job.class': job.display_class,
|
58
|
-
'job.attempt_number': (job[
|
58
|
+
'job.attempt_number': (job["retry_count"].to_i.nonzero? || 0) + 1,
|
59
59
|
'job.id': job.jid,
|
60
60
|
'job.arguments_bytes': job.args.to_json.bytesize,
|
61
61
|
'job.latency_sec': job.latency,
|
62
|
-
'job.batch_id': job[
|
62
|
+
'job.batch_id': job["bid"]
|
63
63
|
}.compact
|
64
64
|
end
|
65
65
|
|
@@ -70,24 +70,23 @@ module Honeykiq
|
|
70
70
|
}
|
71
71
|
end
|
72
72
|
|
73
|
-
def duration_ms(event)
|
74
|
-
start_time = Time.now
|
75
|
-
yield
|
76
|
-
ensure
|
77
|
-
duration = Time.now - start_time
|
78
|
-
event.add_field(:duration_ms, duration * 1000)
|
79
|
-
end
|
80
|
-
|
81
73
|
def on_error(event, error)
|
82
74
|
return unless event
|
83
75
|
|
84
|
-
event.add_field(:'job.status',
|
85
|
-
return unless
|
76
|
+
event.add_field(:'job.status', "failed")
|
77
|
+
return unless libhoney?
|
86
78
|
|
87
79
|
event.add(
|
88
80
|
'error.class': error.class.name,
|
89
81
|
'error.message': error.message
|
90
82
|
)
|
91
83
|
end
|
84
|
+
|
85
|
+
def call_extra_fields(job)
|
86
|
+
case method(:extra_fields).arity
|
87
|
+
when 0 then extra_fields
|
88
|
+
else extra_fields(job)
|
89
|
+
end
|
90
|
+
end
|
92
91
|
end
|
93
92
|
end
|
data/lib/honeykiq/version.rb
CHANGED
data/lib/honeykiq.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module Honeykiq
|
2
|
-
autoload :
|
3
|
-
autoload :PeriodicReporter,
|
4
|
-
autoload :ServerMiddleware,
|
2
|
+
autoload :VERSION, "honeykiq/version"
|
3
|
+
autoload :PeriodicReporter, "honeykiq/periodic_reporter"
|
4
|
+
autoload :ServerMiddleware, "honeykiq/server_middleware"
|
5
|
+
autoload :ClientMiddleware, "honeykiq/client_middleware"
|
6
|
+
autoload :BeelineSpan, "honeykiq/beeline_span"
|
7
|
+
autoload :LibhoneySpan, "honeykiq/libhoney_span"
|
5
8
|
end
|
metadata
CHANGED
@@ -1,113 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: honeykiq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- carwow Developers
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.2.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.2.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
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
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: carwow_rubocop
|
28
|
+
name: honeycomb-beeline
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
|
-
- - "
|
31
|
+
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
33
|
+
version: '2.6'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- - "
|
38
|
+
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
40
|
+
version: '2.6'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
42
|
+
name: pry
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
|
-
- - "
|
45
|
+
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
47
|
+
version: '0.14'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
|
-
- - "
|
52
|
+
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
54
|
+
version: '0.14'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
56
|
+
name: rake
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
|
-
- - "
|
59
|
+
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
61
|
+
version: '13.0'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- - "
|
66
|
+
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
68
|
+
version: '13.0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
70
|
+
name: rspec
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
|
-
- - "
|
73
|
+
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
75
|
+
version: '3.10'
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
|
-
- - "
|
80
|
+
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
82
|
+
version: '3.10'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
84
|
+
name: standard
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
|
-
- - "
|
87
|
+
- - "~>"
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
89
|
+
version: '0.13'
|
104
90
|
type: :development
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
|
-
- - "
|
94
|
+
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
96
|
+
version: '0.13'
|
111
97
|
description: Send Sidekiq related events to Honeycomb.
|
112
98
|
email:
|
113
99
|
- developers@carwow.co.uk
|
@@ -118,17 +104,17 @@ files:
|
|
118
104
|
- ".circleci/config.yml"
|
119
105
|
- ".gitignore"
|
120
106
|
- ".rspec"
|
121
|
-
- ".rubocop.yml"
|
122
107
|
- CHANGELOG.md
|
123
108
|
- CODE_OF_CONDUCT.md
|
124
|
-
- CONTRIBUTORS.txt
|
125
109
|
- Gemfile
|
126
|
-
- Gemfile.lock
|
127
110
|
- LICENSE.txt
|
128
111
|
- README.md
|
129
112
|
- Rakefile
|
130
113
|
- honeykiq.gemspec
|
131
114
|
- lib/honeykiq.rb
|
115
|
+
- lib/honeykiq/beeline_span.rb
|
116
|
+
- lib/honeykiq/client_middleware.rb
|
117
|
+
- lib/honeykiq/libhoney_span.rb
|
132
118
|
- lib/honeykiq/periodic_reporter.rb
|
133
119
|
- lib/honeykiq/server_middleware.rb
|
134
120
|
- lib/honeykiq/version.rb
|
@@ -137,7 +123,7 @@ licenses:
|
|
137
123
|
- MIT
|
138
124
|
metadata:
|
139
125
|
allowed_push_host: https://rubygems.org
|
140
|
-
post_install_message:
|
126
|
+
post_install_message:
|
141
127
|
rdoc_options: []
|
142
128
|
require_paths:
|
143
129
|
- lib
|
@@ -148,12 +134,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
134
|
version: '0'
|
149
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
136
|
requirements:
|
151
|
-
- - "
|
137
|
+
- - ">="
|
152
138
|
- !ruby/object:Gem::Version
|
153
|
-
version:
|
139
|
+
version: '0'
|
154
140
|
requirements: []
|
155
|
-
rubygems_version: 3.1.
|
156
|
-
signing_key:
|
141
|
+
rubygems_version: 3.1.4
|
142
|
+
signing_key:
|
157
143
|
specification_version: 4
|
158
144
|
summary: "Sidekiq → Honeycomb \U0001F41D"
|
159
145
|
test_files: []
|
data/.rubocop.yml
DELETED
data/CONTRIBUTORS.txt
DELETED
data/Gemfile.lock
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
honeykiq (1.1.0.pre)
|
5
|
-
sidekiq
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
addressable (2.7.0)
|
11
|
-
public_suffix (>= 2.0.2, < 5.0)
|
12
|
-
ast (2.4.0)
|
13
|
-
carwow_rubocop (3.2.2)
|
14
|
-
rubocop (>= 0.78)
|
15
|
-
rubocop-performance
|
16
|
-
rubocop-rspec
|
17
|
-
coderay (1.1.2)
|
18
|
-
connection_pool (2.2.2)
|
19
|
-
diff-lcs (1.3)
|
20
|
-
domain_name (0.5.20190701)
|
21
|
-
unf (>= 0.0.5, < 1.0.0)
|
22
|
-
ffi (1.12.2)
|
23
|
-
ffi-compiler (1.0.1)
|
24
|
-
ffi (>= 1.0.0)
|
25
|
-
rake
|
26
|
-
honeycomb-beeline (2.0.0)
|
27
|
-
libhoney (~> 1.14, >= 1.14.2)
|
28
|
-
http (4.4.1)
|
29
|
-
addressable (~> 2.3)
|
30
|
-
http-cookie (~> 1.0)
|
31
|
-
http-form_data (~> 2.2)
|
32
|
-
http-parser (~> 1.2.0)
|
33
|
-
http-cookie (1.0.3)
|
34
|
-
domain_name (~> 0.5)
|
35
|
-
http-form_data (2.3.0)
|
36
|
-
http-parser (1.2.1)
|
37
|
-
ffi-compiler (>= 1.0, < 2.0)
|
38
|
-
jaro_winkler (1.5.4)
|
39
|
-
libhoney (1.14.4)
|
40
|
-
addressable (~> 2.0)
|
41
|
-
http (>= 2.0, < 5.0)
|
42
|
-
method_source (1.0.0)
|
43
|
-
parallel (1.19.1)
|
44
|
-
parser (2.7.1.2)
|
45
|
-
ast (~> 2.4.0)
|
46
|
-
pry (0.13.1)
|
47
|
-
coderay (~> 1.1)
|
48
|
-
method_source (~> 1.0)
|
49
|
-
public_suffix (4.0.5)
|
50
|
-
rack (2.2.2)
|
51
|
-
rack-protection (2.0.8.1)
|
52
|
-
rack
|
53
|
-
rainbow (3.0.0)
|
54
|
-
rake (13.0.1)
|
55
|
-
redis (4.1.4)
|
56
|
-
rexml (3.2.4)
|
57
|
-
rspec (3.9.0)
|
58
|
-
rspec-core (~> 3.9.0)
|
59
|
-
rspec-expectations (~> 3.9.0)
|
60
|
-
rspec-mocks (~> 3.9.0)
|
61
|
-
rspec-core (3.9.2)
|
62
|
-
rspec-support (~> 3.9.3)
|
63
|
-
rspec-expectations (3.9.2)
|
64
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
-
rspec-support (~> 3.9.0)
|
66
|
-
rspec-mocks (3.9.1)
|
67
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
68
|
-
rspec-support (~> 3.9.0)
|
69
|
-
rspec-support (3.9.3)
|
70
|
-
rubocop (0.82.0)
|
71
|
-
jaro_winkler (~> 1.5.1)
|
72
|
-
parallel (~> 1.10)
|
73
|
-
parser (>= 2.7.0.1)
|
74
|
-
rainbow (>= 2.2.2, < 4.0)
|
75
|
-
rexml
|
76
|
-
ruby-progressbar (~> 1.7)
|
77
|
-
unicode-display_width (>= 1.4.0, < 2.0)
|
78
|
-
rubocop-performance (1.5.2)
|
79
|
-
rubocop (>= 0.71.0)
|
80
|
-
rubocop-rspec (1.39.0)
|
81
|
-
rubocop (>= 0.68.1)
|
82
|
-
ruby-progressbar (1.10.1)
|
83
|
-
sidekiq (6.0.7)
|
84
|
-
connection_pool (>= 2.2.2)
|
85
|
-
rack (~> 2.0)
|
86
|
-
rack-protection (>= 2.0.0)
|
87
|
-
redis (>= 4.1.0)
|
88
|
-
unf (0.1.4)
|
89
|
-
unf_ext
|
90
|
-
unf_ext (0.0.7.7)
|
91
|
-
unicode-display_width (1.7.0)
|
92
|
-
|
93
|
-
PLATFORMS
|
94
|
-
ruby
|
95
|
-
|
96
|
-
DEPENDENCIES
|
97
|
-
bundler
|
98
|
-
carwow_rubocop
|
99
|
-
honeycomb-beeline
|
100
|
-
honeykiq!
|
101
|
-
pry
|
102
|
-
rake
|
103
|
-
rspec
|
104
|
-
|
105
|
-
BUNDLED WITH
|
106
|
-
2.1.4
|