freddy 2.2.0 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/publish.yml +22 -0
- data/README.md +4 -0
- data/lib/freddy/adapters/bunny_adapter.rb +1 -0
- data/lib/freddy/delivery.rb +3 -2
- data/lib/freddy/producers/reply_producer.rb +1 -1
- data/lib/freddy/producers/send_and_forget_producer.rb +1 -1
- data/lib/freddy/producers/send_and_wait_response_producer.rb +1 -1
- data/lib/freddy/tracing.rb +14 -3
- data/lib/freddy/version.rb +1 -1
- data/spec/integration/tracing_spec.rb +23 -1
- data/spec/spec_helper.rb +7 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d6513e834c71f74caf3c8417644369fddf4087d226d8160c0d72f63d6551db0
|
4
|
+
data.tar.gz: e4cd3e5016030ec1b5727d9764593d7af91c389b528458a2befeecc502a6600a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81581b4a9c227aebcfb7f96db79367e4d233502bc0586599500530bb339826371dad203f928e45b2e512f74469c87c8f6f591ca9602d0a14e2e6f047868dae61
|
7
|
+
data.tar.gz: '090195d2a78659ac91cfef94099dca0bdf382b52590b9298680cd17ed5a04586ee87f5ace05e2fb2a465dc8cf87a07c3504445d78f3d25d6839c34208b291a10'
|
@@ -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/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:
|
data/lib/freddy/delivery.rb
CHANGED
@@ -25,7 +25,7 @@ class Freddy
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def in_span(force_follows_from: false, &block)
|
28
|
-
name = "#{@exchange
|
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
|
|
@@ -36,8 +36,9 @@ class Freddy
|
|
36
36
|
links << OpenTelemetry::Trace::Link.new(producer_span_context) if producer_span_context.valid?
|
37
37
|
|
38
38
|
root_span = Freddy.tracer.start_root_span(name, attributes: span_attributes, links: links, kind: kind)
|
39
|
+
|
39
40
|
OpenTelemetry::Trace.with_span(root_span) do
|
40
|
-
|
41
|
+
block.call
|
41
42
|
ensure
|
42
43
|
root_span.finish
|
43
44
|
end
|
@@ -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.
|
data/lib/freddy/tracing.rb
CHANGED
@@ -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
|
-
"
|
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.
|
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
|
data/lib/freddy/version.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Tracing' do
|
4
|
-
let(:
|
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
|
@@ -128,10 +140,20 @@ describe 'Tracing' do
|
|
128
140
|
end
|
129
141
|
wait_for { @deliver_span }
|
130
142
|
|
143
|
+
expect(exporter.finished_spans.map(&:name))
|
144
|
+
.to match([
|
145
|
+
/\.\w+ send/,
|
146
|
+
'test',
|
147
|
+
/freddy-topic\.\w+ process/
|
148
|
+
])
|
149
|
+
|
150
|
+
send_span = exporter.finished_spans.find { |span| span.name =~ /\.\w+ send/ }
|
151
|
+
|
131
152
|
expect(@deliver_span.fetch(:trace_id)).not_to eq(initiator_span.fetch(:trace_id))
|
132
153
|
|
133
154
|
link = @deliver_span.fetch(:links)[0]
|
134
155
|
expect(link.span_context.trace_id).to eq(initiator_span.fetch(:trace_id))
|
156
|
+
expect(link.span_context.span_id).to eq(send_span.span_id)
|
135
157
|
end
|
136
158
|
end
|
137
159
|
|
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.
|
4
|
+
version: 2.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Glia TechMovers
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -130,6 +130,7 @@ 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"
|
@@ -181,7 +182,7 @@ homepage: https://github.com/salemove/freddy
|
|
181
182
|
licenses:
|
182
183
|
- MIT
|
183
184
|
metadata: {}
|
184
|
-
post_install_message:
|
185
|
+
post_install_message:
|
185
186
|
rdoc_options: []
|
186
187
|
require_paths:
|
187
188
|
- lib
|
@@ -197,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
198
|
version: '0'
|
198
199
|
requirements: []
|
199
200
|
rubygems_version: 3.1.6
|
200
|
-
signing_key:
|
201
|
+
signing_key:
|
201
202
|
specification_version: 4
|
202
203
|
summary: API for inter-application messaging supporting acknowledgements and request-response
|
203
204
|
test_files:
|