freddy 1.3.3 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +2 -27
- data/freddy.gemspec +1 -1
- data/lib/freddy/consumers/respond_to_consumer.rb +3 -4
- data/lib/freddy/consumers/tap_into_consumer.rb +3 -4
- data/lib/freddy/delivery.rb +9 -14
- data/lib/freddy/producers/reply_producer.rb +5 -1
- data/lib/freddy/producers/send_and_forget_producer.rb +0 -1
- data/lib/freddy/producers/send_and_wait_response_producer.rb +1 -2
- data/lib/freddy.rb +6 -2
- data/spec/integration/tracing_spec.rb +21 -17
- metadata +2 -4
- data/spec/integration/logging_spec.rb +0 -101
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98d55ddef79dc7231d80d81a8c777a20ffa09685
|
4
|
+
data.tar.gz: c3f6ab7881cc7c22bcee599db7c60318522fe8a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb2fb6945b67811ed7b211d360ffba3f0b63a2ba4a8dcc7bf5f94f3f8c46ca0fb9092a0ab982b69804bf4d054152df1ac4a8bf01df98058bb095890820f86482
|
7
|
+
data.tar.gz: c56d8aaffbe32d22c5e5e761f4a13d0c9075ca398ca5865c4808d9d9b38e3c550b64326bb747d8de4141eaeddeb582614ad8aafd9f0e772349a30948850b8f27
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -142,34 +142,9 @@ Freddy supports [OpenTracing API|https://github.com/opentracing/opentracing-ruby
|
|
142
142
|
OpenTracing.global_tracing = MyTracerImplementation.new(...)
|
143
143
|
```
|
144
144
|
|
145
|
-
|
145
|
+
Current trace can be accessed through a thread-local variable `OpenTracing.active_span`. Calling `deliver` or `deliver_with_response` will pass trace context to down-stream services.
|
146
146
|
|
147
|
-
|
148
|
-
|
149
|
-
Accessing trace information when using Logasm::Tracer implementation:
|
150
|
-
|
151
|
-
```ruby
|
152
|
-
freddy1 = Freddy.build
|
153
|
-
freddy1.respond_do('service1') do |payload, msg_handler|
|
154
|
-
puts "Trace id: #{Freddy.trace.context.trace_id}"
|
155
|
-
puts "Span id: #{Freddy.trace.context.span_id}"
|
156
|
-
|
157
|
-
freddy1.deliver('service2', {})
|
158
|
-
end
|
159
|
-
|
160
|
-
freddy2 = Freddy.build
|
161
|
-
freddy2.tap_into('service2') do |payload|
|
162
|
-
puts "Has same trace_id as the request in service1: #{Freddy.trace.context.trace_id}"
|
163
|
-
puts "Has service1 request span id as parent id: #{Freddy.trace.context.parent_id}"
|
164
|
-
puts "Has its own generated span id: #{Freddy.trace.context.span_id}"
|
165
|
-
end
|
166
|
-
```
|
167
|
-
|
168
|
-
In case you already have an ongoing OpenTracing span (e.g. provided by REST API) then you can pass the trace information to Freddy by doing:
|
169
|
-
```ruby
|
170
|
-
Freddy.trace = trace_span
|
171
|
-
```
|
172
|
-
The `trace_span` must implement OpenTracing::Span interface.
|
147
|
+
See [opentracing-ruby](https://github.com/opentracing/opentracing-ruby) for more information.
|
173
148
|
|
174
149
|
## Notes about concurrency
|
175
150
|
|
data/freddy.gemspec
CHANGED
@@ -34,14 +34,14 @@ class Freddy
|
|
34
34
|
def process_message(delivery, &block)
|
35
35
|
@consume_thread_pool.process do
|
36
36
|
begin
|
37
|
-
|
37
|
+
scope = delivery.build_trace("freddy:respond:#{@destination}",
|
38
38
|
tags: {
|
39
39
|
'peer.address': "#{@destination}:#{delivery.payload[:type]}",
|
40
40
|
'component': 'freddy',
|
41
41
|
'span.kind': 'server' # RPC
|
42
42
|
}
|
43
43
|
)
|
44
|
-
|
44
|
+
scope.span.log_kv(
|
45
45
|
event: 'Received message through respond_to',
|
46
46
|
queue: @destination,
|
47
47
|
payload: delivery.payload,
|
@@ -51,8 +51,7 @@ class Freddy
|
|
51
51
|
block.call(delivery)
|
52
52
|
ensure
|
53
53
|
@channel.acknowledge(delivery.tag, false)
|
54
|
-
|
55
|
-
Freddy.trace = nil
|
54
|
+
scope.close
|
56
55
|
end
|
57
56
|
end
|
58
57
|
end
|
@@ -42,7 +42,7 @@ class Freddy
|
|
42
42
|
def process_message(queue, delivery, &block)
|
43
43
|
@consume_thread_pool.process do
|
44
44
|
begin
|
45
|
-
|
45
|
+
scope = delivery.build_trace("freddy:observe:#{@pattern}",
|
46
46
|
tags: {
|
47
47
|
'message_bus.destination': @pattern,
|
48
48
|
'component': 'freddy',
|
@@ -50,7 +50,7 @@ class Freddy
|
|
50
50
|
},
|
51
51
|
force_follows_from: true
|
52
52
|
)
|
53
|
-
|
53
|
+
scope.span.log_kv(
|
54
54
|
event: 'Received message through tap_into',
|
55
55
|
payload: delivery.payload,
|
56
56
|
correlation_id: delivery.correlation_id
|
@@ -59,8 +59,7 @@ class Freddy
|
|
59
59
|
block.call delivery.payload, delivery.routing_key
|
60
60
|
ensure
|
61
61
|
@channel.acknowledge(delivery.tag, false)
|
62
|
-
|
63
|
-
Freddy.trace = nil
|
62
|
+
scope.close
|
64
63
|
end
|
65
64
|
end
|
66
65
|
end
|
data/lib/freddy/delivery.rb
CHANGED
@@ -23,23 +23,18 @@ class Freddy
|
|
23
23
|
|
24
24
|
def build_trace(operation_name, tags: {}, force_follows_from: false)
|
25
25
|
carrier = TraceCarrier.new(@metadata)
|
26
|
-
parent =
|
27
|
-
|
28
|
-
|
26
|
+
parent = OpenTracing.global_tracer.extract(OpenTracing::FORMAT_TEXT_MAP, carrier)
|
27
|
+
|
28
|
+
references =
|
29
|
+
if !parent
|
30
|
+
[]
|
31
|
+
elsif force_follows_from
|
32
|
+
[OpenTracing::Reference.follows_from(parent)]
|
29
33
|
else
|
30
|
-
|
34
|
+
[OpenTracing::Reference.child_of(parent)]
|
31
35
|
end
|
32
36
|
|
33
|
-
|
34
|
-
# Otherwise creating a new trace because the OpenTracing client does not
|
35
|
-
# support FollowsFrom yet.
|
36
|
-
OpenTracing.start_span(operation_name, child_of: parent, tags: tags)
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def expecting_response?
|
42
|
-
type == 'request'
|
37
|
+
OpenTracing.start_active_span(operation_name, references: references, tags: tags)
|
43
38
|
end
|
44
39
|
end
|
45
40
|
end
|
@@ -9,7 +9,11 @@ class Freddy
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def produce(destination, payload, properties)
|
12
|
-
|
12
|
+
OpenTracing.active_span.log_kv(
|
13
|
+
event: 'Sending response',
|
14
|
+
queue: destination,
|
15
|
+
payload: payload
|
16
|
+
)
|
13
17
|
|
14
18
|
properties = properties.merge(
|
15
19
|
routing_key: destination,
|
@@ -24,11 +24,10 @@ class Freddy
|
|
24
24
|
|
25
25
|
def produce(destination, payload, timeout_in_seconds:, delete_on_timeout:, **properties)
|
26
26
|
span = OpenTracing.start_span("freddy:request:#{destination}",
|
27
|
-
child_of: Freddy.trace,
|
28
27
|
tags: {
|
29
28
|
'component': 'freddy',
|
30
29
|
'span.kind': 'client', # RPC
|
31
|
-
'payload.type': payload[:type]
|
30
|
+
'payload.type': payload[:type] || 'unknown'
|
32
31
|
}
|
33
32
|
)
|
34
33
|
|
data/lib/freddy.rb
CHANGED
@@ -32,12 +32,16 @@ class Freddy
|
|
32
32
|
new(connection, logger, max_concurrency)
|
33
33
|
end
|
34
34
|
|
35
|
+
# @deprecated Use {OpenTracing.active_span} instead
|
35
36
|
def self.trace
|
36
|
-
|
37
|
+
OpenTracing.active_span
|
37
38
|
end
|
38
39
|
|
40
|
+
# @deprecated Use OpenTracing ScopeManager instead
|
39
41
|
def self.trace=(trace)
|
40
|
-
|
42
|
+
if OpenTracing.active_span != trace
|
43
|
+
OpenTracing.scope_manager.activate(trace)
|
44
|
+
end
|
41
45
|
end
|
42
46
|
|
43
47
|
def initialize(connection, logger, max_concurrency)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require '
|
2
|
+
require 'opentracing_test_tracer'
|
3
3
|
|
4
4
|
describe 'Tracing' do
|
5
|
-
let(:tracer) {
|
5
|
+
let(:tracer) { OpenTracingTestTracer.build(logger: logger) }
|
6
6
|
let(:logger) { spy }
|
7
7
|
|
8
8
|
before { OpenTracing.global_tracer = tracer }
|
@@ -19,9 +19,9 @@ describe 'Tracing' do
|
|
19
19
|
freddy.respond_to(destination) do |payload, msg_handler|
|
20
20
|
msg_handler.success({
|
21
21
|
trace_initiator: {
|
22
|
-
trace_id:
|
23
|
-
parent_id:
|
24
|
-
span_id:
|
22
|
+
trace_id: active_span.context.trace_id,
|
23
|
+
parent_id: active_span.context.parent_id,
|
24
|
+
span_id: active_span.context.span_id
|
25
25
|
},
|
26
26
|
current_receiver: freddy.deliver_with_response(destination2, {})
|
27
27
|
})
|
@@ -29,9 +29,9 @@ describe 'Tracing' do
|
|
29
29
|
|
30
30
|
freddy2.respond_to(destination2) do |payload, msg_handler|
|
31
31
|
msg_handler.success({
|
32
|
-
trace_id:
|
33
|
-
parent_id:
|
34
|
-
span_id:
|
32
|
+
trace_id: active_span.context.trace_id,
|
33
|
+
parent_id: active_span.context.parent_id,
|
34
|
+
span_id: active_span.context.span_id
|
35
35
|
})
|
36
36
|
end
|
37
37
|
end
|
@@ -76,9 +76,9 @@ describe 'Tracing' do
|
|
76
76
|
freddy.respond_to(destination) do |payload, msg_handler|
|
77
77
|
msg_handler.success({
|
78
78
|
trace_initiator: {
|
79
|
-
trace_id:
|
80
|
-
parent_id:
|
81
|
-
span_id:
|
79
|
+
trace_id: active_span.context.trace_id,
|
80
|
+
parent_id: active_span.context.parent_id,
|
81
|
+
span_id: active_span.context.span_id
|
82
82
|
}
|
83
83
|
}.merge(freddy.deliver_with_response(destination2, {})))
|
84
84
|
end
|
@@ -86,9 +86,9 @@ describe 'Tracing' do
|
|
86
86
|
freddy2.respond_to(destination2) do |payload, msg_handler|
|
87
87
|
msg_handler.success({
|
88
88
|
previous_receiver: {
|
89
|
-
trace_id:
|
90
|
-
parent_id:
|
91
|
-
span_id:
|
89
|
+
trace_id: active_span.context.trace_id,
|
90
|
+
parent_id: active_span.context.parent_id,
|
91
|
+
span_id: active_span.context.span_id
|
92
92
|
},
|
93
93
|
current_receiver: freddy2.deliver_with_response(destination3, {})
|
94
94
|
})
|
@@ -96,9 +96,9 @@ describe 'Tracing' do
|
|
96
96
|
|
97
97
|
freddy3.respond_to(destination3) do |payload, msg_handler|
|
98
98
|
msg_handler.success({
|
99
|
-
trace_id:
|
100
|
-
parent_id:
|
101
|
-
span_id:
|
99
|
+
trace_id: active_span.context.trace_id,
|
100
|
+
parent_id: active_span.context.parent_id,
|
101
|
+
span_id: active_span.context.span_id
|
102
102
|
})
|
103
103
|
end
|
104
104
|
end
|
@@ -130,4 +130,8 @@ describe 'Tracing' do
|
|
130
130
|
expect(current_receiver.fetch(:span_id)).to_not eq(previous_receiver.fetch(:span_id))
|
131
131
|
end
|
132
132
|
end
|
133
|
+
|
134
|
+
def active_span
|
135
|
+
OpenTracing.active_span
|
136
|
+
end
|
133
137
|
end
|
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: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Salemove TechMovers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -144,7 +144,6 @@ files:
|
|
144
144
|
- spec/freddy/sync_response_container_spec.rb
|
145
145
|
- spec/freddy/trace_carrier_spec.rb
|
146
146
|
- spec/integration/concurrency_spec.rb
|
147
|
-
- spec/integration/logging_spec.rb
|
148
147
|
- spec/integration/reply_spec.rb
|
149
148
|
- spec/integration/tap_into_with_group_spec.rb
|
150
149
|
- spec/integration/tracing_spec.rb
|
@@ -183,7 +182,6 @@ test_files:
|
|
183
182
|
- spec/freddy/sync_response_container_spec.rb
|
184
183
|
- spec/freddy/trace_carrier_spec.rb
|
185
184
|
- spec/integration/concurrency_spec.rb
|
186
|
-
- spec/integration/logging_spec.rb
|
187
185
|
- spec/integration/reply_spec.rb
|
188
186
|
- spec/integration/tap_into_with_group_spec.rb
|
189
187
|
- spec/integration/tracing_spec.rb
|
@@ -1,101 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'logasm/tracer'
|
3
|
-
|
4
|
-
describe 'Logging with Logasm::Tracer' do
|
5
|
-
let(:logger) { ArrayLogger.new }
|
6
|
-
let(:tracer) { Logasm::Tracer.new(logger) }
|
7
|
-
|
8
|
-
before { OpenTracing.global_tracer = tracer }
|
9
|
-
after { OpenTracing.global_tracer = nil }
|
10
|
-
|
11
|
-
context 'when receiving an untraced request' do
|
12
|
-
let(:freddy) { Freddy.build(spy, config) }
|
13
|
-
let(:destination) { random_destination }
|
14
|
-
|
15
|
-
before do
|
16
|
-
freddy.respond_to(destination) do |payload, msg_handler|
|
17
|
-
sleep 0.1 # emulate some processing
|
18
|
-
msg_handler.success({})
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
after { freddy.close }
|
23
|
-
|
24
|
-
it 'generates a trace' do
|
25
|
-
freddy.deliver_with_response(destination, {})
|
26
|
-
|
27
|
-
expect(logger.calls.map(&:first)).to eq([
|
28
|
-
# Initiator
|
29
|
-
"Span [freddy:request:#{destination}] started",
|
30
|
-
"Span [freddy:request:#{destination}] Publishing request",
|
31
|
-
|
32
|
-
# Service
|
33
|
-
"Span [freddy:respond:#{destination}] started",
|
34
|
-
"Span [freddy:respond:#{destination}] Received message through respond_to",
|
35
|
-
"Span [freddy:respond:#{destination}] Sending response",
|
36
|
-
"Span [freddy:respond:#{destination}] finished",
|
37
|
-
|
38
|
-
# Initiator
|
39
|
-
"Span [freddy:request:#{destination}] finished"
|
40
|
-
])
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'when receiving a traced request' do
|
45
|
-
let(:freddy) { Freddy.build(spy, config) }
|
46
|
-
let(:freddy2) { Freddy.build(spy, config) }
|
47
|
-
|
48
|
-
let(:destination) { random_destination }
|
49
|
-
let(:destination2) { random_destination }
|
50
|
-
|
51
|
-
before do
|
52
|
-
freddy.respond_to(destination) do |payload, msg_handler|
|
53
|
-
sleep 0.1 # emulate some processing
|
54
|
-
msg_handler.success({
|
55
|
-
trace_initiator: {},
|
56
|
-
current_receiver: freddy.deliver_with_response(destination2, {})
|
57
|
-
})
|
58
|
-
end
|
59
|
-
|
60
|
-
freddy2.respond_to(destination2) do |payload, msg_handler|
|
61
|
-
sleep 0.1 # emulate some processing
|
62
|
-
msg_handler.success({})
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
after do
|
67
|
-
freddy.close
|
68
|
-
freddy2.close
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'generates a trace' do
|
72
|
-
freddy.deliver_with_response(destination, {})
|
73
|
-
|
74
|
-
expect(logger.calls.map(&:first)).to eq([
|
75
|
-
# Initiator
|
76
|
-
"Span [freddy:request:#{destination}] started",
|
77
|
-
"Span [freddy:request:#{destination}] Publishing request",
|
78
|
-
|
79
|
-
# Service 1
|
80
|
-
"Span [freddy:respond:#{destination}] started",
|
81
|
-
"Span [freddy:respond:#{destination}] Received message through respond_to",
|
82
|
-
"Span [freddy:request:#{destination2}] started",
|
83
|
-
"Span [freddy:request:#{destination2}] Publishing request",
|
84
|
-
|
85
|
-
# Service 2
|
86
|
-
"Span [freddy:respond:#{destination2}] started",
|
87
|
-
"Span [freddy:respond:#{destination2}] Received message through respond_to",
|
88
|
-
"Span [freddy:respond:#{destination2}] Sending response",
|
89
|
-
"Span [freddy:respond:#{destination2}] finished",
|
90
|
-
|
91
|
-
# Service 1
|
92
|
-
"Span [freddy:request:#{destination2}] finished",
|
93
|
-
"Span [freddy:respond:#{destination}] Sending response",
|
94
|
-
"Span [freddy:respond:#{destination}] finished",
|
95
|
-
|
96
|
-
# Initiator
|
97
|
-
"Span [freddy:request:#{destination}] finished"
|
98
|
-
])
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|