freddy 2.2.1 → 2.3.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: 9c7e04742f9d67bcdce9f6bf6335d4ff12a1ac684a6059cffaeee00e44002426
4
- data.tar.gz: 2bb02e320d0b0458a182105a82931f48681a27b4f995c789cd6e7a655f3b9251
3
+ metadata.gz: 55182881b38a721d174a649943e973134d3ebac9c0502b34cce14ddc503f33db
4
+ data.tar.gz: 2e0c118f4a4af53745b070d512a74bdc87245e8c8489ea6985d788b71ddd9eab
5
5
  SHA512:
6
- metadata.gz: 3666fe665db677115174ae5d3d864cf3f67beccad3b5d7832be9497cece4296c516086b62af4c1b90514a67c69663dd56d9238ea02903880b6c9b8fb0fa26859
7
- data.tar.gz: 14578870d95999f972b7638f0ad5a6d80ea3d326a0d1f565ea6a673bb9f9133a316b00f11506fec3ec6d13db94d157cbd70aea1023f20664d4532365dd3d8982
6
+ metadata.gz: b72b0edde6c555492c90a722d19e99ccc32cd49a8066e7a7fcde71625541c90b1a893980b98f002beadc0644132512954e6f4d7850f55b536ef3f4771e71c1b0
7
+ data.tar.gz: 79a42a9ea43f43a472066129ea8fe5a00c793c458fe36d482d51286dc45e44d7de3cfc2f0fd23828e05cb4d2fe95471b9304d59a1e09c27cbcbbdb53c33fc1c8
@@ -27,5 +27,6 @@ jobs:
27
27
  with:
28
28
  ruby-version: ${{ matrix.ruby-version }}
29
29
  bundler-cache: true
30
+ cache-version: 1
30
31
  - name: Run lint & tests
31
32
  run: bundle exec rake
@@ -0,0 +1,22 @@
1
+ name: Publish Gem
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ with:
14
+ fetch-depth: 2
15
+
16
+
17
+ - name: Release Gem
18
+ uses: discourse/publish-rubygems-action@b55d7b91b55e61752dc6cbc2972f8e16fe6c1a02
19
+ env:
20
+ GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
21
+ RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
22
+ RELEASE_COMMAND: rake release
data/.gitignore CHANGED
@@ -1,5 +1,4 @@
1
1
  .bundle/
2
- Gemfile.lock
3
2
  pkg
4
3
  .tags
5
4
  .tags1
