Skip to content

Commit

Permalink
Add spec for Net::HTTP span description with `send_default_pii = fa…
Browse files Browse the repository at this point in the history
…lse`
  • Loading branch information
ojab committed Dec 13, 2021
1 parent b2335d3 commit d183b9d
Showing 1 changed file with 46 additions and 14 deletions.
60 changes: 46 additions & 14 deletions sentry-ruby/spec/sentry/net/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,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
Expand Down

0 comments on commit d183b9d

Please sign in to comment.