|
61 | 61 | end |
62 | 62 |
|
63 | 63 | 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" |
66 | 66 |
|
| 67 | + expected_sample_rand = Sentry::Utils::SampleRand.new(trace_id: "771a43a4192642f0b136d5159a501700").generate_from_trace_id |
67 | 68 | transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, baggage: baggage_header) |
68 | 69 |
|
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 |
70 | 73 |
|
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" |
73 | 77 |
|
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) |
77 | 80 |
|
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) |
81 | 82 |
|
82 | 83 | baggage = transaction.get_baggage |
83 | 84 |
|
84 | 85 | expect(baggage.items).to eq({ |
85 | 86 | "trace_id" => "771a43a4192642f0b136d5159a501700", |
86 | | - "sample_rate" => "0.25" |
| 87 | + "sample_rand" => "1.5" |
87 | 88 | }) |
88 | 89 | end |
89 | 90 |
|
|
152 | 153 |
|
153 | 154 | expect(transaction_baggage.items["sample_rand"]).to eq("0.600000") |
154 | 155 | 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 |
177 | 156 | end |
178 | 157 | end |
0 commit comments