sentry-ruby-core 4.9.0 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acac59016a784fe97a900098b0dbd42d74996a3193d8e8f6026da3d097593d19
4
- data.tar.gz: 2e670fbe76abfbd62e0c45e5272929a5cce1ba3ffb556afb68b50f35b4969be3
3
+ metadata.gz: 848bd1089194abb9be8a48b6c1c4c218dfba27a3555d8ae79a5ffe7d52a05569
4
+ data.tar.gz: c52711ba4c4275d35cc4ed54a0dc0936422a63e199de91c08e3e6964fb80d6d6
5
5
  SHA512:
6
- metadata.gz: 68fd8755acacba19433d948722cb02a751c61ea822360a6dcfb245a9657f197df08f11ceef800f6db06bc75b4c5e39862b8d2f2cb88c0f844718bccf2dffec77
7
- data.tar.gz: f3083e8f467ecc06c878aa568c01dfcfd4c793da989196f1397684ef0276107b2500eeb2233557e34a55ad6e7a53e9110fcfb06ccb68077cac63d1f3810ae3b4
6
+ metadata.gz: fb55681acc83a4c970fbf8dd7c6715fbef7b6d26ad0a4ca674bc463de13881887d33dd8673772e60e25c2c66b6cb1f111a6c23936b1683d74384296924bb2b33
7
+ data.tar.gz: 598c1571d00ca441b3a351dfe12c56967d3dae8e4f05b4a8f21b3e8fe16d0c94558e8dec5d211ff72aced12d5b433fb0f7f5f1b6ed522206d15847087dafd959
data/lib/sentry/client.rb CHANGED
@@ -76,8 +76,9 @@ module Sentry
76
76
  # @param hint [Hash] the hint data that'll be passed to `before_send` callback and the scope's event processors.
77
77
  # @return [Event, nil]
78
78
  def event_from_exception(exception, hint = {})
79
+ return unless @configuration.sending_allowed? && @configuration.exception_class_allowed?(exception)
80
+
79
81
  integration_meta = Sentry.integrations[hint[:integration]]
80
- return unless @configuration.exception_class_allowed?(exception)
81
82
 
82
83
  Event.new(configuration: configuration, integration_meta: integration_meta).tap do |event|
83
84
  event.add_exception_interface(exception)
@@ -90,6 +91,8 @@ module Sentry
90
91
  # @param hint [Hash] the hint data that'll be passed to `before_send` callback and the scope's event processors.
91
92
  # @return [Event]
92
93
  def event_from_message(message, hint = {}, backtrace: nil)
94
+ return unless @configuration.sending_allowed?
95
+
93
96
  integration_meta = Sentry.integrations[hint[:integration]]
94
97
  event = Event.new(configuration: configuration, integration_meta: integration_meta, message: message)
95
98
  event.add_threads_interface(backtrace: backtrace || caller)
data/lib/sentry/hub.rb CHANGED
@@ -114,6 +114,9 @@ module Sentry
114
114
  options[:hint][:message] = message
115
115
  backtrace = options.delete(:backtrace)
116
116
  event = current_client.event_from_message(message, options[:hint], backtrace: backtrace)
117
+
118
+ return unless event
119
+
117
120
  capture_event(event, **options, &block)
118
121
  end
119
122
 
@@ -3,8 +3,7 @@
3
3
  module Sentry
4
4
  class Transport
5
5
  class Configuration
6
- attr_accessor :timeout, :open_timeout, :proxy, :ssl, :ssl_ca_file, :ssl_verification, :http_adapter, :faraday_builder,
7
- :encoding
6
+ attr_accessor :timeout, :open_timeout, :proxy, :ssl, :ssl_ca_file, :ssl_verification, :encoding
8
7
  attr_reader :transport_class
9
8
 
10
9
  def initialize
@@ -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,14 +12,13 @@ module Sentry
12
12
  DEFAULT_DELAY = 60
13
13
  RETRY_AFTER_HEADER = "retry-after"
14
14
  RATE_LIMIT_HEADER = "x-sentry-rate-limits"
15
-
16
- attr_reader :conn, :adapter
15
+ USER_AGENT = "sentry-ruby/#{Sentry::VERSION}"
17
16
 
18
17
  def initialize(*args)
