Skip to content

Commit 8245da4

Browse files
committed
Refine a couple of specs
1 parent fcea85e commit 8245da4

File tree

1 file changed

+13
-34
lines changed

1 file changed

+13
-34
lines changed

sentry-ruby/spec/sentry/transactions/trace_propagation_spec.rb

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,30 @@
6161
end
6262

6363
it "handles missing sample_rand gracefully" do
64-
sentry_trace = "771a43a4192642f0b136d5159a501700-7c51afd529da4a2a-1"
65-
baggage_header = "sentry-trace_id=771a43a4192642f0b136d5159a501700,sentry-sample_rate=0.25"
64+
sentry_trace = "771a43a4192642f0b136d5159a501700-7c51afd529da4a2a"
65+
baggage_header = "sentry-trace_id=#{sentry_trace},sentry-sample_rate=0.25"
6666

67+
expected_sample_rand = Sentry::Utils::SampleRand.new(trace_id: "771a43a4192642f0b136d5159a501700").generate_from_trace_id
6768
transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, baggage: baggage_header)
6869

69-
expect(transaction).not_to be_nil
70+
expect(transaction.sample_rand).to eql(expected_sample_rand)
71+
expect(transaction.baggage.items["sample_rate"]).to eql("0.25")
72+
end
7073

71-
generator = Sentry::Utils::SampleRand.new(trace_id: "771a43a4192642f0b136d5159a501700")
72-
expected_sample_rand = generator.generate_from_sampling_decision(true, 0.25)
74+
it "handles invalid sample_rand in baggage" do
75+
sentry_trace = "771a43a4192642f0b136d5159a501700-7c51afd529da4a2a-1"
76+
baggage_header = "sentry-trace_id=771a43a4192642f0b136d5159a501700,sentry-sample_rand=1.5"
7377

74-
expect(expected_sample_rand).to be >= 0.0
75-
expect(expected_sample_rand).to be < 1.0
76-
expect(expected_sample_rand).to be < 0.25
78+
expected_sample_rand = Sentry::Utils::SampleRand.new(trace_id: "771a43a4192642f0b136d5159a501700").generate_from_trace_id
79+
transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, baggage: baggage_header)
7780

78-
generator2 = Sentry::Utils::SampleRand.new(trace_id: "771a43a4192642f0b136d5159a501700")
79-
expected_sample_rand2 = generator2.generate_from_sampling_decision(true, 0.25)
80-
expect(expected_sample_rand2).to eq(expected_sample_rand)
81+
expect(transaction.sample_rand).to eq(expected_sample_rand)
8182

8283
baggage = transaction.get_baggage
8384

8485
expect(baggage.items).to eq({
8586
"trace_id" => "771a43a4192642f0b136d5159a501700",
86-
"sample_rate" => "0.25"
87+
"sample_rand" => "1.5"
8788
})
8889
end
8990

@@ -152,27 +153,5 @@
152153

153154
expect(transaction_baggage.items["sample_rand"]).to eq("0.600000")
154155
end
155-
156-
it "handles invalid sample_rand in baggage" do
157-
sentry_trace = "771a43a4192642f0b136d5159a501700-7c51afd529da4a2a-1"
158-
baggage_header = "sentry-trace_id=771a43a4192642f0b136d5159a501700,sentry-sample_rand=1.5"
159-
160-
transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, baggage: baggage_header)
161-
162-
expect(transaction).not_to be_nil
163-
164-
generator = Sentry::Utils::SampleRand.new(trace_id: "771a43a4192642f0b136d5159a501700")
165-
expected_sample_rand = generator.generate_from_trace_id
166-
167-
expect(expected_sample_rand).to be >= 0.0
168-
expect(expected_sample_rand).to be < 1.0
169-
170-
baggage = transaction.get_baggage
171-
172-
expect(baggage.items).to eq({
173-
"trace_id" => "771a43a4192642f0b136d5159a501700",
174-
"sample_rand" => "1.5"
175-
})
176-
end
177156
end
178157
end

0 commit comments

Comments
 (0)