forked from getsentry/sentry-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
baggage_spec.rb
103 lines (90 loc) · 3.06 KB
/
baggage_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require "spec_helper"
RSpec.describe Sentry::Baggage do
let(:malformed_baggage) { "," }
let(:third_party_baggage) { "other-vendor-value-1=foo;bar;baz, other-vendor-value-2=foo;bar;" }
let(:mixed_baggage) do
"other-vendor-value-1=foo;bar;baz, "\
"sentry-trace_id=771a43a4192642f0b136d5159a501700, "\
"sentry-public_key=49d0f7386ad645858ae85020e393bef3, "\
"sentry-sample_rate=0.01337, "\
"sentry-user_id=Am%C3%A9lie, "\
"sentry-foo=bar, "\
"other-vendor-value-2=foo;bar;"
end
describe "#dynamic_sampling_context" do
context "when malformed baggage" do
it "is empty" do
baggage = described_class.from_baggage_string(malformed_baggage)
expect(baggage.dynamic_sampling_context).to eq({})
end
end
context "when only third party baggage" do
it "is empty" do
baggage = described_class.from_baggage_string(third_party_baggage)
expect(baggage.dynamic_sampling_context).to eq({})
end
end
context "when mixed baggage" do
it "populates DSC" do
baggage = described_class.from_baggage_string(mixed_baggage)
expect(baggage.dynamic_sampling_context).to eq({
"sample_rate" => "0.01337",
"public_key" => "49d0f7386ad645858ae85020e393bef3",
"trace_id" => "771a43a4192642f0b136d5159a501700",
"user_id" => "Amélie",
"foo" => "bar"
})
end
end
end
describe "#serialize" do
context "default args (without third party)" do
context "when malformed baggage" do
it "is empty string" do
baggage = described_class.from_baggage_string(malformed_baggage)
expect(baggage.serialize).to eq("")
end
end
context "when only third party baggage" do
it "is empty" do
baggage = described_class.from_baggage_string(third_party_baggage)
expect(baggage.serialize).to eq("")
end
end
context "when mixed baggage" do
it "populates DSC" do
baggage = described_class.from_baggage_string(mixed_baggage)
expect(baggage.serialize).to eq(
"sentry-trace_id=771a43a4192642f0b136d5159a501700,"\
"sentry-public_key=49d0f7386ad645858ae85020e393bef3,"\
"sentry-sample_rate=0.01337,"\
"sentry-user_id=Am%C3%A9lie,"\
"sentry-foo=bar"
)
end
end
end
end
describe "#mutable" do
context "when only third party baggage" do
it "is mutable" do
baggage = described_class.from_baggage_string(third_party_baggage)
expect(baggage.mutable).to eq(true)
end
end
context "when has sentry baggage" do
it "is immutable" do
baggage = described_class.from_baggage_string(mixed_baggage)
expect(baggage.mutable).to eq(false)
end
end
end
describe "#freeze!" do
it "makes it immutable" do
baggage = described_class.from_baggage_string(third_party_baggage)
expect(baggage.mutable).to eq(true)
baggage.freeze!
expect(baggage.mutable).to eq(false)
end
end
end