data/Gemfile.lock ADDED
@@ -0,0 +1,102 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ freddy (2.3.0)
5
+ bunny (~> 2.11)
6
+ oj (~> 3.6)
7
+ opentelemetry-api (~> 1.0.0.rc3)
8
+ opentelemetry-semantic_conventions (~> 1.0)
9
+ thread (~> 0.1)
10
+ zlib (~> 1.1)
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ amq-protocol (2.3.2)
16
+ ast (2.4.2)
17
+ bunny (2.19.0)
18
+ amq-protocol (~> 2.3, >= 2.3.1)
19
+ sorted_set (~> 1, >= 1.0.2)
20
+ coderay (1.1.3)
21
+ concurrent-ruby (1.1.9)
22
+ diff-lcs (1.4.4)
23
+ hamster (3.0.0)
24
+ concurrent-ruby (~> 1.0)
25
+ method_source (1.0.0)
26
+ oj (3.13.2)
27
+ opentelemetry-api (1.0.0.rc3)
28
+ opentelemetry-common (0.19.1)
29
+ opentelemetry-api (~> 1.0.0.rc3)
30
+ opentelemetry-instrumentation-base (0.18.2)
31
+ opentelemetry-api (~> 1.0.0.rc3)
32
+ opentelemetry-sdk (1.0.0.rc3)
33
+ opentelemetry-api (~> 1.0.0.rc3)
34
+ opentelemetry-common (~> 0.19.1)
35
+ opentelemetry-instrumentation-base (~> 0.18.2)
36
+ opentelemetry-semantic_conventions
37
+ opentelemetry-semantic_conventions (1.6.0)
38
+ opentelemetry-api (~> 1.0.0.rc3)
39
+ parallel (1.20.1)
40
+ parser (3.0.2.0)
41
+ ast (~> 2.4.1)
42
+ pry (0.14.1)
43
+ coderay (~> 1.1)
44
+ method_source (~> 1.0)
45
+ rainbow (3.0.0)
46
+ rake (13.0.6)
47
+ rbtree (0.4.4)
48
+ regexp_parser (2.1.1)
49
+ rexml (3.2.5)
50
+ rspec (3.10.0)
51
+ rspec-core (~> 3.10.0)
52
+ rspec-expectations (~> 3.10.0)
53
+ rspec-mocks (~> 3.10.0)
54
+ rspec-core (3.10.1)
55
+ rspec-support (~> 3.10.0)
56
+ rspec-expectations (3.10.1)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.10.0)
59
+ rspec-mocks (3.10.2)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.10.0)
62
+ rspec-support (3.10.2)
63
+ rubocop (1.19.0)
64
+ parallel (~> 1.10)
65
+ parser (>= 3.0.0.0)
66
+ rainbow (>= 2.2.2, < 4.0)
67
+ regexp_parser (>= 1.8, < 3.0)
68
+ rexml
69
+ rubocop-ast (>= 1.9.1, < 2.0)
70
+ ruby-progressbar (~> 1.7)
71
+ unicode-display_width (>= 1.4.0, < 3.0)
72
+ rubocop-ast (1.10.0)
73
+ parser (>= 3.0.1.1)
74
+ rubocop-rspec (2.4.0)
75
+ rubocop (~> 1.0)
76
+ rubocop-ast (>= 1.1.0)
77
+ ruby-progressbar (1.11.0)
78
+ set (1.0.1)
79
+ sorted_set (1.0.3)
80
+ rbtree
81
+ set (~> 1.0)
82
+ thread (0.2.2)
83
+ unicode-display_width (2.0.0)
84
+ zlib (1.1.0)
85
+
86
+ PLATFORMS
87
+ ruby
88
+ x86_64-linux
89
+
90
+ DEPENDENCIES
91
+ bundler
92
+ freddy!
93
+ hamster (~> 3.0)
94
+ opentelemetry-sdk (~> 1.0.0.rc3)
95
+ pry
96
+ rake
97
+ rspec
98
+ rubocop (~> 1.19)
99
+ rubocop-rspec (~> 2.4)
100
+
101
+ BUNDLED WITH
102
+ 2.2.27
data/README.md CHANGED
@@ -11,6 +11,10 @@ logger = Logger.new(STDOUT)
11
11
  freddy = Freddy.build(logger, host: 'localhost', port: 5672, user: 'guest', pass: 'guest')
