hutch 1.0.0 → 1.1.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
2
  SHA256:
3
- metadata.gz: 626b85f02b69ee2113376ff382173fd124cdcae1bdc404f0681874e76a80310e
4
- data.tar.gz: 3d1d6a2cd275b1c2d72d4842841ad90f70145cabe6800ff3860b206aebf0308e
3
+ metadata.gz: 74721c392b797963bf268ff65d638b888e11d43307446ed63bd3de14e36aa97e
4
+ data.tar.gz: 1ddb6053bd164c0332650169415ae9a20daa9724039be7765cc90aade1e0f304
5
5
  SHA512:
6
- metadata.gz: c1b0c80bf6362b0cfbc6f54b3257c74549c6d927fbae3bcaecb50aeb4ed0f28e01466a6a3013ce9175f55eb481b2e9378f89954edcc1453753da00b76873c766
7
- data.tar.gz: 4c346421c5c1fa49440866b56486cc75d68c3eed8c3014ae2f51e2643f40a59b084634248b52d32965b65f692d1560250a8f5add30c4b75b2f541c895574aa26
6
+ metadata.gz: e690481212eeca9499f491b34c39e9f8e4f883f617063a5123bf1471e87b7f7251c52e0c92b103fe73dfa8db1859ad5feca76b6f0694ff68554191e66621f209
7
+ data.tar.gz: 043c203877a230f2d50c023a005ce84c7a7fc764c2b6ce3d452ab8aa143fa4175e4ba4bd54a4e2e611839360b2ec292d28c03ec338c92bbaa3b84e34b8a644f0
data/.travis.yml CHANGED
@@ -11,14 +11,13 @@ before_script:
11
11
  - "./bin/ci/before_build.sh"
12
12
  matrix:
13
13
  include:
14
+ - rvm: "3.0.0"
14
15
  - rvm: "2.7.1"
15
16
  - rvm: "2.6.6"
16
17
  - rvm: "2.5.8"
17
- - rvm: "2.4.10"
18
- - rvm: "2.3.8"
19
- - rvm: "jruby-9.2.9.0"
18
+ - rvm: "jruby-9.2.19.0"
19
+ name: "Latest JRuby"
20
20
  - rvm: "ruby-head"
21
21
  allow_failures:
22
- rvm:
23
- - "jruby-9.2.9.0"
24
- - ruby-head
22
+ - name: "Latest JRuby"
23
+ - rvm: ruby-head
data/CHANGELOG.md CHANGED
@@ -1,6 +1,27 @@
1
- ## 1.0.1 (in development)
1
+ ## 1.1.0 (July 26th, 2021)
2
+
3
+ ### Bugsnag Error Handler
4
+
5
+ Contributed by @ivanhuang1.
6
+
7
+ GitHub issue: [#362](https://github.com/ruby-amqp/hutch/pull/362)
8
+
9
+ ### Updated Sentry Error Handler
10
+
11
+ Contributed by Karol @Azdaroth Galanciak.
12
+
13
+ GitHub issue: [#363](https://github.com/ruby-amqp/hutch/pull/363)
14
+
15
+
16
+ ### Type Casting for Values Set Using Hutch::Config.set
17
+
18
+ Values set with `Hutch::Config.set` now have expected setting type casting
19
+ applied to them.
20
+
21
+ Contributed by Karol @Azdaroth Galanciak.
22
+
23
+ GitHub issue: [#358](https://github.com/ruby-amqp/hutch/pull/358)
2
24
 
3
- No changes yet.
4
25
 
5
26
  ## 1.0.0 (April 8th, 2020)
6
27
 
@@ -59,8 +80,8 @@ contains potentially breaking changes.
59
80
 
60
81
  #### Enhancements
61
82
 
62
- * Exchange type is now configurable via the `` config setting. Supported exchanges must be
63
- compatible with topic exchanges (e.g. wrap it). Default value is `"topic"`.
83
+ * Exchange type is now configurable via the `mq_exchange_type` config setting. Supported exchanges must be
84
+ compatible with topic exchanges (e.g. wrap it). Default value is `topic`.
64
85
 
65
86
  This feature is limited to topic and delayed message exchange plugins and is mostly
66
87
  useful for forward compatibility.
data/Gemfile CHANGED
@@ -20,11 +20,14 @@ group :development, :test do
20
20
  gem "simplecov", "~> 0.12"
21
21
 
22
22
  gem "sentry-raven"
23
+ gem "sentry-ruby"
23
24
  gem "honeybadger"
24
25
  gem "coveralls", "~> 0.8.15", require: false
25
26
  gem "newrelic_rpm"
27
+ gem "ddtrace"
26
28
  gem "airbrake", "~> 10.0"
27
29
  gem "rollbar"
30
+ gem "bugsnag"
28
31
  end
29
32
 
30
33
  group :development, :darwin do
data/README.md CHANGED
@@ -39,7 +39,7 @@ gem install hutch
39
39
 
40
40
  ## Requirements
41
41
 
42
- - Hutch requires Ruby 2.3+ or JRuby 9K.
42
+ - Hutch requires Ruby 2.4+ or JRuby 9K.
43
43
  - Hutch requires RabbitMQ 3.3 or later.
44
44
 
45
45
  ## Overview
@@ -59,8 +59,8 @@ Hutch uses [Bunny](http://rubybunny.info) or [March Hare](http://rubymarchhare.i
59
59
  ### Project Maturity
60
60
 
61
61
  Hutch is a mature project that was originally extracted from production systems
62
- at [GoCardless](https://gocardless.com) in 2013 and is now maintained by a large
63
- group of contributors.
62
+ at [GoCardless](https://gocardless.com) in 2013 and is now maintained by its contributors
63
+ and users.
64
64
 
65
65
  ## Consumers
66
66
 
@@ -188,6 +188,12 @@ This will enable NewRelic custom instrumentation:
188
188
  Hutch::Config.set(:tracer, Hutch::Tracers::NewRelic)
189
189
  ```
190
190
 
191
+ And this will enable Datadog custom instrumentation:
192
+
193
+ ```ruby
194
+ Hutch::Config.set(:tracer, Hutch::Tracers::Datadog)
195
+ ```
196
+
191
197
  Batteries included!
192
198
 
193
199
  ## Running Hutch
@@ -246,7 +252,7 @@ and the consumers are not loaded in development environment you will need to
246
252
  trigger the autoloading in an initializer with
247
253
 
248
254
  ```ruby
249
- ::Zeitwerk::Loader.eager_load_all
255
+ ::Zeitwerk::Loader.eager_load_all
250
256
  ```
251
257
 
252
258
  or with something more specific like
@@ -259,13 +265,37 @@ Dir.glob(File.join('app/consumers', '*_consumer.rb')).each do |consumer|
259
265
  end
260
266
  ```
261
267
 
268
+ ### Consumer Groups
269
+
270
+ It is possible to load only a subset of consumers. This is done by defining a consumer
271
+ group under the `consumer_groups` configuration key:
272
+
273
+ ``` yaml
274
+ consumer_groups:
275
+ payments:
276
+ - DepositConsumer
277
+ - CashoutConsumer
278
+ notification:
279
+ - EmailNotificationConsumer
280
+ ```
281
+
282
+ To only load a group of consumers, use the `--only-group` option:
283
+
284
+ ``` shell
285
+ hutch --only-group=payments --config=/path/to/hutch.yaml
286
+ ```
287
+
288
+ ### Loading Consumers Manually (One-by-One)
289
+
262
290
  To require files that define consumers manually, simply pass each file as an
263
291
  option to `--require`. Hutch will automatically detect whether you've provided
264
292
  a Rails app or a standard file, and take the appropriate behaviour:
265
293
 
266
294
  ```bash
267
- $ hutch --require path/to/rails-app # loads a rails app
268
- $ hutch --require path/to/file.rb # loads a ruby file
295
+ # loads a rails app
296
+ hutch --require path/to/rails-app
297
+ # loads a ruby file
298
+ hutch --require path/to/file.rb
269
299
  ```
270
300
 
271
301
  ### Stopping Hutch
@@ -384,6 +414,7 @@ Known configuration parameters are:
384
414
  * `automatically_recover`: Bunny's enable/disable network recovery (default: `true`)
385
415
  * `network_recovery_interval`: Bunny's reconnect interval (default: `1`)
386
416
  * `tracer`: tracer to use to track message processing
417
+ * `namespace`: A namespace string to help group your queues (default: `nil`)
387
418
 
388
419
  ### Environment variables
389
420
 
@@ -442,6 +473,13 @@ Generate with
442
473
  <td><tt>HUTCH_MQ_EXCHANGE</tt></td>
443
474
  <td><p>RabbitMQ Exchange to use for publishing</p></td>
444
475
  </tr>
476
+ <tr>
477
+ <td><tt>mq_exchange_type</tt></td>
478
+ <td>topic</td>
479
+ <td>String</td>
480
+ <td><tt>HUTCH_MQ_EXCHANGE_TYPE</tt></td>
481
+ <td><p>RabbitMQ Exchange type to use for publishing</p></td>
482
+ </tr>
445
483
  <tr>
446
484
  <td><tt>mq_vhost</tt></td>
447
485
  <td>/</td>
@@ -624,5 +662,19 @@ Generate with
624
662
  <td><tt>HUTCH_CONSUMER_TAG_PREFIX</tt></td>
625
663
  <td><p>Prefix displayed on the consumers tags.</p></td>
626
664
  </tr>
665
+ <tr>
666
+ <td><tt>namespace</tt></td>
667
+ <td>nil</td>
668
+ <td>String</td>
669
+ <td><tt>HUTCH_NAMESPACE</tt></td>
670
+ <td><p>A namespace to help group your queues</p></td>
671
+ </tr>
672
+ <tr>
673
+ <td><tt>group</tt></td>
674
+ <td>''</td>
675
+ <td>String</td>
676
+ <td><tt>HUTCH_GROUP</tt></td>
677
+ <td></td>
678
+ </tr>
627
679
  </tbody>
628
680
  </table>
@@ -1,17 +1,46 @@
1
1
  #!/bin/sh
2
2
 
3
- sudo apt-get install -y wget
4
- wget -O - "https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc" | sudo apt-key add -
3
+ sudo apt-get install curl gnupg debian-keyring debian-archive-keyring apt-transport-https -y
5
4
 
6
- sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list <<EOF
7
- deb https://dl.bintray.com/rabbitmq-erlang/debian bionic erlang
8
- deb https://dl.bintray.com/rabbitmq/debian bionic main
5
+ ## Team RabbitMQ's main signing key
6
+ sudo apt-key adv --keyserver "hkps://keys.openpgp.org" --recv-keys "0x0A9AF2115F4687BD29803A206B73A36E6026DFCA"
7
+ ## Launchpad PPA that provides modern Erlang releases
8
+ sudo apt-key adv --keyserver "keyserver.ubuntu.com" --recv-keys "F77F1EDA57EBB1CC"
9
+ ## PackageCloud RabbitMQ repository
10
+ sudo apt-key adv --keyserver "keyserver.ubuntu.com" --recv-keys "F6609E60DC62814E"
11
+
12
+ ## Add apt repositories maintained by Team RabbitMQ
13
+ sudo tee /etc/apt/sources.list.d/rabbitmq.list <<EOF
14
+ ## Provides modern Erlang/OTP releases
15
+ ##
16
+ ## "bionic" as distribution name should work for any reasonably recent Ubuntu or Debian release.
17
+ ## See the release to distribution mapping table in RabbitMQ doc guides to learn more.
18
+ deb http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu bionic main
19
+ deb-src http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu bionic main
20
+
21
+ ## Provides RabbitMQ
22
+ ##
23
+ ## "bionic" as distribution name should work for any reasonably recent Ubuntu or Debian release.
24
+ ## See the release to distribution mapping table in RabbitMQ doc guides to learn more.
25
+ deb https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ bionic main
26
+ deb-src https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ bionic main
9
27
  EOF
10
28
 
29
+ ## Update package indices
11
30
  sudo apt-get update -y
12
- sudo apt-get upgrade -y
13
- sudo apt-get install -y rabbitmq-server
31
+
32
+ ## Install Erlang packages
33
+ sudo apt-get install -y erlang-base \
34
+ erlang-asn1 erlang-crypto erlang-eldap erlang-ftp erlang-inets \
35
+ erlang-mnesia erlang-os-mon erlang-parsetools erlang-public-key \
36
+ erlang-runtime-tools erlang-snmp erlang-ssl \
37
+ erlang-syntax-tools erlang-tftp erlang-tools erlang-xmerl
38
+
39
+ ## Install rabbitmq-server and its dependencies
40
+ sudo apt-get install rabbitmq-server -y --fix-missing
14
41
 
15
42
  sudo service rabbitmq-server start
16
43
 
44
+ sudo rabbitmqctl await_startup --timeout 120
45
+
17
46
  until sudo lsof -i:5672; do echo "Waiting for RabbitMQ to start..."; sleep 1; done
data/hutch.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.add_runtime_dependency 'march_hare', '>= 3.0.0'
7
7
  else
8
8
  gem.platform = Gem::Platform::RUBY
9
- gem.add_runtime_dependency 'bunny', '>= 2.15', '< 2.16'
9
+ gem.add_runtime_dependency 'bunny', '>= 2.16', '< 3.0'
10
10
  end
11
11
  gem.add_runtime_dependency 'carrot-top', '~> 0.0.7'
12
12
  gem.add_runtime_dependency 'multi_json', '~> 1.14'
data/lib/hutch/cli.rb CHANGED
@@ -40,6 +40,9 @@ module Hutch
40
40
  # handlers are set up. Due to this, we never got any Sentry notifications
41
41
  # when an error occurred in any of the consumers.
42
42
  if defined?(Raven)
43
+ Hutch::Config[:error_handlers] << Hutch::ErrorHandlers::SentryRaven.new
44
+ end
45
+ if defined?(Sentry)
43
46
  Hutch::Config[:error_handlers] << Hutch::ErrorHandlers::Sentry.new
44
47
  end
45
48
 
data/lib/hutch/config.rb CHANGED
@@ -145,6 +145,9 @@ module Hutch
145
145
  # Prefix displayed on the consumers tags.
146
146
  string_setting :consumer_tag_prefix, 'hutch'
147
147
 
148
+ # A namespace to help group your queues
149
+ string_setting :namespace, nil
150
+
148
151
  string_setting :group, ''
149
152
 
150
153
  # Set of all setting keys
@@ -193,14 +196,7 @@ module Hutch
193
196
  env_keys_configured.each_with_object({}) {|attr, result|
194
197
  value = ENV[key_for(attr)]
195
198
 
196
- case
197
- when is_bool(attr) || value == 'false'
198
- result[attr] = to_bool(value)
199
- when is_num(attr)
200
- result[attr] = value.to_i
201
- else
202
- result[attr] = value
203
- end
199
+ result[attr] = type_cast(attr, value)
204
200
  }
205
201
  end
206
202
 
@@ -235,7 +231,7 @@ module Hutch
235
231
 
236
232
  def self.set(attr, value)
237
233
  check_attr(attr.to_sym)
238
- user_config[attr.to_sym] = value
234
+ user_config[attr.to_sym] = type_cast(attr, value)
239
235
  end
240
236
 
241
237
  class << self
@@ -272,6 +268,18 @@ module Hutch
272
268
  end
273
269
  end
274
270
 
271
+ def self.type_cast(attr, value)
272
+ case
273
+ when is_bool(attr) || value == 'false'
274
+ to_bool(value)
275
+ when is_num(attr)
276
+ value.to_i
277
+ else
278
+ value
279
+ end
280
+ end
281
+ private_class_method :type_cast
282
+
275
283
  def self.define_methods
276
284
  @config.keys.each do |key|
277
285
  define_singleton_method(key) do
@@ -2,8 +2,10 @@ module Hutch
2
2
  module ErrorHandlers
3
3
  autoload :Logger, 'hutch/error_handlers/logger'
4
4
  autoload :Sentry, 'hutch/error_handlers/sentry'
5
+ autoload :SentryRaven, 'hutch/error_handlers/sentry_raven'
5
6
  autoload :Honeybadger, 'hutch/error_handlers/honeybadger'
6
7
  autoload :Airbrake, 'hutch/error_handlers/airbrake'
7
8
  autoload :Rollbar, 'hutch/error_handlers/rollbar'
9
+ autoload :Bugsnag, 'hutch/error_handlers/bugsnag'
8
10
  end
9
11
  end
@@ -0,0 +1,30 @@
1
+ require "hutch/logging"
2
+ require "bugsnag"
3
+ require "hutch/error_handlers/base"
4
+
5
+ module Hutch
6
+ module ErrorHandlers
7
+ class Bugsnag < Base
8
+ def handle(properties, payload, consumer, ex)
9
+ message_id = properties.message_id
10
+ prefix = "message(#{message_id || "-"}):"
11
+ logger.error "#{prefix} Logging event to Bugsnag"
12
+ logger.error "#{prefix} #{ex.class} - #{ex.message}"
13
+
14
+ ::Bugsnag.notify(ex) do |report|
15
+ report.add_tab(:hutch, {
16
+ payload: payload,
17
+ consumer: consumer
18
+ })
19
+ end
20
+ end
21
+
22
+ def handle_setup_exception(ex)
23
+ logger.error "Logging setup exception to Bugsnag"
24
+ logger.error "#{ex.class} - #{ex.message}"
25
+
26
+ ::Bugsnag.notify(ex)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,31 +1,26 @@
1
1
  require 'hutch/logging'
2
- require 'raven'
2
+ require 'sentry-ruby'
3
3
  require 'hutch/error_handlers/base'
4
4
 
5
5
  module Hutch
6
6
  module ErrorHandlers
7
7
  class Sentry < Base
8
-
9
- def initialize
10
- unless Raven.respond_to?(:capture_exception)
11
- raise "The Hutch Sentry error handler requires Raven >= 0.4.0"
12
- end
13
- end
14
-
15
8
  def handle(properties, payload, consumer, ex)
16
9
  message_id = properties.message_id
17
10
  prefix = "message(#{message_id || '-'}):"
18
11
  logger.error "#{prefix} Logging event to Sentry"
19
12
  logger.error "#{prefix} #{ex.class} - #{ex.message}"
20
- Raven.capture_exception(ex, extra: { payload: payload })
13
+ ::Sentry.configure_scope do |scope|
14
+ scope.set_context("payload", payload)
15
+ end
16
+ ::Sentry.capture_exception(ex)
21
17
  end
22
18
 
23
19
  def handle_setup_exception(ex)
24
20
  logger.error "Logging setup exception to Sentry"
25
21
  logger.error "#{ex.class} - #{ex.message}"
26
- Raven.capture_exception(ex)
22
+ ::Sentry.capture_exception(ex)
27
23
  end
28
-
29
24
  end
30
25
  end
31
26
  end
@@ -0,0 +1,31 @@
1
+ require 'hutch/logging'
2
+ require 'raven'
3
+ require 'hutch/error_handlers/base'
4
+
5
+ module Hutch
6
+ module ErrorHandlers
7
+ class SentryRaven < Base
8
+
9
+ def initialize
10
+ unless Raven.respond_to?(:capture_exception)
11
+ raise "The Hutch Sentry error handler requires Raven >= 0.4.0"
12
+ end
13
+ end
14
+
15
+ def handle(properties, payload, consumer, ex)
16
+ message_id = properties.message_id
17
+ prefix = "message(#{message_id || '-'}):"
18
+ logger.error "#{prefix} Logging event to Sentry"
19
+ logger.error "#{prefix} #{ex.class} - #{ex.message}"
20
+ Raven.capture_exception(ex, extra: { payload: payload })
21
+ end
22
+
23
+ def handle_setup_exception(ex)
24
+ logger.error "Logging setup exception to Sentry"
25
+ logger.error "#{ex.class} - #{ex.message}"
26
+ Raven.capture_exception(ex)
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -6,7 +6,7 @@ module Hutch
6
6
  class JSON
7
7
 
8
8
  def self.encode(payload)
9
- ::JSON.dump(payload)
9
+ ::MultiJson.dump(payload)
10
10
  end
11
11
 
12
12
  def self.decode(payload)
data/lib/hutch/tracers.rb CHANGED
@@ -2,5 +2,6 @@ module Hutch
2
2
  module Tracers
3
3
  autoload :NullTracer, 'hutch/tracers/null_tracer'
4
4
  autoload :NewRelic, 'hutch/tracers/newrelic'
5
+ autoload :Datadog, 'hutch/tracers/datadog'
5
6
  end
6
7
  end
@@ -0,0 +1,17 @@
1
+ require 'ddtrace'
2
+
3
+ module Hutch
4
+ module Tracers
5
+ class Datadog
6
+ def initialize(klass)
7
+ @klass = klass
8
+ end
9
+
10
+ def handle(message)
11
+ ::Datadog.tracer.trace(@klass.class.name, service: 'hutch', span_type: 'rabbitmq') do
12
+ @klass.process(message)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
data/lib/hutch/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hutch
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
@@ -49,6 +49,44 @@ describe Hutch::Config do
49
49
  context 'sets value in user config hash' do
50
50
  it { is_expected.to eq(new_value) }
51
51
  end
52
+
53
+ context 'type casting' do
54
+ context 'number attributes' do
55
+ before { Hutch::Config.set(:heartbeat, new_value) }
56
+ subject(:value) { Hutch::Config.user_config[:heartbeat] }
57
+
58
+ let(:new_value) { "0" }
59
+
60
+
61
+ specify 'casts values to integers' do
62
+ expect(value).to eq 0
63
+ end
64
+ end
65
+ end
66
+
67
+ context 'boolean attributes' do
68
+ before { Hutch::Config.set(:autoload_rails, new_value) }
69
+ subject(:value) { Hutch::Config.user_config[:autoload_rails] }
70
+
71
+ let(:new_value) { "t" }
72
+
73
+
74
+ specify 'casts values to booleans' do
75
+ expect(value).to eq true
76
+ end
77
+ end
78
+
79
+ context 'string attributes' do
80
+ before { Hutch::Config.set(:mq_exchange_type, new_value) }
81
+ subject(:value) { Hutch::Config.user_config[:mq_exchange_type] }
82
+
83
+ let(:new_value) { 1 }
84
+
85
+
86
+ specify 'does not perform any typecasting' do
87
+ expect(value).to eq new_value
88
+ end
89
+ end
52
90
  end
53
91
 
54
92
  context 'for invalid attributes' do
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ describe Hutch::ErrorHandlers::Bugsnag do
6
+ let(:error_handler) { described_class.new }
7
+
8
+ before do
9
+ Bugsnag.configure do |bugsnag|
10
+ bugsnag.api_key = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
11
+ end
12
+ end
13
+
14
+ describe "#handle" do
15
+ let(:error) do
16
+ begin
17
+ raise "Stuff went wrong"
18
+ rescue RuntimeError => err
19
+ err
20
+ end
21
+ end
22
+
23
+ it "logs the error to Bugsnag" do
24
+ message_id = "1"
25
+ properties = OpenStruct.new(message_id: message_id)
26
+ payload = "{}"
27
+ consumer = double
28
+ ex = error
29
+ message = {
30
+ payload: payload,
31
+ consumer: consumer
32
+ }
33
+
34
+ expect(::Bugsnag).to receive(:notify).with(ex).and_call_original
35
+ expect_any_instance_of(::Bugsnag::Report).to receive(:add_tab).with(:hutch, message)
36
+ error_handler.handle(properties, payload, consumer, ex)
37
+ end
38
+ end
39
+
40
+ describe "#handle_setup_exception" do
41
+ let(:error) do
42
+ begin
43
+ raise "Stuff went wrong"
44
+ rescue RuntimeError => err
45
+ err
46
+ end
47
+ end
48
+
49
+ it "logs the error to Bugsnag" do
50
+ ex = error
51
+ expect(::Bugsnag).to receive(:notify).with(ex)
52
+ error_handler.handle_setup_exception(ex)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hutch::ErrorHandlers::SentryRaven do
4
+ let(:error_handler) { Hutch::ErrorHandlers::SentryRaven.new }
5
+
6
+ describe '#handle' do
7
+ let(:properties) { OpenStruct.new(message_id: "1") }
8
+ let(:payload) { "{}" }
9
+ let(:error) do
10
+ begin
11
+ raise "Stuff went wrong"
12
+ rescue RuntimeError => err
13
+ err
14
+ end
15
+ end
16
+
17
+ it "logs the error to Sentry" do
18
+ expect(Raven).to receive(:capture_exception).with(error, extra: { payload: payload })
19
+ error_handler.handle(properties, payload, double, error)
20
+ end
21
+ end
22
+
23
+ describe '#handle_setup_exception' do
24
+ let(:error) do
25
+ begin
26
+ raise "Stuff went wrong during setup"
27
+ rescue RuntimeError => err
28
+ err
29
+ end
30
+ end
31
+
32
+ it "logs the error to Sentry" do
33
+ expect(Raven).to receive(:capture_exception).with(error)
34
+ error_handler.handle_setup_exception(error)
35
+ end
36
+ end
37
+ end
@@ -15,7 +15,8 @@ describe Hutch::ErrorHandlers::Sentry do
15
15
  end
16
16
 
17
17
  it "logs the error to Sentry" do
18
- expect(Raven).to receive(:capture_exception).with(error, extra: { payload: payload })
18
+ expect(::Sentry).to receive(:capture_exception).with(error).and_call_original
19
+
19
20
  error_handler.handle(properties, payload, double, error)
20
21
  end
21
22
  end
@@ -30,7 +31,8 @@ describe Hutch::ErrorHandlers::Sentry do
30
31
  end
31
32
 
32
33
  it "logs the error to Sentry" do
33
- expect(Raven).to receive(:capture_exception).with(error)
34
+ expect(::Sentry).to receive(:capture_exception).with(error).and_call_original
35
+
34
36
  error_handler.handle_setup_exception(error)
35
37
  end
36
38
  end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Hutch::Tracers::Datadog do
4
+ describe "#handle" do
5
+ subject(:handle) { tracer.handle(message) }
6
+
7
+ let(:tracer) { described_class.new(klass) }
8
+ let(:klass) do
9
+ Class.new do
10
+ attr_reader :message
11
+
12
+ def initialize
13
+ @message = nil
14
+ end
15
+
16
+ def class
17
+ OpenStruct.new(name: 'ClassName')
18
+ end
19
+
20
+ def process(message)
21
+ @message = message
22
+ end
23
+ end.new
24
+ end
25
+ let(:message) { double(:message) }
26
+
27
+ before do
28
+ allow(Datadog.tracer).to receive(:trace).and_call_original
29
+ end
30
+
31
+ it 'uses Datadog tracer' do
32
+ handle
33
+
34
+ expect(Datadog.tracer).to have_received(:trace).with('ClassName',
35
+ hash_including(service: 'hutch', span_type: 'rabbitmq'))
36
+ end
37
+
38
+ it 'processes the message' do
39
+ expect {
40
+ handle
41
+ }.to change { klass.message }.from(nil).to(message)
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hutch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harry Marr
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-08 00:00:00.000000000 Z
11
+ date: 2021-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.15'
19
+ version: '2.16'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '2.16'
22
+ version: '3.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '2.15'
29
+ version: '2.16'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '2.16'
32
+ version: '3.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: carrot-top
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -116,10 +116,12 @@ files:
116
116
  - lib/hutch/error_handlers.rb
117
117
  - lib/hutch/error_handlers/airbrake.rb
118
118
  - lib/hutch/error_handlers/base.rb
119
+ - lib/hutch/error_handlers/bugsnag.rb
119
120
  - lib/hutch/error_handlers/honeybadger.rb
120
121
  - lib/hutch/error_handlers/logger.rb
121
122
  - lib/hutch/error_handlers/rollbar.rb
122
123
  - lib/hutch/error_handlers/sentry.rb
124
+ - lib/hutch/error_handlers/sentry_raven.rb
123
125
  - lib/hutch/exceptions.rb
124
126
  - lib/hutch/logging.rb
125
127
  - lib/hutch/message.rb
@@ -127,6 +129,7 @@ files:
127
129
  - lib/hutch/serializers/identity.rb
128
130
  - lib/hutch/serializers/json.rb
129
131
  - lib/hutch/tracers.rb
132
+ - lib/hutch/tracers/datadog.rb
130
133
  - lib/hutch/tracers/newrelic.rb
131
134
  - lib/hutch/tracers/null_tracer.rb
132
135
  - lib/hutch/version.rb
@@ -139,13 +142,16 @@ files:
139
142
  - spec/hutch/config_spec.rb
140
143
  - spec/hutch/consumer_spec.rb
141
144
  - spec/hutch/error_handlers/airbrake_spec.rb
145
+ - spec/hutch/error_handlers/bugsnag_spec.rb
142
146
  - spec/hutch/error_handlers/honeybadger_spec.rb
143
147
  - spec/hutch/error_handlers/logger_spec.rb
144
148
  - spec/hutch/error_handlers/rollbar_spec.rb
149
+ - spec/hutch/error_handlers/sentry_raven_spec.rb
145
150
  - spec/hutch/error_handlers/sentry_spec.rb
146
151
  - spec/hutch/logger_spec.rb
147
152
  - spec/hutch/message_spec.rb
148
153
  - spec/hutch/serializers/json_spec.rb
154
+ - spec/hutch/tracers/datadog_spec.rb
149
155
  - spec/hutch/waiter_spec.rb
150
156
  - spec/hutch/worker_spec.rb
151
157
  - spec/hutch_spec.rb
@@ -163,7 +169,7 @@ homepage: https://github.com/gocardless/hutch
163
169
  licenses:
164
170
  - MIT
165
171
  metadata: {}
166
- post_install_message:
172
+ post_install_message:
167
173
  rdoc_options: []
168
174
  require_paths:
169
175
  - lib
@@ -178,8 +184,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
184
  - !ruby/object:Gem::Version
179
185
  version: '0'
180
186
  requirements: []
181
- rubygems_version: 3.1.2
182
- signing_key:
187
+ rubygems_version: 3.1.4
188
+ signing_key:
183
189
  specification_version: 4
184
190
  summary: Easy inter-service communication using RabbitMQ.
185
191
  test_files:
@@ -188,13 +194,16 @@ test_files:
188
194
  - spec/hutch/config_spec.rb
189
195
  - spec/hutch/consumer_spec.rb
190
196
  - spec/hutch/error_handlers/airbrake_spec.rb
197
+ - spec/hutch/error_handlers/bugsnag_spec.rb
191
198
  - spec/hutch/error_handlers/honeybadger_spec.rb
192
199
  - spec/hutch/error_handlers/logger_spec.rb
193
200
  - spec/hutch/error_handlers/rollbar_spec.rb
201
+ - spec/hutch/error_handlers/sentry_raven_spec.rb
194
202
  - spec/hutch/error_handlers/sentry_spec.rb
195
203
  - spec/hutch/logger_spec.rb
196
204
  - spec/hutch/message_spec.rb
197
205
  - spec/hutch/serializers/json_spec.rb
206
+ - spec/hutch/tracers/datadog_spec.rb
198
207
  - spec/hutch/waiter_spec.rb
199
208
  - spec/hutch/worker_spec.rb
200
209
  - spec/hutch_spec.rb