Skip to content

Commit

Permalink
Fix early return in Faraday when Sentry is not initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Aug 2, 2024
1 parent fd0debe commit 259f223
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/faraday.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Instrumenter
include Utils::HttpTracing

def instrument(op_name, env, &block)
return unless Sentry.initialized?
return block.call unless Sentry.initialized?

Check warning on line 32 in sentry-ruby/lib/sentry/faraday.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/faraday.rb#L32

Added line #L32 was not covered by tests

Sentry.with_child_span(op: op_name, start_timestamp: Sentry.utc_now.to_f, origin: SPAN_ORIGIN) do |sentry_span|
request_info = extract_request_info(env)
Expand Down
22 changes: 22 additions & 0 deletions sentry-ruby/spec/sentry/faraday_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,26 @@
expect(transaction.span_recorder.spans.map(&:origin)).not_to include("auto.http.faraday")
end
end

context "when Sentry is not initialized" do
let(:http) do
Faraday.new(url) do |f|
f.adapter Faraday::Adapter::Test do |stub|
stub.get("/test") do
[200, { "Content-Type" => "text/html" }, "<h1>hello world</h1>"]
end
end
end
end

let(:url) { "http://example.com" }

it "skips instrumentation" do
allow(Sentry).to receive(:initialized?).and_return(false)

response = http.get("/test")

expect(response.status).to eq(200)
end
end
end

0 comments on commit 259f223

Please sign in to comment.