Skip to content

Commit 3357a80

Browse files
committed
feat: [#43] Improve O11y
* Bump ruby docker image to 3.3 * Remove warnings from docker-compose * Add debug log when a message is received by a subscriber * Amend debug log when a message is published so that exchange name is included * Improve message for MissingExchangeDefinition and MissingConsumerDefinition * Use Gemfile for development dependencies of the gem * Add error_class, error_message and error_backtrace for `--require` file/folder from cli * Return self for Topology methods such as add_exchange, add_queue and add_binding
1 parent d4362af commit 3357a80

14 files changed

+116
-83
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## [0.9.0] - 2024-08-09
4+
5+
### Added
6+
- Add debug log when a message is received by a subscriber
7+
- Add error_class, error_message and error_backtrace for `--require` option from cli
8+
9+
### Changed
10+
- Amend debug log when a message is published so that exchange name is included
11+
- Improve error message for MissingExchangeDefinition and
12+
MissingConsumerDefinition
13+
- Define dev dependencies through Gemfile instead of gemspec
14+
- Changed Topology methods to return self so that Topology definition becomes chainable
15+
316
## [0.8.1] - 2024-04-08
417

518
### Fixed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ruby:3.2.2-alpine3.18 as base
1+
FROM ruby:3.3.4-alpine3.20 as base
22
ENV APP /opt
33
WORKDIR $APP
44
COPY Gemfile Gemfile.lock harmoniser.gemspec Rakefile $APP/

Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ source "https://rubygems.org"
44

55
# Specify your gem's dependencies in harmoniser.gemspec
66
gemspec
7+
8+
group :development, :test do
9+
gem 'rake', '~> 13'
10+
gem 'rspec', '~> 3'
11+
gem 'standardrb', '~> 1'
12+
end

Gemfile.lock

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
harmoniser (0.8.1)
4+
harmoniser (0.9.0)
55
bunny (~> 2.22)
66

77
GEM
@@ -12,78 +12,80 @@ GEM
1212
bunny (2.22.0)
1313
amq-protocol (~> 2.3, >= 2.3.1)
1414
sorted_set (~> 1, >= 1.0.2)
15-
diff-lcs (1.5.0)
16-
json (2.6.3)
15+
diff-lcs (1.5.1)
16+
json (2.7.2)
1717
language_server-protocol (3.17.0.3)
1818
lint_roller (1.1.0)
19-
parallel (1.23.0)
20-
parser (3.2.2.4)
19+
parallel (1.25.1)
20+
parser (3.3.4.0)
2121
ast (~> 2.4.1)
2222
racc
23-
racc (1.7.3)
23+
racc (1.8.0)
2424
rainbow (3.1.1)
25-
rake (13.1.0)
25+
rake (13.2.1)
2626
rbtree (0.4.6)
27-
regexp_parser (2.8.2)
28-
rexml (3.2.6)
29-
rspec (3.12.0)
30-
rspec-core (~> 3.12.0)
31-
rspec-expectations (~> 3.12.0)
32-
rspec-mocks (~> 3.12.0)
33-
rspec-core (3.12.2)
34-
rspec-support (~> 3.12.0)
35-
rspec-expectations (3.12.3)
27+
regexp_parser (2.9.2)
28+
rexml (3.3.2)
29+
strscan
30+
rspec (3.13.0)
31+
rspec-core (~> 3.13.0)
32+
rspec-expectations (~> 3.13.0)
33+
rspec-mocks (~> 3.13.0)
34+
rspec-core (3.13.0)
35+
rspec-support (~> 3.13.0)
36+
rspec-expectations (3.13.1)
3637
diff-lcs (>= 1.2.0, < 2.0)
37-
rspec-support (~> 3.12.0)
38-
rspec-mocks (3.12.6)
38+
rspec-support (~> 3.13.0)
39+
rspec-mocks (3.13.1)
3940
diff-lcs (>= 1.2.0, < 2.0)
40-
rspec-support (~> 3.12.0)
41-
rspec-support (3.12.1)
42-
rubocop (1.57.2)
41+
rspec-support (~> 3.13.0)
42+
rspec-support (3.13.1)
43+
rubocop (1.64.1)
4344
json (~> 2.3)
4445
language_server-protocol (>= 3.17.0)
4546
parallel (~> 1.10)
46-
parser (>= 3.2.2.4)
47+
parser (>= 3.3.0.2)
4748
rainbow (>= 2.2.2, < 4.0)
4849
regexp_parser (>= 1.8, < 3.0)
4950
rexml (>= 3.2.5, < 4.0)
50-
rubocop-ast (>= 1.28.1, < 2.0)
51+
rubocop-ast (>= 1.31.1, < 2.0)
5152
ruby-progressbar (~> 1.7)
5253
unicode-display_width (>= 2.4.0, < 3.0)
53-
rubocop-ast (1.30.0)
54-
parser (>= 3.2.1.0)
55-
rubocop-performance (1.19.1)
56-
rubocop (>= 1.7.0, < 2.0)
57-
rubocop-ast (>= 0.4.0)
54+
rubocop-ast (1.31.3)
55+
parser (>= 3.3.1.0)
56+
rubocop-performance (1.21.1)
57+
rubocop (>= 1.48.1, < 2.0)
58+
rubocop-ast (>= 1.31.1, < 2.0)
5859
ruby-progressbar (1.13.0)
5960
set (1.0.3)
6061
sorted_set (1.0.3)
6162
rbtree
6263
set (~> 1.0)
63-
standard (1.32.0)
64+
standard (1.39.2)
6465
language_server-protocol (~> 3.17.0.2)
6566
lint_roller (~> 1.0)
66-
rubocop (~> 1.57.2)
67+
rubocop (~> 1.64.0)
6768
standard-custom (~> 1.0.0)
68-
standard-performance (~> 1.2)
69+
standard-performance (~> 1.4)
6970
standard-custom (1.0.2)
7071
lint_roller (~> 1.0)
7172
rubocop (~> 1.50)
72-
standard-performance (1.2.1)
73+
standard-performance (1.4.0)
7374
lint_roller (~> 1.1)
74-
rubocop-performance (~> 1.19.1)
75+
rubocop-performance (~> 1.21.0)
7576
standardrb (1.0.1)
7677
standard
78+
strscan (3.1.0)
7779
unicode-display_width (2.5.0)
7880

7981
PLATFORMS
8082
aarch64-linux-musl
8183

8284
DEPENDENCIES
8385
harmoniser!
84-
rake (~> 13.0)
86+
rake (~> 13)
8587
rspec (~> 3)
86-
standardrb (~> 1.0)
88+
standardrb (~> 1)
8789

8890
BUNDLED WITH
8991
2.4.10

docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: "3.7"
21
services:
32
gem:
43
build:

harmoniser.gemspec

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,4 @@ Gem::Specification.new do |spec|
2525
spec.require_paths = ["lib"]
2626

2727
spec.add_runtime_dependency "bunny", "~> 2.22"
28-
spec.add_development_dependency "rake", "~> 13.0"
29-
spec.add_development_dependency "rspec", "~> 3"
30-
spec.add_development_dependency "standardrb", "~> 1.0"
3128
end

lib/harmoniser/launcher.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ def start_subscribers
3434
def load_rails
3535
filepath = File.expand_path("#{@configuration.require}/config/environment.rb")
3636
require filepath
37-
rescue LoadError
38-
@logger.warn("Error while requiring file within directory. No subscribers will run for this process: require = `#{@configuration.require}`, filepath = `#{filepath}`")
37+
rescue LoadError => e
38+
@logger.warn("Error while requiring file within directory. No subscribers will run for this process: require = `#{@configuration.require}`, filepath = `#{filepath}`, error_class = `#{e.class}`, error_message = `#{e.message}`, error_backtrace = `#{e.backtrace&.first(5)}`")
3939
end
4040

4141
def load_file
4242
require @configuration.require
43-
rescue LoadError
44-
@logger.warn("Error while requiring file. No subscribers will run for this process: require = `#{@configuration.require}`")
43+
rescue LoadError => e
44+
@logger.warn("Error while requiring file. No subscribers will run for this process: require = `#{@configuration.require}`, error_class = `#{e.class}`, error_message = `#{e.message}`, error_backtrace = `#{e.backtrace&.first(5)}`")
4545
end
4646
end
4747
end

lib/harmoniser/publisher.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def publish(payload, opts = {})
2121
const_get(:HARMONISER_PUBLISHER_MUTEX).synchronize do
2222
harmoniser_exchange.publish(payload, opts)
2323
end
24-
Harmoniser.logger.debug { "Message published: payload = `#{payload}`, opts = `#{opts}`" }
24+
Harmoniser.logger.debug { "Message published: exchange = `#{@harmoniser_exchange_definition.name}`, payload = `#{payload}`, opts = `#{opts}`" }
2525

2626
harmoniser_exchange
2727
end
@@ -44,7 +44,7 @@ def create_exchange
4444
end
4545

4646
def raise_missing_exchange_definition
47-
raise MissingExchangeDefinition, "Please, call harmoniser_publisher class method first with the exchange_name that will be used for publications"
47+
raise MissingExchangeDefinition, "Please call the harmoniser_publisher class method at `#{const_get(:HARMONISER_PUBLISHER_CLASS)}` with the exchange_name that will be used for publishing"
4848
end
4949

5050
def handle_return(exchange)
@@ -57,6 +57,7 @@ def handle_return(exchange)
5757
class << self
5858
def included(base)
5959
base.const_set(:HARMONISER_PUBLISHER_MUTEX, Mutex.new)
60+
base.const_set(:HARMONISER_PUBLISHER_CLASS, base)
6061
base.extend(ClassMethods)
6162
end
6263
end

lib/harmoniser/subscriber.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def handle_cancellation(consumer)
5757

5858
def handle_delivery(consumer)
5959
consumer.on_delivery do |delivery_info, properties, payload|
60+
Harmoniser.logger.debug { "Message received by a consumer: consumer_tag = `#{consumer.consumer_tag}, `payload = `#{payload}`, queue = `#{consumer.queue}`" }
6061
if respond_to?(:on_delivery)
6162
on_delivery(delivery_info, properties, payload)
6263
else
@@ -70,13 +71,14 @@ def register_consumer(consumer)
7071
end
7172

7273
def raise_missing_consumer_definition
73-
raise MissingConsumerDefinition, "Please, call harmoniser_subscriber class method first with the queue_name that will be used for subscribing"
74+
raise MissingConsumerDefinition, "Please call the harmoniser_subscriber class method at `#{const_get(:HARMONISER_SUBSCRIBER_CLASS)}` with the queue_name that will be used for subscribing"
7475
end
7576
end
7677

7778
class << self
7879
def included(base)
7980
base.const_set(:HARMONISER_SUBSCRIBER_MUTEX, Mutex.new)
81+
base.const_set(:HARMONISER_SUBSCRIBER_CLASS, base)
8082
base.extend(ClassMethods)
8183
harmoniser_register_included(base)
8284
end

lib/harmoniser/topology.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ def add_exchange(type, name, **opts)
1919
name: name,
2020
opts: opts
2121
)
22+
self
2223
end
2324

2425
def add_queue(name, **opts)
2526
@queues << Definition::Queue.new(
2627
name: name,
2728
opts: opts
2829
)
30+
self
2931
end
3032

3133
def add_binding(exchange_name, destination_name, destination_type = :queue, **opts)
@@ -35,6 +37,7 @@ def add_binding(exchange_name, destination_name, destination_type = :queue, **op
3537
destination_type: destination_type,
3638
opts: opts
3739
)
40+
self
3841
end
3942

4043
def declare

0 commit comments

Comments
 (0)