|
192 | 192 | ) |
193 | 193 | end |
194 | 194 |
|
| 195 | + it "merges baggage header with pre-existing baggage on the request" do |
| 196 | + stub_normal_response |
| 197 | + |
| 198 | + uri = URI("http://example.com/path") |
| 199 | + http = Net::HTTP.new(uri.host, uri.port) |
| 200 | + request = Net::HTTP::Get.new(uri.request_uri) |
| 201 | + request["baggage"] = "routingKey=myvalue,tenantId=123" |
| 202 | + |
| 203 | + transaction = Sentry.start_transaction |
| 204 | + Sentry.get_current_scope.set_span(transaction) |
| 205 | + |
| 206 | + response = http.request(request) |
| 207 | + |
| 208 | + expect(response.code).to eq("200") |
| 209 | + request_span = transaction.span_recorder.spans.last |
| 210 | + sentry_baggage = request_span.to_baggage |
| 211 | + |
| 212 | + expect(request["baggage"]).to include(sentry_baggage) |
| 213 | + expect(request["baggage"]).to include("routingKey=myvalue,tenantId=123") |
| 214 | + expect(request["baggage"]).to eq("#{sentry_baggage},routingKey=myvalue,tenantId=123") |
| 215 | + end |
| 216 | + |
| 217 | + it "sets baggage header normally when no pre-existing baggage on the request" do |
| 218 | + stub_normal_response |
| 219 | + |
| 220 | + uri = URI("http://example.com/path") |
| 221 | + http = Net::HTTP.new(uri.host, uri.port) |
| 222 | + request = Net::HTTP::Get.new(uri.request_uri) |
| 223 | + |
| 224 | + transaction = Sentry.start_transaction |
| 225 | + Sentry.get_current_scope.set_span(transaction) |
| 226 | + |
| 227 | + response = http.request(request) |
| 228 | + |
| 229 | + expect(response.code).to eq("200") |
| 230 | + request_span = transaction.span_recorder.spans.last |
| 231 | + expect(request["baggage"]).to eq(request_span.to_baggage) |
| 232 | + end |
| 233 | + |
195 | 234 | context "with config.propagate_traces = false" do |
196 | 235 | before do |
197 | 236 | Sentry.configuration.propagate_traces = false |
|
0 commit comments