sentry-ruby-core 4.8.3 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'faraday'
4
- require 'zlib'
3
+ require "net/http"
4
+ require "zlib"
5
5
 
6
6
  module Sentry
7
7
  class HTTPTransport < Transport
@@ -12,12 +12,12 @@ module Sentry
12
12
  DEFAULT_DELAY = 60
13
13
  RETRY_AFTER_HEADER = "retry-after"
14
14
  RATE_LIMIT_HEADER = "x-sentry-rate-limits"
15
+ USER_AGENT = "sentry-ruby/#{Sentry::VERSION}"
15
16
 
16
- attr_reader :conn, :adapter
17
+ attr_reader :conn
17
18
 
18
19
  def initialize(*args)
19
20
  super
20
- @adapter = @transport_configuration.http_adapter || Faraday.default_adapter
21
21
  @conn = set_conn
22
22
  @endpoint = @dsn.envelope_endpoint
23
23
  end
@@ -30,29 +30,37 @@ module Sentry
30
30
  encoding = GZIP_ENCODING
31
31
  end
32
32
 
33
- response = conn.post @endpoint do |req|
34
- req.headers['Content-Type'] = CONTENT_TYPE
35
- req.headers['Content-Encoding'] = encoding
36
- req.headers['X-Sentry-Auth'] = generate_auth_header
37
- req.body = data
33
+ headers = {
34
+ 'Content-Type' => CONTENT_TYPE,
35
+ 'Content-Encoding' => encoding,
36
+ 'X-Sentry-Auth' => generate_auth_header,
37
+ 'User-Agent' => USER_AGENT
38
+ }
39
+
40
+ response = conn.start do |http|
41
+ request = ::Net::HTTP::Post.new(@endpoint, headers)
42
+ request.body = data
43
+ http.request(request)
38
44
  end
39
45
 
40
- if has_rate_limited_header?(response.headers)
41
- handle_rate_limited_response(response.headers)
42
- end
43
- rescue Faraday::Error => e
44
- error_info = e.message
46
+ if response.code.match?(/\A2\d{2}/)
47
+ if has_rate_limited_header?(response)
48
+ handle_rate_limited_response(response)
49
+ end
50
+ else
51
+ error_info = "the server responded with status #{response.code}"
45
52
 
46
- if e.response
47
- if e.response[:status] == 429
48
- handle_rate_limited_response(e.response[:headers])
53
+ if response.code == "429"
54
+ handle_rate_limited_response(response)
49
55
  else
50
- error_info += "\nbody: #{e.response[:body]}"
51
- error_info += " Error in headers is: #{e.response[:headers]['x-sentry-error']}" if e.response[:headers]['x-sentry-error']
56
+ error_info += "\nbody: #{response.body}"
57
+ error_info += " Error in headers is: #{response['x-sentry-error']}" if response['x-sentry-error']
52
58
  end
53
- end
54
59
 
55
- raise Sentry::ExternalError, error_info
60
+ raise Sentry::ExternalError, error_info
61
+ end
62
+ rescue SocketError => e
63
+ raise Sentry::ExternalError.new(e.message)
56
64
  end
57
65
 
58
66
  private
@@ -120,31 +128,40 @@ module Sentry
120
128
  end
121
129
 
122
130
  def set_conn
123
- server = @dsn.server
131
+ server = URI(@dsn.server)
124
132
 
125
133
  log_debug("Sentry HTTP Transport connecting to #{server}")
126
134
 
127
- Faraday.new(server, :ssl => ssl_configuration, :proxy => @transport_configuration.proxy) do |builder|
128
- @transport_configuration.faraday_builder&.call(builder)
129
- builder.response :raise_error
130
- builder.options.merge! faraday_opts
131
- builder.headers[:user_agent] = "sentry-ruby/#{Sentry::VERSION}"
132
- builder.adapter(*adapter)
133
- end
134
- end
135
+ use_ssl = server.scheme == "https"
136
+ port = use_ssl ? 443 : 80
135
137
 
136
- # TODO: deprecate and replace where possible w/Faraday Builder
137
- def faraday_opts
138
- [:timeout, :open_timeout].each_with_object({}) do |opt, memo|
139
- memo[opt] = @transport_configuration.public_send(opt) if @transport_configuration.public_send(opt)
138
+ connection =
139
+ if proxy = @transport_configuration.proxy
140
+ ::Net::HTTP.new(server.hostname, port, proxy[:uri].hostname, proxy[:uri].port, proxy[:user], proxy[:password])
141
+ else
142
+ ::Net::HTTP.new(server.hostname, port, nil)
143
+ end
144
+
145
+ connection.use_ssl = use_ssl
146
+ connection.read_timeout = @transport_configuration.timeout
147
+ connection.write_timeout = @transport_configuration.timeout if connection.respond_to?(:write_timeout)
148
+ connection.open_timeout = @transport_configuration.open_timeout
149
+
150
+ ssl_configuration.each do |key, value|
151
+ connection.send("#{key}=", value)
140
152
  end
153
+
154
+ connection
141
155
  end
142
156
 
143
157
  def ssl_configuration
