honeykiq 0.3.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bd68d2d6502122121c482fa34ed093f1d1e8fc55
4
- data.tar.gz: c78a51adabd03fff9f7e17b140eaaca58a310cd2
2
+ SHA256:
3
+ metadata.gz: 0707fda7ab02e35cece97138ce692a99aa4e94b4fdbd29e146f2a12c0e15c2e0
4
+ data.tar.gz: '0686f052a0cb97ea83f4621e079ea610a43ce3e9771f1155cdb36a962c9132e1'
5
5
  SHA512:
6
- metadata.gz: cb767053db59b6e3c568b9dba2059bb00d54c79c9fc6794148d81642a1cfcfee3bb27860a298218c620eaa739351bda563ecd56019eb7af68343381edc48905e
7
- data.tar.gz: f2c2a102e62632209fe9e4c120700e53677a167ec1aeb0300cd5f162001c48b181a0f5cb59aea58648b09fcf1f6d134d254b721a34ecd0af6b419e6547a5573c
6
+ metadata.gz: 071fb39ceafad14abc0f3dd9200cef6c6f1459d4c3f0b389b534ed110bf3c81e89d9800774ad6f06899fe598c89011253d2efccaf385d025ceff4690c36e404d
7
+ data.tar.gz: 001a4165c484889b3eba3755cf98d301c4bd6dc1a1a5274eb85ac05d5cfd49361080cb5ebb0c5723b77afb3d638dfef82d7c49cc940a9cf86c5f26a82016e3ff
@@ -1,5 +1,5 @@
1
1
  ruby: &ruby
2
- image: carwow/ruby-ci:2.5.3
2
+ image: carwow/ruby-ci:2.6
3
3
 
4
4
  version: 2
5
5
 
@@ -6,6 +6,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.2.0]
10
+ ### Added
11
+ - Allow extra_fields to be invoked with job (#16)
12
+
13
+ ## [1.1.0]
14
+ ### Added
15
+ - Honeycomb beeline support (#9)
16
+
17
+ ## [1.0.0]
18
+ ### Added
19
+ - CODE_OF_CONDUCT.md
20
+ - CONTRIBUTORS.txt
21
+
22
+ ### Fixed
23
+ - Tidied up README.md
24
+
25
+ ## [0.3.1]
26
+ ### Fixed
27
+ - Ensure that `Honeykiq::ServerMiddleware#extra_fields` are still included after a job fails
28
+
9
29
  ## [0.3.0]
10
30
  ### Added
11
31
  - `Honeykiq::ServerMiddleware#extra_fields` so you can add custom fields to an event
@@ -17,6 +37,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
17
37
  ### Removed
18
38
  - `Honeykiq.periodic_reporter`. (Use `Honeykiq::PeriodicReporter.new` instead.)
19
39
 
20
- [Unreleased]: https://github.com/carwow/honeykiq/compare/v0.3.0...HEAD
40
+ [Unreleased]: https://github.com/carwow/honeykiq/compare/v1.2.0...HEAD
41
+ [1.2.0]: https://github.com/carwow/honeykiq/compare/v1.1.0...v1.2.0
42
+ [1.1.0]: https://github.com/carwow/honeykiq/compare/v1.0.0...v1.1.0
43
+ [1.0.0]: https://github.com/carwow/honeykiq/compare/v0.3.1...v1.0.0
44
+ [0.3.1]: https://github.com/carwow/honeykiq/compare/v0.3.0...v0.3.1
21
45
  [0.3.0]: https://github.com/carwow/honeykiq/compare/v0.2.0...v0.3.0
22
46
  [0.2.0]: https://github.com/carwow/honeykiq/compare/v0.1.0...v0.2.0
@@ -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
@@ -1,84 +1,94 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- honeykiq (0.3.0)
4
+ honeykiq (1.2.0)
5
5
  sidekiq
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- addressable (2.5.2)
11
- public_suffix (>= 2.0.2, < 4.0)
12
- ast (2.4.0)
13
- carwow_rubocop (2.1.1)
14
- rubocop (~> 0.58)
15
- rubocop-rspec (~> 1.28)
16
- coderay (1.1.2)
17
- connection_pool (2.2.2)
18
- diff-lcs (1.3)
19
- domain_name (0.5.20180417)
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
- http (3.3.0)
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.0)
25
- http_parser.rb (~> 0.6.0)
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.1.1)
29
- http_parser.rb (0.6.0)
30
- jaro_winkler (1.5.1)
31
- libhoney (1.11.0)
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, < 4.0)
34
- method_source (0.9.2)
35
- parallel (1.12.1)
36
- parser (2.5.3.0)
37
- ast (~> 2.4.0)
38
- powerpack (0.1.2)
39
- pry (0.12.2)
40
- coderay (~> 1.1.0)
41
- method_source (~> 0.9.0)
42
- public_suffix (3.0.3)
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 (12.3.2)
48
- redis (4.1.3)
49
- rspec (3.8.0)
50
- rspec-core (~> 3.8.0)
51
- rspec-expectations (~> 3.8.0)
52
- rspec-mocks (~> 3.8.0)
53
- rspec-core (3.8.0)
54
- rspec-support (~> 3.8.0)
55
- rspec-expectations (3.8.2)
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.8.0)
58
- rspec-mocks (3.8.0)
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.8.0)
61
- rspec-support (3.8.0)
62
- rubocop (0.61.1)
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.5, != 2.5.1.1)
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 (~> 1.4.0)
70
- rubocop-rspec (1.30.1)
71
- rubocop (>= 0.60.0)
72
- ruby-progressbar (1.10.0)
73
- sidekiq (6.0.4)
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 (>= 2.0.0)
76
- rack-protection (>= 2.0.0)
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.5)
81
- unicode-display_width (1.4.0)
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.17.2
106
+ 2.1.4
data/README.md CHANGED
@@ -2,11 +2,12 @@
2
2
 
