freddy 2.1.0 → 2.2.3

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: 49a24c63763b6d607d1b5ee60ca4f65211a212999ca5852637c6a567ed6b13d2
4
- data.tar.gz: da8e0b5d8818df0b054a66412c61b9b57f5648295b1a81f0e7f79b017cae66ba
3
+ metadata.gz: 6be4b4b6d953f837c24d9c55f990e4e75872c13e6c11007d8f61ed335681faa2
4
+ data.tar.gz: 863042876b2ed673001cd53f296567ad91420864b96cbed5ed02fb6fd7820b22
5
5
  SHA512:
6
- metadata.gz: 6323a6cb6f468a10c3395c318d3edb9f9de1de984b6f995786fceb17ca8b7a5b37adcc87649ade6caa7868da7671b09bf01d92365d9c46b9c0fa4b6a0a1e4db5
7
- data.tar.gz: c41436342bcb7523f236c4ecec8ba77c0d990fef21aaaff7e3ea9f56071e2797b84faa3266fb176e01d452c1d706e82825c673ac83ac1f4bb4d8ed94f59e5d3a
6
+ metadata.gz: 002f901659f670dc1561db4ddc97d10e5a9d9b689369897628f1844fa0ffc65f759493fe96bc7541f6b7c204427bb584133fa3b306e19752b133a42b1b077a52
7
+ data.tar.gz: d2383b11b79800aabf6a0f0fe52a51f900a12c5ebcf17e64be8ca5e31243bd183dadb662e17c14416b0ee3e7d5ad26cbe00e067f7c39b709133a019082358fe8
@@ -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:
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'bunny'
4
+ require 'forwardable'
4
5
 
5
6
  class Freddy
6
7
  module Adapters
@@ -25,7 +25,7 @@ class Freddy
25
25
  end
26
26
 
27
27
  def in_span(force_follows_from: false, &block)
28
- name = "#{@exchange}.#{@routing_key} receive"
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
 
@@ -35,12 +35,12 @@ class Freddy
35
35
  links = []
36
36
  links << OpenTelemetry::Trace::Link.new(producer_span_context) if producer_span_context.valid?
37
37
 
38
- # In general we should start a new trace here and just link two traces
39
- # together. But Zipkin (which we currently use) doesn't support links.
40
- # So even though the root trace could finish before anything here
41
- # starts executing, we'll continue with the root trace here as well.
42
- OpenTelemetry::Context.with_current(producer_context) do
43
- Freddy.tracer.in_span(name, attributes: span_attributes, links: links, kind: kind, &block)
38
+ root_span = Freddy.tracer.start_root_span(name, attributes: span_attributes, links: links, kind: kind)
39
+
40
+ OpenTelemetry::Trace.with_span(root_span) do
41
+ block.call
42
+ ensure
43
+ root_span.finish
44
44
  end
45
45
  else
46
46
  OpenTelemetry::Context.with_current(producer_context) do
@@ -60,7 +60,7 @@ class Freddy
60
60
  OpenTelemetry::SemanticConventions::Trace::MESSAGING_DESTINATION => @exchange,
61
61
  OpenTelemetry::SemanticConventions::Trace::MESSAGING_DESTINATION_KIND => destination_kind,
62
62
  OpenTelemetry::SemanticConventions::Trace::MESSAGING_RABBITMQ_ROUTING_KEY => @routing_key,
63
- OpenTelemetry::SemanticConventions::Trace::MESSAGING_OPERATION => 'receive'
63
+ OpenTelemetry::SemanticConventions::Trace::MESSAGING_OPERATION => 'process'
64
64
  }
65
65
 
66
66
  # There's no correlation_id when a message was sent using
@@ -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,12 +25,20 @@ 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
 
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
+
32
42
  def self.inject_tracing_information_to_properties!(properties)
33
43
  properties[:headers] ||= {}
34
44
  OpenTelemetry.propagation.inject(properties[:headers])
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Freddy
4
- VERSION = '2.1.0'
4
+ VERSION = '2.2.3'
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
@@ -106,11 +118,48 @@ describe 'Tracing' do
106
118
  end
107
119
  end
108
120
 
121
+ context 'when receiving a broadcast' do
122
+ let(:freddy) { Freddy.build(logger, config) }
123
+ let(:destination) { random_destination }
124
+
125
+ before do
126
+ freddy.tap_into(destination) do
127
+ @deliver_span = current_span_attributes
128
+ end
129
+ end
130
+
131
+ after do
132
+ freddy.close
133
+ end
134
+
135
+ it 'creates a new trace and links it with the sender' do
136
+ initiator_span = nil
137
+ Freddy.tracer.in_span('test') do
138
+ initiator_span = current_span_attributes
139
+ freddy.deliver(destination, {})
140
+ end
141
+ wait_for { @deliver_span }
142
+
143
+ expect(exporter.finished_spans.map(&:name))
144
+ .to match([
145
+ /\.\w+ send/,
146
+ 'test',
147
+ /freddy-topic\.\w+ process/
148
+ ])
149
+
150
+ expect(@deliver_span.fetch(:trace_id)).not_to eq(initiator_span.fetch(:trace_id))
151
+
152
+ link = @deliver_span.fetch(:links)[0]
153
+ expect(link.span_context.trace_id).to eq(initiator_span.fetch(:trace_id))
154
+ end
155
+ end
156
+
109
157
  def current_span_attributes
110
158
  {
111
159
  trace_id: current_span.context.trace_id,
112
160
  parent_id: current_span.parent_span_id,
113
- span_id: current_span.context.span_id
161
+ span_id: current_span.context.span_id,
162
+ links: current_span.links || []
114
163
  }
115
164
  end
116
165
 
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.1.0
4
+ version: 2.2.3
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-07 00:00:00.000000000 Z
11
+ date: 2021-10-11 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"
@@ -196,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
197
  - !ruby/object:Gem::Version
197
198
  version: '0'
198
199
  requirements: []
199
- rubygems_version: 3.1.4
200
+ rubygems_version: 3.1.6
200
201
  signing_key:
201
202
  specification_version: 4
202
203
  summary: API for inter-application messaging supporting acknowledgements and request-response