12
12
  ```
13
13
 
14
+ ## Releasing a new version
15
+
16
+ A new version is created when a change is merged into the master branch that changes the version number in `freddy.gemspec`. A Github Action will create a tag for the version and push the `.gem` file to [rubygems.org](https://rubygems.org)
17
+
14
18
  ## Supported message queues
15
19
 
16
20
  These message queues have been tested and are working with Freddy. Other queues can be added easily:
@@ -47,7 +47,7 @@ class Freddy
47
47
 
48
48
  def process_message(_queue, delivery)
49
49
  @consume_thread_pool.process do
50
- delivery.in_span(force_follows_from: true) do
50
+ delivery.in_span do
51
51
  yield delivery.payload, delivery.routing_key
52
52
  @channel.acknowledge(delivery.tag)
53
53
  end
@@ -24,27 +24,13 @@ class Freddy
24
24
  @metadata.reply_to
25
25
  end
26
26
 
27
- def in_span(force_follows_from: false, &block)
28
- name = "#{@exchange}.#{@routing_key} receive"
27
+ def in_span(&block)
28
+ name = "#{Tracing.span_destination(@exchange, @routing_key)} process"
29
29
  kind = OpenTelemetry::Trace::SpanKind::CONSUMER
30
30
  producer_context = OpenTelemetry.propagation.extract(@metadata[:headers] || {})
31
31
 
32
- if force_follows_from
33
- producer_span_context = OpenTelemetry::Trace.current_span(producer_context).context
34
-
35
- links = []
36
- links << OpenTelemetry::Trace::Link.new(producer_span_context) if producer_span_context.valid?
37
-
38
- root_span = Freddy.tracer.start_root_span(name, attributes: span_attributes, links: links, kind: kind)
39
- OpenTelemetry::Trace.with_span(root_span) do
40
- Freddy.tracer.in_span(name, attributes: span_attributes, links: links, kind: kind, &block)
41
- ensure
42
- root_span.finish
43
- end
44
- else
45
- OpenTelemetry::Context.with_current(producer_context) do
46
- Freddy.tracer.in_span(name, attributes: span_attributes, kind: kind, &block)
47
- end
32
+ OpenTelemetry::Context.with_current(producer_context) do
33
+ Freddy.tracer.in_span(name, attributes: span_attributes, kind: kind, &block)
48
34
  end
49
35
  end
50
36
 
@@ -22,7 +22,7 @@ class Freddy
22
22
  routing_key: routing_key,
23
23
  content_type: CONTENT_TYPE
24
24
  )
25
- Tracing.inject_tracing_information_to_properties!(properties)
25
+ Tracing.inject_tracing_information_to_properties!(properties, span)
26
26
 
27
27
  @exchange.publish Payload.dump(payload), properties
28
28
  ensure
@@ -18,7 +18,7 @@ class Freddy
18
18
  routing_key: routing_key,
19
19
  content_type: CONTENT_TYPE
20
20
  )
21
- Tracing.inject_tracing_information_to_properties!(properties)
21
+ Tracing.inject_tracing_information_to_properties!(properties, span)
22
22
 
23
23
  json_payload = Freddy::Encoding.compress(
24
24
  Payload.dump(payload),
@@ -49,7 +49,7 @@ class Freddy
49
49
  correlation_id: correlation_id, reply_to: @response_queue.name,
50
50
  mandatory: true, type: 'request'
51
51
  )
52
- Tracing.inject_tracing_information_to_properties!(properties)
52
+ Tracing.inject_tracing_information_to_properties!(properties, span)
53
53
 
54
54
  # Connection adapters handle thread safety for #publish themselves. No
55
55
  # need to lock this.
@@ -2,6 +2,8 @@
2
2
 
3
3
  class Freddy
4
4
  module Tracing
5
+ RESPONSE_QUEUE_PREFIX = 'amq.gen-'
6
+
5
7
  # NOTE: Make sure you finish the span youself.
6
8
  def self.span_for_produce(exchange, routing_key, payload, correlation_id: nil, timeout_in_seconds: nil)
7
9
  destination = exchange.name
@@ -23,15 +25,24 @@ class Freddy
23
25
  end
24
26
 
25
27
  Freddy.tracer.start_span(
26
- ".#{routing_key} send",
28
+ "#{span_destination(destination, routing_key)} send",
27
29
  kind: OpenTelemetry::Trace::SpanKind::PRODUCER,
28
30
  attributes: attributes
29
31
  )
30
32
  end
31
33
 
32
- def self.inject_tracing_information_to_properties!(properties)
34
+ def self.span_destination(destination, routing_key)
35
+ if routing_key.to_s.start_with?(RESPONSE_QUEUE_PREFIX)
36
+ "#{destination}.(response queue)"
37
+ else
38
+ "#{destination}.#{routing_key}"
39
+ end
40
+ end
41
+
42
+ def self.inject_tracing_information_to_properties!(properties, span)
43
+ context = OpenTelemetry::Trace.context_with_span(span)
33
44
  properties[:headers] ||= {}
34
- OpenTelemetry.propagation.inject(properties[:headers])
45
+ OpenTelemetry.propagation.inject(properties[:headers], context: context)
35
46
  end
36
47
  end
37
48
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Freddy
4
- VERSION = '2.2.1'
4
+ VERSION = '2.3.0'
5
5
  end
@@ -1,7 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'Tracing' do
4
- let(:logger) { spy }
4
+ let(:exporter) { SPAN_EXPORTER }
5
+
6
+ before do
7
+ exporter.reset
8
+ end
5
9
 
6
10
  context 'when receiving a traced request' do
7
11
  let(:freddy) { Freddy.build(logger, config) }
@@ -48,6 +52,14 @@ describe 'Tracing' do
48
52
  expect(current_receiver.fetch(:span_id)).not_to be_nil
49
53
  expect(current_receiver.fetch(:span_id)).not_to eq(trace_initiator.fetch(:span_id))
50
54
  end
55
+
56
+ it 'replaces generated queue names with (response queue)' do
57
+ freddy.deliver_with_response(destination, {})
58
+ names = exporter.finished_spans.map(&:name)
59
+
60
+ expect(names.any? { |name| name.include?('amq.gen-') }).to eq(false)
61
+ expect(names.any? { |name| name.include?('(response queue)') }).to eq(true)
62
+ end
51
63
  end
52
64
 
53
65
  context 'when receiving a nested traced request' do
@@ -120,18 +132,20 @@ describe 'Tracing' do
120
132
  freddy.close
121
133
  end
122
134
 
123
- it 'creates a new trace and links it with the sender' do
124
- initiator_span = nil
135
+ it 'continues the existing trace' do
125
136
  Freddy.tracer.in_span('test') do
126
- initiator_span = current_span_attributes
127
137
  freddy.deliver(destination, {})
128
138
  end
129
139
  wait_for { @deliver_span }
130
140
 
131
- expect(@deliver_span.fetch(:trace_id)).not_to eq(initiator_span.fetch(:trace_id))
141
+ expect(exporter.finished_spans.map(&:name))
142
+ .to match([
143
+ /\.\w+ send/,
144
+ 'test',
145
+ /freddy-topic\.\w+ process/
146
+ ])
132
147
 
133
- link = @deliver_span.fetch(:links)[0]
134
- expect(link.span_context.trace_id).to eq(initiator_span.fetch(:trace_id))
148
+ expect(exporter.finished_spans.map(&:trace_id).uniq.count).to eq(1)
135
149
  end
136
150
  end
137
151
 
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,13 @@ require 'freddy'
11
11
  require 'logger'
12
12
  require 'hamster/experimental/mutable_set'
13
13
 
14
+ SPAN_EXPORTER = OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new
15
+ span_processor = OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(SPAN_EXPORTER)
16
+
17
+ OpenTelemetry::SDK.configure do |c|
18
+ c.add_span_processor(span_processor)
19
+ end
20
+
14
21
  Thread.abort_on_exception = true
15
22
 
16
23
  RSpec.configure do |config|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freddy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glia TechMovers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-15 00:00:00.000000000 Z
11
+ date: 2021-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -130,12 +130,14 @@ extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
132
  - ".github/workflows/ci.yml"
133
+ - ".github/workflows/publish.yml"
133
134
  - ".gitignore"
134
135
  - ".rspec"
135
136
  - ".rubocop.yml"
136
137
  - ".ruby-gemset"
137
138
  - ".ruby-version"
138
139
  - Gemfile
140
+ - Gemfile.lock
139
141
  - LICENCE.txt
140
142
  - README.md
141
143
  - Rakefile
@@ -196,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
198
  - !ruby/object:Gem::Version
197
199
  version: '0'
198
200
  requirements: []
199
- rubygems_version: 3.0.9
201
+ rubygems_version: 3.1.6
200
202
  signing_key:
201
203
  specification_version: 4
202
204
  summary: API for inter-application messaging supporting acknowledgements and request-response