3
3
  Sidekiq → Honeycomb 🐝
4
4
 
5
- Send Sidekiq related events to Honeycomb.
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'
@@ -24,17 +25,31 @@ The library provides two use cases:
24
25
 
25
26
  ### Honeykiq::ServerMiddleware
26
27
 
27
- Add it to Sidekiq server middleware chain and pass a `Libhoney::Client` as
28
- shown below. It will send an event to Honeycomb once a job finishes or fails.
29
- Have a look at [server_middleware.rb] to see what kind of information we send.
28
+ Add Honeykiq to your Sidekiq server middleware chain. It will send an event to
29
+ Honeycomb once a job finishes or fails. Have a look at [server_middleware.rb]
30
+ to see what kind of information it sends.
30
31
 
31
32
  [server_middleware.rb]: https://github.com/carwow/honeykiq/blob/master/lib/honeykiq/server_middleware.rb
32
33
 
33
34
  ```ruby
35
+ # Configure Honeycomb beeline
36
+ Honeycomb.configure do |config|
37
+ config.writekey = ENV.fetch('HONEYCOMB_WRITE_KEY')
38
+ config.dataset = ENV.fetch('HONEYCOMB_DATASET')
39
+ end
40
+
41
+ # Add the middleware to Sidekiq chain
42
+ Sidekiq.configure_server do |config|
43
+ config.server_middleware do |chain|
44
+ chain.add Honeykiq::ServerMiddleware
45
+ end
46
+ end
47
+
48
+ # Or pass the libhoney client to the middleware
34
49
  Sidekiq.configure_server do |config|
35
50
  config.server_middleware do |chain|
36
51
  chain.add Honeykiq::ServerMiddleware,
37
- honey_client: Libhoney::Client.new(
52
+ libhoney: Libhoney::Client.new(
38
53
  writekey: ENV.fetch('HONEYCOMB_WRITE_KEY'),
39
54
  dataset: ENV.fetch('HONEYCOMB_DATASET')
40
55
  )
@@ -42,14 +57,14 @@ Sidekiq.configure_server do |config|
42
57
  end
43
58
  ```
44
59
 
45
- #### Adding extra data to events
46
60
  You can add your own data or functions to the Honeycomb event by subclassing
47
- `Honeykiq::ServerMiddleware` and overriding the the `extra_fields` method with your own
48
- hash. These will be serialized into individual items in the event:
61
+ `Honeykiq::ServerMiddleware`, and overriding the `extra_fields` method with
62
+ your own hash. The contents will be serialized into individual items in the
63
+ event:
49
64
 
50
65
  ```ruby
51
66
  class MyServerMiddleware < Honeykiq::ServerMiddleware
52
- def extra_fields
67
+ def extra_fields(job) # Sidekiq::Job instance
53
68
  {
54
69
  my_data: 'evaluated and added to the event after the job has finished/errored',
55
70
  my_function: -> { Time.now }
@@ -59,63 +74,64 @@ end
59
74
 
60
75
  Sidekiq.configure_server do |config|
61
76
  config.server_middleware do |chain|
62
- chain.add MyServerMiddleware, honey_client: ...
63
- ...
77
+ chain.add MyServerMiddleware
78
+ end
79
+ end
64
80
  ```
