Skip to content

Commit

Permalink
Specs
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Jul 31, 2023
1 parent 12befb7 commit a485c78
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
```rb
# takes an array of strings or regexps
config.trace_propagation_targets = [/.*/] # default is to all targets
config.trace_propagation_targets = [/example.com/, 'foobar.org']
config.trace_propagation_targets = [/example.com/, 'foobar.org/api/v2']
```

## 5.10.0
Expand Down
4 changes: 2 additions & 2 deletions sentry-ruby/lib/sentry/net/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def request(req, body = nil, &block)
set_sentry_trace_header(req, sentry_span, request_info)

Check warning on line 34 in sentry-ruby/lib/sentry/net/http.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/net/http.rb#L33-L34

Added lines #L33 - L34 were not covered by tests

super.tap do |res|
record_sentry_breadcrumb(req, res, request_info)
record_sentry_breadcrumb(request_info, res)

Check warning on line 37 in sentry-ruby/lib/sentry/net/http.rb

View check run for this annotation

Codecov / codecov/patch

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

Added line #L37 was not covered by tests

if sentry_span
sentry_span.set_description("#{request_info[:method]} #{request_info[:url]}")
Expand Down Expand Up @@ -63,7 +63,7 @@ def set_sentry_trace_header(req, sentry_span, request_info)
req[BAGGAGE_HEADER_NAME] = baggage if baggage && !baggage.empty?
end

def record_sentry_breadcrumb(req, res, request_info)
def record_sentry_breadcrumb(request_info, res)
return unless Sentry.initialized? && Sentry.configuration.breadcrumbs_logger.include?(:http_logger)

crumb = Sentry::Breadcrumb.new(
Expand Down
11 changes: 11 additions & 0 deletions sentry-ruby/spec/sentry/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,17 @@ class SentryConfigurationSample < Sentry::Configuration
end
end

describe "#trace_propagation_targets" do
it "returns match all by default" do
expect(subject.trace_propagation_targets).to eq([/.*/])
end

it "accepts array of strings or regexps" do
subject.trace_propagation_targets = ["example.com", /foobar.org\/api\/v2/]
expect(subject.trace_propagation_targets).to eq(["example.com", /foobar.org\/api\/v2/])
end
end

describe "#instrumenter" do
it "returns :sentry by default" do
expect(subject.instrumenter).to eq(:sentry)
Expand Down
70 changes: 70 additions & 0 deletions sentry-ruby/spec/sentry/net/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,76 @@
end
end

context "with custom trace_propagation_targets" do
before do
Sentry.configuration.trace_propagation_targets = ["example.com", /foobar.org\/api\/v2/]
end

it "doesn't add sentry headers to outgoing requests to different target" do
stub_normal_response

uri = URI("http://google.com/path")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)

transaction = Sentry.start_transaction
Sentry.get_current_scope.set_span(transaction)

http.request(request)

expect(request.key?("sentry-trace")).to eq(false)
expect(request.key?("baggage")).to eq(false)
end

it "doesn't add sentry headers to outgoing requests to different target path" do
stub_normal_response

uri = URI("http://foobar.org/api/v1/path")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)

transaction = Sentry.start_transaction
Sentry.get_current_scope.set_span(transaction)

http.request(request)

expect(request.key?("sentry-trace")).to eq(false)
expect(request.key?("baggage")).to eq(false)
end

it "adds sentry headers to outgoing requests matching string" do
stub_normal_response

uri = URI("http://example.com/path")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)

transaction = Sentry.start_transaction
Sentry.get_current_scope.set_span(transaction)

http.request(request)

expect(request.key?("sentry-trace")).to eq(true)
expect(request.key?("baggage")).to eq(true)
end

it "adds sentry headers to outgoing requests matching regexp" do
stub_normal_response

uri = URI("http://foobar.org/api/v2/path")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)

transaction = Sentry.start_transaction
Sentry.get_current_scope.set_span(transaction)

http.request(request)

expect(request.key?("sentry-trace")).to eq(true)
expect(request.key?("baggage")).to eq(true)
end
end

it "doesn't record span for the SDK's request" do
stub_sentry_response

Expand Down

0 comments on commit a485c78

Please sign in to comment.