From b54705b3b69ceec4cd15f51a941a0b9b980e235e Mon Sep 17 00:00:00 2001 From: Neel Shah Date: Thu, 27 Jul 2023 15:52:45 +0200 Subject: [PATCH] Specs --- CHANGELOG.md | 2 +- sentry-ruby/spec/sentry/configuration_spec.rb | 11 +++ sentry-ruby/spec/sentry/net/http_spec.rb | 70 +++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc9fa589b..7cb52ec0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/sentry-ruby/spec/sentry/configuration_spec.rb b/sentry-ruby/spec/sentry/configuration_spec.rb index ac49db207..6cd571600 100644 --- a/sentry-ruby/spec/sentry/configuration_spec.rb +++ b/sentry-ruby/spec/sentry/configuration_spec.rb @@ -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) diff --git a/sentry-ruby/spec/sentry/net/http_spec.rb b/sentry-ruby/spec/sentry/net/http_spec.rb index 35279ad81..dc4605ffc 100644 --- a/sentry-ruby/spec/sentry/net/http_spec.rb +++ b/sentry-ruby/spec/sentry/net/http_spec.rb @@ -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