freddy 1.4.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Freddy
4
- # Carrier for rabbitmq following OpenTracing API
5
- # See https://github.com/opentracing/opentracing-ruby/blob/master/lib/opentracing/carrier.rb
6
- class TraceCarrier
7
- def initialize(properties)
8
- @properties = properties
9
- end
10
-
11
- def [](key)
12
- @properties.headers && @properties.headers["x-trace-#{key}"]
13
- end
14
-
15
- def []=(key, value)
16
- @properties[:headers] ||= {}
17
- @properties[:headers]["x-trace-#{key}"] = value
18
- end
19
-
20
- def each(&block)
21
- Hash[
22
- (@properties.headers || {})
23
- .select { |key, _| key =~ /^x-trace/ }
24
- .map { |key, value| [key.sub(/x-trace-/, ''), value] }
25
- ].each(&block)
26
- end
27
- end
28
- end
@@ -1,56 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Freddy::TraceCarrier do
4
- subject(:carrier) { described_class.new(properties) }
5
-
6
- context 'when adding trace information' do
7
- let(:properties) { { x: 'y' } }
8
- let(:key_name) { 'some-key' }
9
- let(:key_value) { 'some-key' }
10
-
11
- it 'adds a header with x-trace- prefix' do
12
- carrier[key_name] = key_value
13
- expect(properties[:headers]["x-trace-#{key_name}"]).to eq(key_value)
14
- end
15
- end
16
-
17
- context 'when extracting trace information' do
18
- let(:key_name) { 'some-key' }
19
- let(:serialized_key_name) { "x-trace-#{key_name}" }
20
- let(:key_value) { 'some-key' }
21
-
22
- let(:properties) do
23
- double(headers: { serialized_key_name => key_value })
24
- end
25
-
26
- it 'extracts a header with x-trace- prefix' do
27
- expect(carrier[key_name]).to eq(key_value)
28
- end
29
- end
30
-
31
- describe '#each' do
32
- context 'when headers are present' do
33
- let(:properties) do
34
- double(
35
- headers: {
36
- 'x-trace-key1' => 'value1',
37
- 'x-trace-key2' => 'value2',
38
- 'other-key' => 'value3'
39
- }
40
- )
41
- end
42
-
43
- it 'iterates over keys starting with x-trace- prefix' do
44
- expect(carrier.each.count).to eq(2)
45
- end
46
- end
47
-
48
- context 'when no headers' do
49
- let(:properties) { double(headers: nil) }
50
-
51
- it 'iterates over an empty list' do
52
- expect(carrier.each.count).to eq(0)
53
- end
54
- end
55
- end
56
- end