honeykiq 1.1.0.pre → 1.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 +4 -4
- data/CHANGELOG.md +7 -1
- data/Gemfile.lock +1 -1
- data/README.md +20 -27
- data/lib/honeykiq/periodic_reporter.rb +6 -6
- data/lib/honeykiq/server_middleware.rb +22 -15
- data/lib/honeykiq/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29a3d18dbdcd28d505474e7066089b0bbde7b9db3faa0b994fbc0e54fa412dc2
|
4
|
+
data.tar.gz: b31189efcefaabde05722510097b1ad746c92f542f4e749993c94d775223af9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0495bb5f2d2ba5f2848e4dbe8a58c4d8d97c7c905bca2d33b2692a33ac33ad56ec49ff0368a52f0bbc8265ea971e356a49237bd8aa006efcbc40245110362667'
|
7
|
+
data.tar.gz: 7c702869ffdcc5bedcad9145c3d9979a63d96fa8540b01140272ee743d5b825839ace3dfe478fc2f2b7762ea31050b69001720f8d4dd790d82e47e44f7031730
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,11 @@ 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.1.0]
|
10
|
+
### Added
|
11
|
+
- Honeycomb beeline support (#9)
|
12
|
+
|
8
13
|
## [1.0.0]
|
9
14
|
### Added
|
10
15
|
- CODE_OF_CONDUCT.md
|
@@ -28,7 +33,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
28
33
|
### Removed
|
29
34
|
- `Honeykiq.periodic_reporter`. (Use `Honeykiq::PeriodicReporter.new` instead.)
|
30
35
|
|
31
|
-
[Unreleased]: https://github.com/carwow/honeykiq/compare/v1.
|
36
|
+
[Unreleased]: https://github.com/carwow/honeykiq/compare/v1.1.0...HEAD
|
37
|
+
[1.1.0]: https://github.com/carwow/honeykiq/compare/v1.0.0...v1.1.0
|
32
38
|
[1.0.0]: https://github.com/carwow/honeykiq/compare/v0.3.1...v1.0.0
|
33
39
|
[0.3.1]: https://github.com/carwow/honeykiq/compare/v0.3.0...v0.3.1
|
34
40
|
[0.3.0]: https://github.com/carwow/honeykiq/compare/v0.2.0...v0.3.0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -32,11 +32,13 @@ to see what kind of information it sends.
|
|
32
32
|
[server_middleware.rb]: https://github.com/carwow/honeykiq/blob/master/lib/honeykiq/server_middleware.rb
|
33
33
|
|
34
34
|
```ruby
|
35
|
-
# Configure Honeycomb
|
35
|
+
# Configure Honeycomb beeline
|
36
36
|
Honeycomb.configure do |config|
|
37
37
|
config.writekey = ENV.fetch('HONEYCOMB_WRITE_KEY')
|
38
38
|
config.dataset = ENV.fetch('HONEYCOMB_DATASET')
|
39
39
|
end
|
40
|
+
|
41
|
+
# Add the middleware to Sidekiq chain
|
40
42
|
Sidekiq.configure_server do |config|
|
41
43
|
config.server_middleware do |chain|
|
42
44
|
chain.add Honeykiq::ServerMiddleware
|
@@ -47,7 +49,7 @@ end
|
|
47
49
|
Sidekiq.configure_server do |config|
|
48
50
|
config.server_middleware do |chain|
|
49
51
|
chain.add Honeykiq::ServerMiddleware,
|
50
|
-
|
52
|
+
libhoney: Libhoney::Client.new(
|
51
53
|
writekey: ENV.fetch('HONEYCOMB_WRITE_KEY'),
|
52
54
|
dataset: ENV.fetch('HONEYCOMB_DATASET')
|
53
55
|
)
|
@@ -56,7 +58,7 @@ end
|
|
56
58
|
```
|
57
59
|
|
58
60
|
You can add your own data or functions to the Honeycomb event by subclassing
|
59
|
-
`Honeykiq::ServerMiddleware`, and overriding the
|
61
|
+
`Honeykiq::ServerMiddleware`, and overriding the `extra_fields` method with
|
60
62
|
your own hash. The contents will be serialized into individual items in the
|
61
63
|
event:
|
62
64
|
|
@@ -72,16 +74,16 @@ end
|
|
72
74
|
|
73
75
|
Sidekiq.configure_server do |config|
|
74
76
|
config.server_middleware do |chain|
|
75
|
-
chain.add MyServerMiddleware
|
76
|
-
|
77
|
+
chain.add MyServerMiddleware
|
78
|
+
end
|
79
|
+
end
|
77
80
|
```
|
78
81
|
|
79
82
|
**Note:** If you have long running jobs, an event is only sent to Honeycomb
|
80
83
|
when the job finishes. Therefore, it may appear as though no jobs are currently
|
81
84
|
running. Additionally, if the process receives a `SIGKILL` then no event is
|
82
85
|
sent about that job, and the job may keep retrying without appearing in
|
83
|
-
Honeycomb. The `PeriodicReporter`
|
84
|
-
a nicer approach.
|
86
|
+
Honeycomb. The `PeriodicReporter` provides visibility for these cases.
|
85
87
|
|
86
88
|
### Honeykiq::PeriodicReporter
|
87
89
|
|
@@ -98,37 +100,27 @@ type.
|
|
98
100
|
|
99
101
|
A setup using [clockwork] to report every 30 seconds would look like this:
|
100
102
|
|
101
|
-
|
102
103
|
```ruby
|
104
|
+
require 'honeycomb-beeline'
|
103
105
|
require 'clockwork'
|
104
|
-
require 'libhoney'
|
105
106
|
require 'honeykiq'
|
106
107
|
|
107
|
-
|
108
|
-
|
108
|
+
Honeycomb.configure do |config|
|
109
|
+
config.writekey = ENV.fetch('HONEYCOMB_WRITE_KEY')
|
110
|
+
config.dataset = ENV.fetch('HONEYCOMB_DATASET')
|
109
111
|
end
|
110
112
|
|
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
|
-
)
|
113
|
+
module Clockwork
|
114
|
+
every(30, 'Honeykiq::PeriodicReporter') do
|
115
|
+
Honeykiq::PeriodicReporter.new.report
|
125
116
|
end
|
126
117
|
end
|
127
118
|
```
|
128
119
|
|
129
120
|
## Contributing
|
130
121
|
|
131
|
-
[Pull requests](https://github.com/carwow/honeykiq/pulls) are very welcome!
|
122
|
+
[Pull requests](https://github.com/carwow/honeykiq/pulls) are very welcome!
|
123
|
+
Don't forget to add yourself to [CONTRIBUTORS.txt].
|
132
124
|
|
133
125
|
Please report bugs in a [new issue](https://github.com/carwow/honeykiq/issues/new).
|
134
126
|
|
@@ -136,6 +128,7 @@ Please report bugs in a [new issue](https://github.com/carwow/honeykiq/issues/ne
|
|
136
128
|
|
137
129
|
## License
|
138
130
|
|
139
|
-
The gem is available as open source under the terms of the
|
131
|
+
The gem is available as open source under the terms of the
|
132
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
140
133
|
|
141
134
|
[clockwork]: https://github.com/Rykian/clockwork
|
@@ -2,8 +2,8 @@ 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,
|
@@ -57,7 +57,7 @@ module Honeykiq
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def send_process_event(process, &extra)
|
60
|
-
|
60
|
+
libhoney.event.add(
|
61
61
|
type: :process,
|
62
62
|
'meta.dyno': process['hostname'],
|
63
63
|
'meta.process_id': process['pid'],
|
@@ -68,7 +68,7 @@ module Honeykiq
|
|
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,
|
@@ -2,20 +2,16 @@ 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)
|
6
|
+
@libhoney = libhoney || honey_client
|
7
7
|
end
|
8
8
|
|
9
9
|
def call(_worker, msg, queue_name)
|
10
10
|
job = Sidekiq::Job.new(msg, queue_name)
|
11
|
+
queue = Sidekiq::Queue.new(queue_name)
|
11
12
|
|
12
13
|
start_span(name: job.display_class) do |event|
|
13
|
-
call_with_event(event, job,
|
14
|
-
rescue StandardError => error
|
15
|
-
on_error(event, error)
|
16
|
-
raise
|
17
|
-
ensure
|
18
|
-
event&.add(extra_fields)
|
14
|
+
call_with_event(event, job, queue) { yield }
|
19
15
|
end
|
20
16
|
end
|
21
17
|
|
@@ -25,9 +21,15 @@ module Honeykiq
|
|
25
21
|
|
26
22
|
private
|
27
23
|
|
24
|
+
attr_reader :libhoney
|
25
|
+
|
26
|
+
def libhoney?
|
27
|
+
!!libhoney
|
28
|
+
end
|
29
|
+
|
28
30
|
def start_span(name:)
|
29
|
-
if
|
30
|
-
|
31
|
+
if libhoney?
|
32
|
+
libhoney.event.tap do |event|
|
31
33
|
duration_ms(event) { yield event }
|
32
34
|
ensure
|
33
35
|
event.send
|
@@ -37,17 +39,22 @@ module Honeykiq
|
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
|
-
def call_with_event(event, job,
|
41
|
-
event.add(default_fields(job,
|
42
|
+
def call_with_event(event, job, queue)
|
43
|
+
event.add(default_fields(job, queue))
|
42
44
|
yield
|
43
45
|
event.add_field(:'job.status', 'finished')
|
46
|
+
rescue StandardError => error
|
47
|
+
on_error(event, error)
|
48
|
+
raise
|
49
|
+
ensure
|
50
|
+
event.add(extra_fields)
|
44
51
|
end
|
45
52
|
|
46
|
-
def default_fields(job,
|
53
|
+
def default_fields(job, queue)
|
47
54
|
{
|
48
55
|
type: :job,
|
49
56
|
**job_fields(job),
|
50
|
-
**queue_fields(
|
57
|
+
**queue_fields(queue),
|
51
58
|
'meta.thread_id': Thread.current.object_id
|
52
59
|
}
|
53
60
|
end
|
@@ -82,7 +89,7 @@ module Honeykiq
|
|
82
89
|
return unless event
|
83
90
|
|
84
91
|
event.add_field(:'job.status', 'failed')
|
85
|
-
return unless
|
92
|
+
return unless libhoney?
|
86
93
|
|
87
94
|
event.add(
|
88
95
|
'error.class': error.class.name,
|
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.1.0
|
4
|
+
version: 1.1.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-05-
|
11
|
+
date: 2020-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -148,9 +148,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
148
|
version: '0'
|
149
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
150
|
requirements:
|
151
|
-
- - "
|
151
|
+
- - ">="
|
152
152
|
- !ruby/object:Gem::Version
|
153
|
-
version:
|
153
|
+
version: '0'
|
154
154
|
requirements: []
|
155
155
|
rubygems_version: 3.1.2
|
156
156
|
signing_key:
|