Skip to content

Commit

Permalink
Don't reuse Net::HTTP objects in HTTPTransport (#1696)
Browse files Browse the repository at this point in the history
* Don't reused Net::HTTP objects

* Update changelog
  • Loading branch information
st0012 authored Jan 23, 2022
1 parent ee1cf06 commit c2f9e06
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.0.1

- Don't reuse Net::HTTP objects in `HTTPTransport` [#1696](https://github.com/getsentry/sentry-ruby/pull/1696)

## 5.0.0

### Breaking Change - Goodbye `faraday` 👋
Expand Down
9 changes: 3 additions & 6 deletions sentry-ruby/lib/sentry/transport/http_transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ class HTTPTransport < Transport
RATE_LIMIT_HEADER = "x-sentry-rate-limits"
USER_AGENT = "sentry-ruby/#{Sentry::VERSION}"

attr_reader :conn

def initialize(*args)
super
@conn = set_conn
@endpoint = @dsn.envelope_endpoint

log_debug("Sentry HTTP Transport will connect to #{@dsn.server}")
end

def send_data(data)
Expand Down Expand Up @@ -127,11 +126,9 @@ def should_compress?(data)
@transport_configuration.encoding == GZIP_ENCODING && data.bytesize >= GZIP_THRESHOLD
end

def set_conn
def conn
server = URI(@dsn.server)

log_debug("Sentry HTTP Transport connecting to #{server}")

use_ssl = server.scheme == "https"
port = use_ssl ? 443 : 80

Expand Down
27 changes: 24 additions & 3 deletions sentry-ruby/spec/sentry/transport/http_transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,36 @@
subject.encode(event.to_hash)
end

subject { described_class.new(configuration) }
subject { client.transport }

it "logs a debug message during initialization" do
it "logs a debug message only during initialization" do
stub_request(build_fake_response("200"))
string_io = StringIO.new
configuration.logger = Logger.new(string_io)

subject

expect(string_io.string).to include("sentry: Sentry HTTP Transport connecting to http://sentry.localdomain")
expect(string_io.string).to include("sentry: Sentry HTTP Transport will connect to http://sentry.localdomain")

string_io.string = ""
expect(string_io.string).to eq("")

subject.send_data(data)

expect(string_io.string).not_to include("sentry: Sentry HTTP Transport will connect to http://sentry.localdomain")
end

it "initializes new Net::HTTP instance for every request" do
stub_request(build_fake_response("200")) do |request|
expect(request["User-Agent"]).to eq("sentry-ruby/#{Sentry::VERSION}")
end

subject

expect(Net::HTTP).to receive(:new).and_call_original.exactly(2)

subject.send_data(data)
subject.send_data(data)
end

describe "customizations" do
Expand Down

0 comments on commit c2f9e06

Please sign in to comment.