65
81
 
66
- **Note on long running jobs:** If you have long running jobs an event is only
67
- sent to Honeycomb when it finishes so it may appear as no jobs are running.
68
- Also if the process gets a SIGKILL then no event is sent about that job and the
69
- job may keep retrying and not appear in Honeycomb. The `PeriodicReporter`
70
- should help with this but we are thinking of a nicer approach.
82
+ **Note:** If you have long running jobs, an event is only sent to Honeycomb
83
+ when the job finishes. Therefore, it may appear as though no jobs are currently
84
+ running. Additionally, if the process receives a `SIGKILL` then no event is
85
+ sent about that job, and the job may keep retrying without appearing in
86
+ Honeycomb. The `PeriodicReporter` provides visibility for these cases.
71
87
 
72
88
  ### Honeykiq::PeriodicReporter
73
89
 
74
- The periodic reporter should be scheduled to report every few seconds depending
75
- on your use case (e.g. 30 seconds). Every time the `#report` method is called
76
- it will send a total of `1 + P + Q` events to Honeycomb where P and Q are the
90
+ The periodic reporter should be scheduled to report every few seconds,
91
+ depending on your use case. Every time the `#report` method is called it will
92
+ send a total of `1 + P + Q` events to Honeycomb where `P` and `Q` are the
77
93
  number of processes and queues respectively.
78
94
 
79
- It sends three types of events: instance, process, and queue. Have a look at
80
- [periodic_reporter.rb] to see what kind of information we send for each type.
95
+ It sends three types of events: `instance`, `process`, and `queue`. Have a look
96
+ at [periodic_reporter.rb] to see what kind of information we send for each
97
+ type.
81
98
 
82
99
  [periodic_reporter.rb]: https://github.com/carwow/honeykiq/blob/master/lib/honeykiq/periodic_reporter.rb
83
100
 
84
- A simple setup using [clockwork] would look like this:
85
-
86
- [clockwork]: https://github.com/Rykian/clockwork
101
+ A setup using [clockwork] to report every 30 seconds would look like this:
87
102
 
88
103
  ```ruby
104
+ require 'honeycomb-beeline'
89
105
  require 'clockwork'
90
- require 'libhoney'
91
106
  require 'honeykiq'
92
107
 
93
- module Clockwork
94
- every(30, 'Honeykiq', thread: true) { SidekiqHealth.report }
108
+ Honeycomb.configure do |config|
109
+ config.writekey = ENV.fetch('HONEYCOMB_WRITE_KEY')
110
+ config.dataset = ENV.fetch('HONEYCOMB_DATASET')
95
111
  end
96
112
 
97
- module SidekiqHealth
98
- def self.report
99
- reporter.report
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
- )
113
+ module Clockwork
114
+ every(30, 'Honeykiq::PeriodicReporter') do
115
+ Honeykiq::PeriodicReporter.new.report
111
116
  end
112
117
  end
113
118
  ```
114
119
 
120
+ [clockwork]: https://github.com/Rykian/clockwork
121
+
115
122
  ## Contributing
116
123
 
117
- Bug reports and pull requests are welcome on GitHub at https://github.com/carwow/honeykiq.
124
+ [Pull requests] are very welcome!
125
+
126
+ Please report bugs in a [new issue].
127
+
128
+ Everyone is expected to follow the [code of conduct].
129
+
130
+ [Pull requests]: https://github.com/carwow/honeykiq/pulls
131
+ [new issue]: https://github.com/carwow/honeykiq/issues/new
132
+ [code of conduct]: https://github.com/carwow/honeykiq/tree/master/CODE_OF_CONDUCT.md
118
133
 
119
134
  ## License
120
135
 
