honeykiq 0.3.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +1 -1
- data/CHANGELOG.md +26 -1
- data/CODE_OF_CONDUCT.md +70 -0
- data/Gemfile.lock +70 -60
- data/README.md +100 -45
- data/honeykiq.gemspec +1 -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/periodic_reporter.rb +6 -6
- data/lib/honeykiq/server_middleware.rb +45 -26
- data/lib/honeykiq/version.rb +1 -1
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
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/.circleci/config.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,27 @@ 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.3.0]
|
10
|
+
### Added
|
11
|
+
- Allow beeline tracing to be configured (#11)
|
12
|
+
|
13
|
+
## [1.2.0]
|
14
|
+
### Added
|
15
|
+
- Allow extra_fields to be invoked with job (#16)
|
16
|
+
|
17
|
+
## [1.1.0]
|
18
|
+
### Added
|
19
|
+
- Honeycomb beeline support (#9)
|
20
|
+
|
21
|
+
## [1.0.0]
|
22
|
+
### Added
|
23
|
+
- CODE_OF_CONDUCT.md
|
24
|
+
- CONTRIBUTORS.txt
|
25
|
+
|
26
|
+
### Fixed
|
27
|
+
- Tidied up README.md
|
28
|
+
|
8
29
|
## [0.3.1]
|
9
30
|
### Fixed
|
10
31
|
- Ensure that `Honeykiq::ServerMiddleware#extra_fields` are still included after a job fails
|
@@ -20,7 +41,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
20
41
|
### Removed
|
21
42
|
- `Honeykiq.periodic_reporter`. (Use `Honeykiq::PeriodicReporter.new` instead.)
|
22
43
|
|
23
|
-
[Unreleased]: https://github.com/carwow/honeykiq/compare/
|
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
|
46
|
+
[1.2.0]: https://github.com/carwow/honeykiq/compare/v1.1.0...v1.2.0
|
47
|
+
[1.1.0]: https://github.com/carwow/honeykiq/compare/v1.0.0...v1.1.0
|
48
|
+
[1.0.0]: https://github.com/carwow/honeykiq/compare/v0.3.1...v1.0.0
|
24
49
|
[0.3.1]: https://github.com/carwow/honeykiq/compare/v0.3.0...v0.3.1
|
25
50
|
[0.3.0]: https://github.com/carwow/honeykiq/compare/v0.2.0...v0.3.0
|
26
51
|
[0.2.0]: https://github.com/carwow/honeykiq/compare/v0.1.0...v0.2.0
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as contributors and
|
6
|
+
maintainers pledge to making participation in our project and our community a
|
7
|
+
harassment-free experience for everyone, regardless of age, body size, disability,
|
8
|
+
ethnicity, gender identity and expression, level of experience, education, socio-economic
|
9
|
+
status, 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 include:
|
15
|
+
|
16
|
+
* Using welcoming and inclusive language
|
17
|
+
* Being respectful of differing viewpoints and experiences
|
18
|
+
* Gracefully accepting constructive criticism
|
19
|
+
* Focusing on what is best for the community
|
20
|
+
* Showing empathy towards other community members
|
21
|
+
|
22
|
+
Examples of unacceptable behavior by participants include:
|
23
|
+
|
24
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
25
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
26
|
+
* Public or private harassment
|
27
|
+
* Publishing others' private information, such as a physical or electronic address,
|
28
|
+
without explicit permission
|
29
|
+
* Other conduct which could reasonably be considered inappropriate in a professional
|
30
|
+
setting
|
31
|
+
|
32
|
+
## Our Responsibilities
|
33
|
+
|
34
|
+
Project maintainers are responsible for clarifying the standards of acceptable behavior
|
35
|
+
and are expected to take appropriate and fair corrective action in response to any
|
36
|
+
instances of unacceptable behavior.
|
37
|
+
|
38
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments,
|
39
|
+
commits, code, wiki edits, issues, and other contributions that are not aligned to this
|
40
|
+
Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors
|
41
|
+
that they deem inappropriate, threatening, offensive, or harmful.
|
42
|
+
|
43
|
+
## Scope
|
44
|
+
|
45
|
+
This Code of Conduct applies both within project spaces and in public spaces when an
|
46
|
+
individual is representing the project or its community. Examples of representing a
|
47
|
+
project or community include using an official project e-mail address, posting via an
|
48
|
+
official social media account, or acting as an appointed representative at an online or
|
49
|
+
offline event. Representation of a project may be further defined and clarified by project
|
50
|
+
maintainers.
|
51
|
+
|
52
|
+
## Enforcement
|
53
|
+
|
54
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
|
55
|
+
contacting the [project team](developers@carwow.co.uk). All complaints will be reviewed and
|
56
|
+
investigated and will result in a response that is deemed necessary and appropriate to the
|
57
|
+
circumstances. The project team is obligated to maintain confidentiality with regard to
|
58
|
+
the reporter of an incident. Further details of specific enforcement policies may be
|
59
|
+
posted separately.
|
60
|
+
|
61
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may
|
62
|
+
face temporary or permanent repercussions as determined by other members of the project's
|
63
|
+
leadership.
|
64
|
+
|
65
|
+
## Attribution
|
66
|
+
|
67
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
68
|
+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
69
|
+
|
70
|
+
[homepage]: https://www.contributor-covenant.org
|
data/Gemfile.lock
CHANGED
@@ -1,84 +1,94 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
honeykiq (
|
4
|
+
honeykiq (1.3.0)
|
5
5
|
sidekiq
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
addressable (2.
|
11
|
-
public_suffix (>= 2.0.2, <
|
12
|
-
ast (2.4.
|
13
|
-
carwow_rubocop (
|
14
|
-
rubocop (
|
15
|
-
rubocop-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
addressable (2.7.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
|
+
ast (2.4.1)
|
13
|
+
carwow_rubocop (3.3.0)
|
14
|
+
rubocop (>= 0.78)
|
15
|
+
rubocop-performance
|
16
|
+
rubocop-rspec
|
17
|
+
coderay (1.1.3)
|
18
|
+
connection_pool (2.2.3)
|
19
|
+
diff-lcs (1.4.4)
|
20
|
+
domain_name (0.5.20190701)
|
20
21
|
unf (>= 0.0.5, < 1.0.0)
|
21
|
-
|
22
|
+
ffi (1.13.1)
|
23
|
+
ffi-compiler (1.0.1)
|
24
|
+
ffi (>= 1.0.0)
|
25
|
+
rake
|
26
|
+
honeycomb-beeline (2.1.1)
|
27
|
+
libhoney (~> 1.14, >= 1.14.2)
|
28
|
+
http (4.4.1)
|
22
29
|
addressable (~> 2.3)
|
23
30
|
http-cookie (~> 1.0)
|
24
|
-
http-form_data (~> 2.
|
25
|
-
|
31
|
+
http-form_data (~> 2.2)
|
32
|
+
http-parser (~> 1.2.0)
|
26
33
|
http-cookie (1.0.3)
|
27
34
|
domain_name (~> 0.5)
|
28
|
-
http-form_data (2.
|
29
|
-
|
30
|
-
|
31
|
-
libhoney (1.
|
35
|
+
http-form_data (2.3.0)
|
36
|
+
http-parser (1.2.1)
|
37
|
+
ffi-compiler (>= 1.0, < 2.0)
|
38
|
+
libhoney (1.14.4)
|
32
39
|
addressable (~> 2.0)
|
33
|
-
http (>= 2.0, <
|
34
|
-
method_source (0.
|
35
|
-
parallel (1.
|
36
|
-
parser (2.
|
37
|
-
ast (~> 2.4.
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
rack (2.0.8)
|
44
|
-
rack-protection (2.0.8.1)
|
45
|
-
rack
|
40
|
+
http (>= 2.0, < 5.0)
|
41
|
+
method_source (1.0.0)
|
42
|
+
parallel (1.19.2)
|
43
|
+
parser (2.7.1.4)
|
44
|
+
ast (~> 2.4.1)
|
45
|
+
pry (0.13.1)
|
46
|
+
coderay (~> 1.1)
|
47
|
+
method_source (~> 1.0)
|
48
|
+
public_suffix (4.0.5)
|
49
|
+
rack (2.2.3)
|
46
50
|
rainbow (3.0.0)
|
47
|
-
rake (
|
48
|
-
redis (4.1
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
rspec-
|
53
|
-
|
54
|
-
rspec-
|
55
|
-
rspec-
|
51
|
+
rake (13.0.1)
|
52
|
+
redis (4.2.1)
|
53
|
+
regexp_parser (1.7.1)
|
54
|
+
rexml (3.2.4)
|
55
|
+
rspec (3.9.0)
|
56
|
+
rspec-core (~> 3.9.0)
|
57
|
+
rspec-expectations (~> 3.9.0)
|
58
|
+
rspec-mocks (~> 3.9.0)
|
59
|
+
rspec-core (3.9.2)
|
60
|
+
rspec-support (~> 3.9.3)
|
61
|
+
rspec-expectations (3.9.2)
|
56
62
|
diff-lcs (>= 1.2.0, < 2.0)
|
57
|
-
rspec-support (~> 3.
|
58
|
-
rspec-mocks (3.
|
63
|
+
rspec-support (~> 3.9.0)
|
64
|
+
rspec-mocks (3.9.1)
|
59
65
|
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
-
rspec-support (~> 3.
|
61
|
-
rspec-support (3.
|
62
|
-
rubocop (0.
|
63
|
-
jaro_winkler (~> 1.5.1)
|
66
|
+
rspec-support (~> 3.9.0)
|
67
|
+
rspec-support (3.9.3)
|
68
|
+
rubocop (0.88.0)
|
64
69
|
parallel (~> 1.10)
|
65
|
-
parser (>= 2.
|
66
|
-
powerpack (~> 0.1)
|
70
|
+
parser (>= 2.7.1.1)
|
67
71
|
rainbow (>= 2.2.2, < 4.0)
|
72
|
+
regexp_parser (>= 1.7)
|
73
|
+
rexml
|
74
|
+
rubocop-ast (>= 0.1.0, < 1.0)
|
68
75
|
ruby-progressbar (~> 1.7)
|
69
|
-
unicode-display_width (
|
70
|
-
rubocop-
|
71
|
-
|
72
|
-
|
73
|
-
|
76
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
77
|
+
rubocop-ast (0.2.0)
|
78
|
+
parser (>= 2.7.0.1)
|
79
|
+
rubocop-performance (1.7.1)
|
80
|
+
rubocop (>= 0.82.0)
|
81
|
+
rubocop-rspec (1.42.0)
|
82
|
+
rubocop (>= 0.87.0)
|
83
|
+
ruby-progressbar (1.10.1)
|
84
|
+
sidekiq (6.1.1)
|
74
85
|
connection_pool (>= 2.2.2)
|
75
|
-
rack (
|
76
|
-
|
77
|
-
redis (>= 4.1.0)
|
86
|
+
rack (~> 2.0)
|
87
|
+
redis (>= 4.2.0)
|
78
88
|
unf (0.1.4)
|
79
89
|
unf_ext
|
80
|
-
unf_ext (0.0.7.
|
81
|
-
unicode-display_width (1.
|
90
|
+
unf_ext (0.0.7.7)
|
91
|
+
unicode-display_width (1.7.0)
|
82
92
|
|
83
93
|
PLATFORMS
|
84
94
|
ruby
|
@@ -86,11 +96,11 @@ PLATFORMS
|
|
86
96
|
DEPENDENCIES
|
87
97
|
bundler
|
88
98
|
carwow_rubocop
|
99
|
+
honeycomb-beeline
|
89
100
|
honeykiq!
|
90
|
-
libhoney
|
91
101
|
pry
|
92
102
|
rake
|
93
103
|
rspec
|
94
104
|
|
95
105
|
BUNDLED WITH
|
96
|
-
1.
|
106
|
+
2.1.4
|
data/README.md
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
|
3
3
|
Sidekiq → Honeycomb 🐝
|
4
4
|
|
5
|
-
Send Sidekiq
|
5
|
+
Send [Sidekiq](https://sidekiq.org)-related events to
|
6
|
+
[Honeycomb](https://www.honeycomb.io).
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
9
|
-
Add this line to your application's Gemfile
|
10
|
+
Add this line to your application's `Gemfile`:
|
10
11
|
|
11
12
|
```ruby
|
12
13
|
gem 'honeykiq'
|
@@ -14,27 +15,80 @@ gem 'honeykiq'
|
|
14
15
|
|
15
16
|
## Usage
|
16
17
|
|
17
|
-
The library provides
|
18
|
+
The library provides three use cases:
|
18
19
|
|
20
|
+
- [`Honeykiq::ClientMiddleware`]
|
19
21
|
- [`Honeykiq::ServerMiddleware`]
|
20
22
|
- [`Honeykiq::PeriodicReporter`]
|
21
23
|
|
24
|
+
[`Honeykiq::ClientMiddleware`]: #HoneykiqClientMiddleware
|
22
25
|
[`Honeykiq::ServerMiddleware`]: #HoneykiqServerMiddleware
|
23
26
|
[`Honeykiq::PeriodicReporter`]: #HoneykiqPeriodicReporter
|
24
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
|
+
|
25
65
|
### Honeykiq::ServerMiddleware
|
26
66
|
|
27
|
-
Add
|
28
|
-
|
29
|
-
|
67
|
+
Add Honeykiq to your Sidekiq server middleware chain. It will send an event to
|
68
|
+
Honeycomb once a job finishes or fails. Have a look at [server_middleware.rb]
|
69
|
+
to see what kind of information it sends.
|
30
70
|
|
31
71
|
[server_middleware.rb]: https://github.com/carwow/honeykiq/blob/master/lib/honeykiq/server_middleware.rb
|
32
72
|
|
33
73
|
```ruby
|
74
|
+
# Configure Honeycomb beeline
|
75
|
+
Honeycomb.configure do |config|
|
76
|
+
config.writekey = ENV.fetch('HONEYCOMB_WRITE_KEY')
|
77
|
+
config.dataset = ENV.fetch('HONEYCOMB_DATASET')
|
78
|
+
end
|
79
|
+
|
80
|
+
# Add the middleware to Sidekiq chain
|
81
|
+
Sidekiq.configure_server do |config|
|
82
|
+
config.server_middleware do |chain|
|
83
|
+
chain.add Honeykiq::ServerMiddleware
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Or pass the libhoney client to the middleware
|
34
88
|
Sidekiq.configure_server do |config|
|
35
89
|
config.server_middleware do |chain|
|
36
90
|
chain.add Honeykiq::ServerMiddleware,
|
37
|
-
|
91
|
+
libhoney: Libhoney::Client.new(
|
38
92
|
writekey: ENV.fetch('HONEYCOMB_WRITE_KEY'),
|
39
93
|
dataset: ENV.fetch('HONEYCOMB_DATASET')
|
40
94
|
)
|
@@ -42,14 +96,14 @@ Sidekiq.configure_server do |config|
|
|
42
96
|
end
|
43
97
|
```
|
44
98
|
|
45
|
-
#### Adding extra data to events
|
46
99
|
You can add your own data or functions to the Honeycomb event by subclassing
|
47
|
-
`Honeykiq::ServerMiddleware
|
48
|
-
hash.
|
100
|
+
`Honeykiq::ServerMiddleware`, and overriding the `extra_fields` method with
|
101
|
+
your own hash. The contents will be serialized into individual items in the
|
102
|
+
event:
|
49
103
|
|
50
104
|
```ruby
|
51
105
|
class MyServerMiddleware < Honeykiq::ServerMiddleware
|
52
|
-
def extra_fields
|
106
|
+
def extra_fields(job) # Sidekiq::Job instance
|
53
107
|
{
|
54
108
|
my_data: 'evaluated and added to the event after the job has finished/errored',
|
55
109
|
my_function: -> { Time.now }
|
@@ -59,63 +113,64 @@ end
|
|
59
113
|
|
60
114
|
Sidekiq.configure_server do |config|
|
61
115
|
config.server_middleware do |chain|
|
62
|
-
chain.add MyServerMiddleware
|
63
|
-
|
116
|
+
chain.add MyServerMiddleware
|
117
|
+
end
|
118
|
+
end
|
64
119
|
```
|
65
120
|
|
66
|
-
**Note
|
67
|
-
|
68
|
-
|
69
|
-
job may keep retrying
|
70
|
-
|
121
|
+
**Note:** If you have long running jobs, an event is only sent to Honeycomb
|
122
|
+
when the job finishes. Therefore, it may appear as though no jobs are currently
|
123
|
+
running. Additionally, if the process receives a `SIGKILL` then no event is
|
124
|
+
sent about that job, and the job may keep retrying without appearing in
|
125
|
+
Honeycomb. The `PeriodicReporter` provides visibility for these cases.
|
71
126
|
|
72
127
|
### Honeykiq::PeriodicReporter
|
73
128
|
|
74
|
-
The periodic reporter should be scheduled to report every few seconds
|
75
|
-
on your use case
|
76
|
-
|
129
|
+
The periodic reporter should be scheduled to report every few seconds,
|
130
|
+
depending on your use case. Every time the `#report` method is called it will
|
131
|
+
send a total of `1 + P + Q` events to Honeycomb where `P` and `Q` are the
|
77
132
|
number of processes and queues respectively.
|
78
133
|
|
79
|
-
It sends three types of events: instance
|
80
|
-
[periodic_reporter.rb] to see what kind of information we send for each
|
134
|
+
It sends three types of events: `instance`, `process`, and `queue`. Have a look
|
135
|
+
at [periodic_reporter.rb] to see what kind of information we send for each
|
136
|
+
type.
|
81
137
|
|
82
138
|
[periodic_reporter.rb]: https://github.com/carwow/honeykiq/blob/master/lib/honeykiq/periodic_reporter.rb
|
83
139
|
|
84
|
-
A
|
85
|
-
|
86
|
-
[clockwork]: https://github.com/Rykian/clockwork
|
140
|
+
A setup using [clockwork] to report every 30 seconds would look like this:
|
87
141
|
|
88
142
|
```ruby
|
143
|
+
require 'honeycomb-beeline'
|
89
144
|
require 'clockwork'
|
90
|
-
require 'libhoney'
|
91
145
|
require 'honeykiq'
|
92
146
|
|
93
|
-
|
94
|
-
|
147
|
+
Honeycomb.configure do |config|
|
148
|
+
config.writekey = ENV.fetch('HONEYCOMB_WRITE_KEY')
|
149
|
+
config.dataset = ENV.fetch('HONEYCOMB_DATASET')
|
95
150
|
end
|
96
151
|
|
97
|
-
module
|
98
|
-
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
def self.reporter
|
103
|
-
@reporter ||= Honeykiq::PeriodicReporter.new(honey_client: honey_client)
|
104
|
-
end
|
105
|
-
|
106
|
-
def self.honey_client
|
107
|
-
Libhoney::Client.new(
|
108
|
-
writekey: ENV.fetch('HONEYCOMB_WRITE_KEY'),
|
109
|
-
dataset: ENV.fetch('HONEYCOMB_DATASET')
|
110
|
-
)
|
152
|
+
module Clockwork
|
153
|
+
every(30, 'Honeykiq::PeriodicReporter') do
|
154
|
+
Honeykiq::PeriodicReporter.new.report
|
111
155
|
end
|
112
156
|
end
|
113
157
|
```
|
114
158
|
|
159
|
+
[clockwork]: https://github.com/Rykian/clockwork
|
160
|
+
|
115
161
|
## Contributing
|
116
162
|
|
117
|
-
|
163
|
+
[Pull requests] are very welcome!
|
164
|
+
|
165
|
+
Please report bugs in a [new issue].
|
166
|
+
|
167
|
+
Everyone is expected to follow the [code of conduct].
|
168
|
+
|
169
|
+
[Pull requests]: https://github.com/carwow/honeykiq/pulls
|
170
|
+
[new issue]: https://github.com/carwow/honeykiq/issues/new
|
171
|
+
[code of conduct]: https://github.com/carwow/honeykiq/tree/master/CODE_OF_CONDUCT.md
|
118
172
|
|
119
173
|
## License
|
120
174
|
|
121
|
-
The gem is available as open source under the terms of the
|
175
|
+
The gem is available as open source under the terms of the
|
176
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
data/honeykiq.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
|
29
29
|
spec.add_development_dependency 'bundler'
|
30
30
|
spec.add_development_dependency 'carwow_rubocop'
|
31
|
-
spec.add_development_dependency '
|
31
|
+
spec.add_development_dependency 'honeycomb-beeline'
|
32
32
|
spec.add_development_dependency 'pry'
|
33
33
|
spec.add_development_dependency 'rake'
|
34
34
|
spec.add_development_dependency 'rspec'
|
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,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,40 +2,52 @@ 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
|
-
|
11
|
+
job = Sidekiq::Job.new(msg, queue_name)
|
12
|
+
queue = Sidekiq::Queue.new(queue_name)
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
event&.add(error_info(error))
|
16
|
-
raise
|
17
|
-
ensure
|
18
|
-
event&.add(extra_fields)
|
19
|
-
event&.send
|
14
|
+
span_builder.call(name: job.display_class, serialized_trace: msg['serialized_trace']) do |event|
|
15
|
+
call_with_event(event, job, queue) { yield }
|
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
|
-
|
25
|
+
attr_reader :libhoney, :tracing_mode
|
26
|
+
|
27
|
+
def libhoney?
|
28
|
+
!!libhoney
|
29
|
+
end
|
30
|
+
|
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))
|
37
|
+
yield
|
31
38
|
event.add_field(:'job.status', 'finished')
|
39
|
+
rescue StandardError => error
|
40
|
+
on_error(event, error)
|
41
|
+
raise
|
42
|
+
ensure
|
43
|
+
event.add(call_extra_fields(job))
|
32
44
|
end
|
33
45
|
|
34
|
-
def default_fields(
|
46
|
+
def default_fields(job, queue)
|
35
47
|
{
|
36
48
|
type: :job,
|
37
|
-
**job_fields(
|
38
|
-
**queue_fields(
|
49
|
+
**job_fields(job),
|
50
|
+
**queue_fields(queue),
|
39
51
|
'meta.thread_id': Thread.current.object_id
|
40
52
|
}
|
41
53
|
end
|
@@ -58,16 +70,23 @@ module Honeykiq
|
|
58
70
|
}
|
59
71
|
end
|
60
72
|
|
61
|
-
def
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
73
|
+
def on_error(event, error)
|
74
|
+
return unless event
|
75
|
+
|
76
|
+
event.add_field(:'job.status', 'failed')
|
77
|
+
return unless libhoney?
|
78
|
+
|
79
|
+
event.add(
|
80
|
+
'error.class': error.class.name,
|
81
|
+
'error.message': error.message
|
82
|
+
)
|
67
83
|
end
|
68
84
|
|
69
|
-
def
|
70
|
-
|
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
|
71
90
|
end
|
72
91
|
end
|
73
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:
|
4
|
+
version: 1.3.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: 2020-
|
11
|
+
date: 2020-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: honeycomb-beeline
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- ".rspec"
|
121
121
|
- ".rubocop.yml"
|
122
122
|
- CHANGELOG.md
|
123
|
+
- CODE_OF_CONDUCT.md
|
123
124
|
- Gemfile
|
124
125
|
- Gemfile.lock
|
125
126
|
- LICENSE.txt
|
@@ -127,6 +128,9 @@ files:
|
|
127
128
|
- Rakefile
|
128
129
|
- honeykiq.gemspec
|
129
130
|
- lib/honeykiq.rb
|
131
|
+
- lib/honeykiq/beeline_span.rb
|
132
|
+
- lib/honeykiq/client_middleware.rb
|
133
|
+
- lib/honeykiq/libhoney_span.rb
|
130
134
|
- lib/honeykiq/periodic_reporter.rb
|
131
135
|
- lib/honeykiq/server_middleware.rb
|
132
136
|
- lib/honeykiq/version.rb
|
@@ -135,7 +139,7 @@ licenses:
|
|
135
139
|
- MIT
|
136
140
|
metadata:
|
137
141
|
allowed_push_host: https://rubygems.org
|
138
|
-
post_install_message:
|
142
|
+
post_install_message:
|
139
143
|
rdoc_options: []
|
140
144
|
require_paths:
|
141
145
|
- lib
|
@@ -150,9 +154,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
154
|
- !ruby/object:Gem::Version
|
151
155
|
version: '0'
|
152
156
|
requirements: []
|
153
|
-
|
154
|
-
|
155
|
-
signing_key:
|
157
|
+
rubygems_version: 3.1.2
|
158
|
+
signing_key:
|
156
159
|
specification_version: 4
|
157
160
|
summary: "Sidekiq → Honeycomb \U0001F41D"
|
158
161
|
test_files: []
|