honeykiq 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +40 -1
- data/lib/honeykiq.rb +3 -0
- data/lib/honeykiq/beeline_span.rb +54 -0
- data/lib/honeykiq/client_middleware.rb +9 -0
- data/lib/honeykiq/libhoney_span.rb +37 -0
- data/lib/honeykiq/server_middleware.rb +6 -31
- data/lib/honeykiq/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd0cc1127fd3dfa658cb69820e243542bd84e614531405a8b95e4b9110e93bd7
|
4
|
+
data.tar.gz: 5e5d47b4301050821f7977e49da897e3dbd7f9d7312236cddd42dea0b3f29a7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4def9fb593162c5e7246527e50de7538561aad8153b31ecfa12b1182897445c09902b3a67f76cada6bffb4fdd542a10cfa08f8ae39cea73c201f51d86a4b0536
|
7
|
+
data.tar.gz: 03242d018493326a2314fe07c80a15fbaed72c048a300ae7226c9802057886920cccf86d93a6e43cc167fd9d3a2b8794c06863ca175025687b2c185cd3e84c95
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.3.0]
|
10
|
+
### Added
|
11
|
+
- Allow beeline tracing to be configured (#11)
|
12
|
+
|
9
13
|
## [1.2.0]
|
10
14
|
### Added
|
11
15
|
- Allow extra_fields to be invoked with job (#16)
|
@@ -38,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
38
42
|
- `Honeykiq.periodic_reporter`. (Use `Honeykiq::PeriodicReporter.new` instead.)
|
39
43
|
|
40
44
|
[Unreleased]: https://github.com/carwow/honeykiq/compare/v1.2.0...HEAD
|
45
|
+
[1.3.0]: https://github.com/carwow/honeykiq/compare/v1.2.0...v1.3.0
|
41
46
|
[1.2.0]: https://github.com/carwow/honeykiq/compare/v1.1.0...v1.2.0
|
42
47
|
[1.1.0]: https://github.com/carwow/honeykiq/compare/v1.0.0...v1.1.0
|
43
48
|
[1.0.0]: https://github.com/carwow/honeykiq/compare/v0.3.1...v1.0.0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -15,14 +15,53 @@ 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.writekey = 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_server do |config|
|
45
|
+
config.server_middleware do |chain|
|
46
|
+
# tracing_mode: options are :link or :child
|
47
|
+
# - :link will use link events https://docs.honeycomb.io/getting-data-in/tracing/send-trace-data/#links
|
48
|
+
# - :child will use add the job as a span to the enqueing trace
|
49
|
+
chain.add Honeykiq::ServerMiddleware, tracing_mode: :link
|
50
|
+
end
|
51
|
+
|
52
|
+
# Configure the servers client. Used when a worker enqueues a job itself.
|
53
|
+
config.client_middleware do |chain|
|
54
|
+
chain.add Honeykiq::ClientMiddleware
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
Sidekiq.configure_client do |config|
|
59
|
+
config.client_middleware do |chain|
|
60
|
+
chain.add Honeykiq::ClientMiddleware
|
61
|
+
end
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
26
65
|
### Honeykiq::ServerMiddleware
|
27
66
|
|
28
67
|
Add Honeykiq to your Sidekiq server middleware chain. It will send an event to
|
data/lib/honeykiq.rb
CHANGED
@@ -2,4 +2,7 @@ module Honeykiq
|
|
2
2
|
autoload :Version, 'honeykiq/version'
|
3
3
|
autoload :PeriodicReporter, 'honeykiq/periodic_reporter'
|
4
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
|
@@ -0,0 +1,54 @@
|
|
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
|
+
else
|
12
|
+
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 child_span(name, serialized_trace)
|
29
|
+
Honeycomb.start_span(name: name, serialized_trace: serialized_trace) do |event|
|
30
|
+
yield event
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def link_to_enqueuing_trace(current, serialized_trace)
|
35
|
+
return unless serialized_trace
|
36
|
+
|
37
|
+
trace_id, parent_span_id, = TraceParser.parse(serialized_trace)
|
38
|
+
|
39
|
+
Honeycomb.libhoney.event.add(
|
40
|
+
'trace.link.trace_id': trace_id,
|
41
|
+
'trace.link.span_id': parent_span_id,
|
42
|
+
'meta.span_type': 'link',
|
43
|
+
'trace.parent_id': current.id,
|
44
|
+
'trace.trace_id': current.trace.id
|
45
|
+
).send
|
46
|
+
end
|
47
|
+
|
48
|
+
if defined?(Honeycomb)
|
49
|
+
class TraceParser
|
50
|
+
extend Honeycomb::PropagationParser
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
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
|
@@ -2,15 +2,16 @@ require 'sidekiq/api'
|
|
2
2
|
|
3
3
|
module Honeykiq
|
4
4
|
class ServerMiddleware
|
5
|
-
def initialize(libhoney: nil, honey_client: nil)
|
5
|
+
def initialize(libhoney: nil, honey_client: nil, tracing_mode: nil)
|
6
6
|
@libhoney = libhoney || honey_client
|
7
|
+
@tracing_mode = tracing_mode
|
7
8
|
end
|
8
9
|
|
9
10
|
def call(_worker, msg, queue_name)
|
10
11
|
job = Sidekiq::Job.new(msg, queue_name)
|
11
12
|
queue = Sidekiq::Queue.new(queue_name)
|
12
13
|
|
13
|
-
|
14
|
+
span_builder.call(name: job.display_class, serialized_trace: msg['serialized_trace']) do |event|
|
14
15
|
call_with_event(event, job, queue) { yield }
|
15
16
|
end
|
16
17
|
end
|
@@ -21,22 +22,14 @@ module Honeykiq
|
|
21
22
|
|
22
23
|
private
|
23
24
|
|
24
|
-
attr_reader :libhoney
|
25
|
+
attr_reader :libhoney, :tracing_mode
|
25
26
|
|
26
27
|
def libhoney?
|
27
28
|
!!libhoney
|
28
29
|
end
|
29
30
|
|
30
|
-
def
|
31
|
-
|
32
|
-
libhoney.event.tap do |event|
|
33
|
-
duration_ms(event) { yield event }
|
34
|
-
ensure
|
35
|
-
event.send
|
36
|
-
end
|
37
|
-
else
|
38
|
-
Honeycomb.start_span(name: name) { |event| yield event }
|
39
|
-
end
|
31
|
+
def span_builder
|
32
|
+
@span_builder ||= libhoney? ? LibhoneySpan.new(libhoney) : BeelineSpan.new(tracing_mode)
|
40
33
|
end
|
41
34
|
|
42
35
|
def call_with_event(event, job, queue)
|
@@ -77,14 +70,6 @@ module Honeykiq
|
|
77
70
|
}
|
78
71
|
end
|
79
72
|
|
80
|
-
def duration_ms(event)
|
81
|
-
start_time = now
|
82
|
-
yield
|
83
|
-
ensure
|
84
|
-
duration = now - start_time
|
85
|
-
event.add_field(:duration_ms, duration * 1000)
|
86
|
-
end
|
87
|
-
|
88
73
|
def on_error(event, error)
|
89
74
|
return unless event
|
90
75
|
|
@@ -103,15 +88,5 @@ module Honeykiq
|
|
103
88
|
else extra_fields(job)
|
104
89
|
end
|
105
90
|
end
|
106
|
-
|
107
|
-
if defined?(Process::CLOCK_MONOTONIC)
|
108
|
-
def now
|
109
|
-
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
110
|
-
end
|
111
|
-
else
|
112
|
-
def now
|
113
|
-
Time.now
|
114
|
-
end
|
115
|
-
end
|
116
91
|
end
|
117
92
|
end
|
data/lib/honeykiq/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: honeykiq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- carwow Developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07
|
11
|
+
date: 2020-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -128,6 +128,9 @@ files:
|
|
128
128
|
- Rakefile
|
129
129
|
- honeykiq.gemspec
|
130
130
|
- lib/honeykiq.rb
|
131
|
+
- lib/honeykiq/beeline_span.rb
|
132
|
+
- lib/honeykiq/client_middleware.rb
|
133
|
+
- lib/honeykiq/libhoney_span.rb
|
131
134
|
- lib/honeykiq/periodic_reporter.rb
|
132
135
|
- lib/honeykiq/server_middleware.rb
|
133
136
|
- lib/honeykiq/version.rb
|