121
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
136
+ The gem is available as open source under the terms of the
137
+ [MIT License](https://opensource.org/licenses/MIT).
@@ -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 'libhoney'
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'
@@ -2,8 +2,8 @@ require 'sidekiq/api'
2
2
 
3
3
  module Honeykiq
4
4
  class PeriodicReporter
5
- def initialize(honey_client:)
6
- @honey_client = honey_client
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 :honey_client
17
+ attr_reader :libhoney
18
18
 
19
19
  def send_instance_event(&extra)
20
- honey_client.event.add(
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
- honey_client.event.add(
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
- honey_client.event.add(
71
+ libhoney.event.add(
72
72
  type: :queue,
73
73
  'queue.name': queue.name,
74
74
  'queue.latency_sec': queue.latency.to_f,
@@ -2,39 +2,59 @@ require 'sidekiq/api'
2
2
 
3
3
  module Honeykiq
4
4
  class ServerMiddleware
5
- def initialize(options = {})
6
- @honey_client = options.fetch(:honey_client)
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
- event = @honey_client.event
11
- run_with_hooks(event, msg, queue_name) { yield }
12
- event.add_field(:'job.status', 'finished')
13
- rescue StandardError => error
14
- event&.add_field(:'job.status', 'failed')
15
- event&.add(error_info(error))
16
- raise
17
- ensure
18
- event&.send
10
+ job = Sidekiq::Job.new(msg, queue_name)
11
+ queue = Sidekiq::Queue.new(queue_name)
12
+
13
+ start_span(name: job.display_class) do |event|
14
+ call_with_event(event, job, queue) { yield }
15
+ end
19
16
  end
20
17
 
21
- def extra_fields
18
+ def extra_fields(_job = nil)
22
19
  {}
23
20
  end
24
21
 
25
22
  private
26
23
 
27
- def run_with_hooks(event, msg, queue_name)
28
- event.add(default_fields(msg, queue_name))
29
- duration_ms(event) { yield }
30
- event.add(extra_fields)
24
+ attr_reader :libhoney
25
+
26
+ def libhoney?
27
+ !!libhoney
31
28
  end
32
29
 
33
- def default_fields(msg, queue_name)
30
+ def start_span(name:)
31
+ if libhoney?
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
40
+ end
41
+
42
+ def call_with_event(event, job, queue)
43
+ event.add(default_fields(job, queue))
44
+ yield
45
+ event.add_field(:'job.status', 'finished')
46
+ rescue StandardError => error
47
+ on_error(event, error)
48
+ raise
49
+ ensure
50
+ event.add(call_extra_fields(job))
51
+ end
52
+
53
+ def default_fields(job, queue)
34
54
  {
35
55
  type: :job,
36
- **job_fields(Sidekiq::Job.new(msg, queue_name)),
37
- **queue_fields(Sidekiq::Queue.new(queue_name)),
56
+ **job_fields(job),
57
+ **queue_fields(queue),
38
58
  'meta.thread_id': Thread.current.object_id
39
59
  }
40
60
  end
@@ -58,15 +78,40 @@ module Honeykiq
58
78
  end
59
79
 
60
80
  def duration_ms(event)
61
- start_time = Time.now
81
+ start_time = now
62
82
  yield
63
83
  ensure
64
- duration = Time.now - start_time
84
+ duration = now - start_time
65
85
  event.add_field(:duration_ms, duration * 1000)
66
86
  end
67
87
 
68
- def error_info(error)
69
- { 'error.class': error.class.name, 'error.message': error.message }
88
+ def on_error(event, error)
89
+ return unless event
90
+
91
+ event.add_field(:'job.status', 'failed')
92
+ return unless libhoney?
93
+
94
+ event.add(
95
+ 'error.class': error.class.name,
96
+ 'error.message': error.message
97
+ )
98
+ end
99
+
100
+ def call_extra_fields(job)
101
+ case method(:extra_fields).arity
102
+ when 0 then extra_fields
103
+ else extra_fields(job)
104
+ end
105
+ 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
70
115
  end
71
116
  end
72
117
  end
@@ -1,3 +1,3 @@
1
1
  module Honeykiq
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
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: 0.3.0
4
+ version: 1.2.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-01-08 00:00:00.000000000 Z
11
+ date: 2020-07-29 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: libhoney
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
@@ -135,7 +136,7 @@ licenses:
135
136
  - MIT
136
137
  metadata:
137
138
  allowed_push_host: https://rubygems.org
138
- post_install_message:
139
+ post_install_message:
139
140
  rdoc_options: []
140
141
  require_paths:
141
142
  - lib
@@ -150,9 +151,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
151
  - !ruby/object:Gem::Version
151
152
  version: '0'
152
153
  requirements: []
153
- rubyforge_project:
154
- rubygems_version: 2.6.14.1
155
- signing_key:
154
+ rubygems_version: 3.1.2
155
+ signing_key:
156
156
  specification_version: 4
157
157
  summary: "Sidekiq → Honeycomb \U0001F41D"
158
158
  test_files: []