Skip to content

Commit

Permalink
Move http query to span data (#2039)
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py authored May 15, 2023
1 parent 32375a8 commit c0dd6df
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

### Features

- Move `http.query` to span data in net/http integration [#2039](https://github.com/getsentry/sentry-ruby/pull/2039)

## 5.9.0

### Features
Expand Down
7 changes: 5 additions & 2 deletions sentry-ruby/lib/sentry/net/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def request(req, body = nil, &block)
if sentry_span
request_info = extract_request_info(req)
sentry_span.set_description("#{request_info[:method]} #{request_info[:url]}")
sentry_span.set_data(:status, res.code.to_i)
sentry_span.set_data('url', request_info[:url])
sentry_span.set_data('http.method', request_info[:method])
sentry_span.set_data('http.query', request_info[:query]) if request_info[:query]
sentry_span.set_data('status', res.code.to_i)
end
end
end
Expand Down Expand Up @@ -87,7 +90,7 @@ def extract_request_info(req)
result = { method: req.method, url: url }

if Sentry.configuration.send_default_pii
result[:url] = result[:url] + "?#{uri.query}"
result[:query] = uri.query
result[:body] = req.body
end

Expand Down
6 changes: 3 additions & 3 deletions sentry-ruby/spec/sentry/breadcrumb/http_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
expect(response.code).to eq("200")
crumb = Sentry.get_current_scope.breadcrumbs.peek
expect(crumb.category).to eq("net.http")
expect(crumb.data).to eq({ status: 200, method: "GET", url: "http://example.com/path?foo=bar", body: nil })
expect(crumb.data).to eq({ status: 200, method: "GET", url: "http://example.com/path", query: "foo=bar", body: nil })

http = Net::HTTP.new("example.com")
request = Net::HTTP::Get.new("/path?foo=bar")
Expand All @@ -41,7 +41,7 @@
expect(response.code).to eq("200")
crumb = Sentry.get_current_scope.breadcrumbs.peek
expect(crumb.category).to eq("net.http")
expect(crumb.data).to eq({ status: 200, method: "GET", url: "http://example.com/path?foo=bar", body: nil })
expect(crumb.data).to eq({ status: 200, method: "GET", url: "http://example.com/path", query: "foo=bar", body: nil })

request = Net::HTTP::Post.new("/path?foo=bar")
request.body = 'quz=qux'
Expand All @@ -51,7 +51,7 @@
crumb = Sentry.get_current_scope.breadcrumbs.peek
expect(crumb.category).to eq("net.http")
expect(crumb.data).to eq(
{ status: 200, method: "POST", url: "http://example.com/path?foo=bar", body: 'quz=qux' }
{ status: 200, method: "POST", url: "http://example.com/path", query: "foo=bar", body: 'quz=qux' }
)
end
end
Expand Down
33 changes: 25 additions & 8 deletions sentry-ruby/spec/sentry/net/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
Sentry.configuration.send_default_pii = true
end

it "records the request's span with query string" do
it "records the request's span with query string in data" do
stub_normal_response

transaction = Sentry.start_transaction
Expand All @@ -41,17 +41,22 @@
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 })
expect(request_span.description).to eq("GET http://example.com/path")
expect(request_span.data).to eq({
"status" => 200,
"url" => "http://example.com/path",
"http.method" => "GET",
"http.query" => "foo=bar"
})
end
end

context "with config.send_default_pii = true" do
context "with config.send_default_pii = false" do
before do
Sentry.configuration.send_default_pii = false
end

it "records the request's span with query string" do
it "records the request's span without query string" do
stub_normal_response

transaction = Sentry.start_transaction
Expand All @@ -68,7 +73,11 @@
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(request_span.data).to eq({
"status" => 200,
"url" => "http://example.com/path",
"http.method" => "GET",
})
end
end

Expand Down Expand Up @@ -237,15 +246,23 @@ def verify_spans(transaction)
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(request_span.data).to eq({
"status" => 200,
"url" => "http://example.com/path",
"http.method" => "GET",
})

request_span = transaction.span_recorder.spans[2]
expect(request_span.op).to eq("http.client")
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: 404 })
expect(request_span.data).to eq({
"status" => 404,
"url" => "http://example.com/path",
"http.method" => "GET",
})
end

it "doesn't mess different requests' data together" do
Expand Down

0 comments on commit c0dd6df

Please sign in to comment.