Skip to content

Commit c0dd6df

Browse files
authored
Move http query to span data (#2039)
1 parent 32375a8 commit c0dd6df

File tree

4 files changed

+39
-13
lines changed

4 files changed

+39
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Unreleased
2+
3+
### Features
4+
5+
- Move `http.query` to span data in net/http integration [#2039](https://github.com/getsentry/sentry-ruby/pull/2039)
6+
17
## 5.9.0
28

39
### Features

sentry-ruby/lib/sentry/net/http.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ def request(req, body = nil, &block)
3838
if sentry_span
3939
request_info = extract_request_info(req)
4040
sentry_span.set_description("#{request_info[:method]} #{request_info[:url]}")
41-
sentry_span.set_data(:status, res.code.to_i)
41+
sentry_span.set_data('url', request_info[:url])
42+
sentry_span.set_data('http.method', request_info[:method])
43+
sentry_span.set_data('http.query', request_info[:query]) if request_info[:query]
44+
sentry_span.set_data('status', res.code.to_i)
4245
end
4346
end
4447
end
@@ -87,7 +90,7 @@ def extract_request_info(req)
8790
result = { method: req.method, url: url }
8891

8992
if Sentry.configuration.send_default_pii
90-
result[:url] = result[:url] + "?#{uri.query}"
93+
result[:query] = uri.query
9194
result[:body] = req.body
9295
end
9396

sentry-ruby/spec/sentry/breadcrumb/http_logger_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
expect(response.code).to eq("200")
3333
crumb = Sentry.get_current_scope.breadcrumbs.peek
3434
expect(crumb.category).to eq("net.http")
35-
expect(crumb.data).to eq({ status: 200, method: "GET", url: "http://example.com/path?foo=bar", body: nil })
35+
expect(crumb.data).to eq({ status: 200, method: "GET", url: "http://example.com/path", query: "foo=bar", body: nil })
3636

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

4646
request = Net::HTTP::Post.new("/path?foo=bar")
4747
request.body = 'quz=qux'
@@ -51,7 +51,7 @@
5151
crumb = Sentry.get_current_scope.breadcrumbs.peek
5252
expect(crumb.category).to eq("net.http")
5353
expect(crumb.data).to eq(
54-
{ status: 200, method: "POST", url: "http://example.com/path?foo=bar", body: 'quz=qux' }
54+
{ status: 200, method: "POST", url: "http://example.com/path", query: "foo=bar", body: 'quz=qux' }
5555
)
5656
end
5757
end

sentry-ruby/spec/sentry/net/http_spec.rb

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
Sentry.configuration.send_default_pii = true
2626
end
2727

28-
it "records the request's span with query string" do
28+
it "records the request's span with query string in data" do
2929
stub_normal_response
3030

3131
transaction = Sentry.start_transaction
@@ -41,17 +41,22 @@
4141
expect(request_span.start_timestamp).not_to be_nil
4242
expect(request_span.timestamp).not_to be_nil
4343
expect(request_span.start_timestamp).not_to eq(request_span.timestamp)
44-
expect(request_span.description).to eq("GET http://example.com/path?foo=bar")
45-
expect(request_span.data).to eq({ status: 200 })
44+
expect(request_span.description).to eq("GET http://example.com/path")
45+
expect(request_span.data).to eq({
46+
"status" => 200,
47+
"url" => "http://example.com/path",
48+
"http.method" => "GET",
49+
"http.query" => "foo=bar"
50+
})
4651
end
4752
end
4853

49-
context "with config.send_default_pii = true" do
54+
context "with config.send_default_pii = false" do
5055
before do
5156
Sentry.configuration.send_default_pii = false
5257
end
5358

54-
it "records the request's span with query string" do
59+
it "records the request's span without query string" do
5560
stub_normal_response
5661

5762
transaction = Sentry.start_transaction
@@ -68,7 +73,11 @@
6873
expect(request_span.timestamp).not_to be_nil
6974
expect(request_span.start_timestamp).not_to eq(request_span.timestamp)
7075
expect(request_span.description).to eq("GET http://example.com/path")
71-
expect(request_span.data).to eq({ status: 200 })
76+
expect(request_span.data).to eq({
77+
"status" => 200,
78+
"url" => "http://example.com/path",
79+
"http.method" => "GET",
80+
})
7281
end
7382
end
7483

@@ -237,15 +246,23 @@ def verify_spans(transaction)
237246
expect(request_span.timestamp).not_to be_nil
238247
expect(request_span.start_timestamp).not_to eq(request_span.timestamp)
239248
expect(request_span.description).to eq("GET http://example.com/path")
240-
expect(request_span.data).to eq({ status: 200 })
249+
expect(request_span.data).to eq({
250+
"status" => 200,
251+
"url" => "http://example.com/path",
252+
"http.method" => "GET",
253+
})
241254

242255
request_span = transaction.span_recorder.spans[2]
243256
expect(request_span.op).to eq("http.client")
244257
expect(request_span.start_timestamp).not_to be_nil
245258
expect(request_span.timestamp).not_to be_nil
246259
expect(request_span.start_timestamp).not_to eq(request_span.timestamp)
247260
expect(request_span.description).to eq("GET http://example.com/path")
248-
expect(request_span.data).to eq({ status: 404 })
261+
expect(request_span.data).to eq({
262+
"status" => 404,
263+
"url" => "http://example.com/path",
264+
"http.method" => "GET",
265+
})
249266
end
250267

251268
it "doesn't mess different requests' data together" do

0 commit comments

Comments
 (0)