19
18
  super
20
- @adapter = @transport_configuration.http_adapter || Faraday.default_adapter
21
- @conn = set_conn
22
19
  @endpoint = @dsn.envelope_endpoint
20
+
21
+ log_debug("Sentry HTTP Transport will connect to #{@dsn.server}")
23
22
  end
24
23
 
25
24
  def send_data(data)
@@ -30,29 +29,37 @@ module Sentry
30
29
  encoding = GZIP_ENCODING
31
30
  end
32
31
 
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
32
+ headers = {
33
+ 'Content-Type' => CONTENT_TYPE,
34
+ 'Content-Encoding' => encoding,
35
+ 'X-Sentry-Auth' => generate_auth_header,
36
+ 'User-Agent' => USER_AGENT
37
+ }
38
+
39
+ response = conn.start do |http|
40
+ request = ::Net::HTTP::Post.new(@endpoint, headers)
41
+ request.body = data
42
+ http.request(request)
38
43
  end
39
44
 
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
45
+ if response.code.match?(/\A2\d{2}/)
46
+ if has_rate_limited_header?(response)
47
+ handle_rate_limited_response(response)
48
+ end
49
+ else
50
+ error_info = "the server responded with status #{response.code}"
45
51
 
46
- if e.response
47
- if e.response[:status] == 429
48
- handle_rate_limited_response(e.response[:headers])
52
+ if response.code == "429"
53
+ handle_rate_limited_response(response)
49
54
  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']
55
+ error_info += "\nbody: #{response.body}"
56
+ error_info += " Error in headers is: #{response['x-sentry-error']}" if response['x-sentry-error']
52
57
  end
53
- end
54
58
 
55
- raise Sentry::ExternalError, error_info
59
+ raise Sentry::ExternalError, error_info
60
+ end
61
+ rescue SocketError => e
62
+ raise Sentry::ExternalError.new(e.message)
56
63
  end
57
64
 
58
65
  private
@@ -119,32 +126,39 @@ module Sentry
119
126
  @transport_configuration.encoding == GZIP_ENCODING && data.bytesize >= GZIP_THRESHOLD
120
127
  end
121
128
 
122
- def set_conn
123
- server = @dsn.server
129
+ def conn
130
+ server = URI(@dsn.server)
124
131
 
125
- log_debug("Sentry HTTP Transport connecting to #{server}")
132
+ use_ssl = server.scheme == "https"
133
+ port = use_ssl ? 443 : 80
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
+ connection =
136
+ if proxy = @transport_configuration.proxy
137
+ ::Net::HTTP.new(server.hostname, port, proxy[:uri].hostname, proxy[:uri].port, proxy[:user], proxy[:password])
138
+ else
139
+ ::Net::HTTP.new(server.hostname, port, nil)
140
+ end
135
141
 
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)
142
+ connection.use_ssl = use_ssl
143
+ connection.read_timeout = @transport_configuration.timeout
144
+ connection.write_timeout = @transport_configuration.timeout if connection.respond_to?(:write_timeout)
145
+ connection.open_timeout = @transport_configuration.open_timeout
146
+
147
+ ssl_configuration.each do |key, value|
148
+ connection.send("#{key}=", value)
140
149
  end
150
+
151
+ connection
141
152
  end
142
153
 
143
154
  def ssl_configuration
144
- {
155
+ configuration = {
145
156
  verify: @transport_configuration.ssl_verification,
146
157
  ca_file: @transport_configuration.ssl_ca_file
147
158
  }.merge(@transport_configuration.ssl || {})
159
+
160
+ configuration[:verify_mode] = configuration.delete(:verify) ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
161
+ configuration
148
162
  end
149
163
  end
150
164
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sentry
4
- VERSION = "4.9.0"
4
+ VERSION = "5.0.1"
5
5
  end
data/lib/sentry-ruby.rb CHANGED
@@ -174,7 +174,7 @@ module Sentry
174
174
  #
175
175
  # @return [Boolean]
176
176
  def initialized?
177
- !!@main_hub
177
+ !!get_main_hub
178
178
  end
179
179
 
180
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.9.0
4
+ version: 5.0.1
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-07 00:00:00.000000000 Z
11
+ date: 2022-01-23 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