From 2795b9aafbfe362f030d394de17e6edc4f3589fc Mon Sep 17 00:00:00 2001 From: ojab Date: Fri, 10 Dec 2021 12:37:40 +0000 Subject: [PATCH] Add spec for `Net::HTTP` span description with `send_default_pii = false` --- sentry-ruby/spec/sentry/net/http_spec.rb | 60 ++++++++++++++++++------ 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/sentry-ruby/spec/sentry/net/http_spec.rb b/sentry-ruby/spec/sentry/net/http_spec.rb index 3695ac6c2..f5acff321 100644 --- a/sentry-ruby/spec/sentry/net/http_spec.rb +++ b/sentry-ruby/spec/sentry/net/http_spec.rb @@ -143,24 +143,56 @@ def stub_normal_response(code: "200") end end - it "records the request's span" do - stub_normal_response + context "with config.send_default_pii = true" do + before do + Sentry.configuration.send_default_pii = true + end - transaction = Sentry.start_transaction - Sentry.get_current_scope.set_span(transaction) + it "records the request's span with query string" do + stub_normal_response - response = Net::HTTP.get_response(URI("http://example.com/path")) + transaction = Sentry.start_transaction + Sentry.get_current_scope.set_span(transaction) - expect(response.code).to eq("200") - expect(transaction.span_recorder.spans.count).to eq(2) + response = Net::HTTP.get_response(URI("http://example.com/path?foo=bar")) - request_span = transaction.span_recorder.spans.last - expect(request_span.op).to eq("net.http") - expect(request_span.start_timestamp).not_to be_nil - expect(request_span.timestamp).not_to be_nil - expect(request_span.start_timestamp).not_to eq(request_span.timestamp) - expect(request_span.description).to eq("GET http://example.com/path") - expect(request_span.data).to eq({ status: 200 }) + expect(response.code).to eq("200") + expect(transaction.span_recorder.spans.count).to eq(2) + + request_span = transaction.span_recorder.spans.last + expect(request_span.op).to eq("net.http") + expect(request_span.start_timestamp).not_to be_nil + expect(request_span.timestamp).not_to be_nil + expect(request_span.start_timestamp).not_to eq(request_span.timestamp) + expect(request_span.description).to eq("GET http://example.com/path?foo=bar") + expect(request_span.data).to eq({ status: 200 }) + end + end + + context "with config.send_default_pii = true" do + before do + Sentry.configuration.send_default_pii = false + end + + it "records the request's span with query string" do + stub_normal_response + + transaction = Sentry.start_transaction + Sentry.get_current_scope.set_span(transaction) + + response = Net::HTTP.get_response(URI("http://example.com/path?foo=bar")) + + expect(response.code).to eq("200") + expect(transaction.span_recorder.spans.count).to eq(2) + + request_span = transaction.span_recorder.spans.last + expect(request_span.op).to eq("net.http") + expect(request_span.start_timestamp).not_to be_nil + expect(request_span.timestamp).not_to be_nil + expect(request_span.start_timestamp).not_to eq(request_span.timestamp) + expect(request_span.description).to eq("GET http://example.com/path") + expect(request_span.data).to eq({ status: 200 }) + end end it "adds sentry-trace header to the request header" do