144
- {
158
+ configuration = {
145
159
  verify: @transport_configuration.ssl_verification,
146
160
  ca_file: @transport_configuration.ssl_ca_file
147
161
  }.merge(@transport_configuration.ssl || {})
162
+
163
+ configuration[:verify_mode] = configuration.delete(:verify) ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
164
+ configuration
148
165
  end
149
166
  end
150
167
  end
@@ -23,7 +23,10 @@ module Sentry
23
23
 
24
24
  include LoggingHelper
25
25
 
26
- attr_reader :logger, :rate_limits, :discarded_events, :last_client_report_sent
26
+ attr_reader :rate_limits, :discarded_events, :last_client_report_sent
27
+
28
+ # @deprecated Use Sentry.logger to retrieve the current logger instead.
29
+ attr_reader :logger
27
30
 
28
31
  def initialize(configuration)
29
32
  @logger = configuration.logger
@@ -6,21 +6,21 @@ module Sentry
6
6
  message = "#{message}: #{exception.message}"
7
7
  message += "\n#{exception.backtrace.join("\n")}" if debug
8
8
 
9
- logger.error(LOGGER_PROGNAME) do
9
+ @logger.error(LOGGER_PROGNAME) do
10
10
  message
11
11
  end
12
12
  end
13
13
 
14
14
  def log_info(message)
15
- logger.info(LOGGER_PROGNAME) { message }
15
+ @logger.info(LOGGER_PROGNAME) { message }
16
16
  end
17
17
 
18
18
  def log_debug(message)
19
- logger.debug(LOGGER_PROGNAME) { message }
19
+ @logger.debug(LOGGER_PROGNAME) { message }
20
20
  end
21
21
 
22
22
  def log_warn(message)
23
- logger.warn(LOGGER_PROGNAME) { message }
23
+ @logger.warn(LOGGER_PROGNAME) { message }
24
24
  end
25
25
  end
26
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sentry
4
- VERSION = "4.8.3"
4
+ VERSION = "5.0.0"
5
5
  end
data/lib/sentry-ruby.rb CHANGED
@@ -18,7 +18,6 @@ require "sentry/transaction"
18
18
  require "sentry/hub"
19
19
  require "sentry/background_worker"
20
20
 
21
-
22
21
  [
23
22
  "sentry/rake",
24
23
  "sentry/rack",
@@ -101,7 +100,47 @@ module Sentry
101
100
 
102
101
  extend Forwardable
103
102
 
103
+ # @!macro [new] configuration
104
+ # The Configuration object that's used for configuring the client and its transport.
105
+ # @return [Configuration]
106
+ # @!macro [new] send_event
107
+ # Sends the event to Sentry.
108
+ # @param event [Event] the event to be sent.
109
+ # @param hint [Hash] the hint data that'll be passed to `before_send` callback.
110
+ # @return [Event]
111
+
112
+ # @!method configuration
113
+ # @!macro configuration
114
+ # @!method send_event
115
+ # @!macro send_event
104
116
  def_delegators :get_current_client, :configuration, :send_event
117
+
118
+ # @!macro [new] set_extras
119
+ # Updates the scope's extras attribute by merging with the old value.
120
+ # @param extras [Hash]
121
+ # @return [Hash]
122
+ # @!macro [new] set_user
123
+ # Sets the scope's user attribute.
124
+ # @param user [Hash]
125
+ # @return [Hash]
126
+ # @!macro [new] set_context
127
+ # Adds a new key-value pair to current contexts.
128
+ # @param key [String, Symbol]
129
+ # @param value [Object]
130
+ # @return [Hash]
131
+ # @!macro [new] set_tags
132
+ # Updates the scope's tags attribute by merging with the old value.
133
+ # @param tags [Hash]
134
+ # @return [Hash]
135
+
136
+ # @!method set_tags
137
+ # @!macro set_tags
138
+ # @!method set_extras
139
+ # @!macro set_extras
140
+ # @!method set_user
141
+ # @!macro set_user
142
+ # @!method set_context
143
+ # @!macro set_context
105
144
  def_delegators :get_current_scope, :set_tags, :set_extras, :set_user, :set_context
106
145
 
107
146
  ##### Main APIs #####
@@ -135,7 +174,7 @@ module Sentry
135
174
  #
136
175
  # @return [Boolean]
137
176
  def initialized?
138
- !!@main_hub
177
+ !!get_main_hub
139
178
  end
140
179
 
141
180
  # Returns an uri for security policy reporting that's generated from the given DSN
@@ -22,6 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_dependency "faraday"
26
25
  spec.add_dependency "concurrent-ruby"
27
26
  end
data/sentry-ruby.gemspec CHANGED
@@ -18,6 +18,5 @@ Gem::Specification.new do |spec|
18
18
  spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
19
19
 
20
20
  spec.add_dependency "sentry-ruby-core", Sentry::VERSION
21
- spec.add_dependency "faraday", "~> 1.0"
22
21
  spec.add_dependency "concurrent-ruby", '~> 1.0', '>= 1.0.2'
23
22
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-ruby-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.8.3
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-05 00:00:00.000000000 Z
11
+ date: 2022-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: faraday
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: concurrent-ruby
29
15
  requirement: !ruby/object:Gem::Requirement