httpx 0.19.5 → 0.19.8

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: 0dbbe59cf004c889830daa1a45b0111eb4e04e7447fc0e94bca9ae7041d99770
4
- data.tar.gz: 95acfba594d42b96a41e0d18d682f5873cbe57e1e394d62d76ce7be1463741ad
3
+ metadata.gz: 05a379db82c9c86f84a847680f4a784ed62a4cbcb8ce8d09a3d3c29abeb7d5d1
4
+ data.tar.gz: 5046f5d1e86f7d5c523a171b23fd5fb8126b63636a021c204a7c33a4ebf5e319
5
5
  SHA512:
6
- metadata.gz: 401ee8e3e4c1eb92a454a9debb73d3f1c7d1f119ba757e5a2534b4d2b7a39c2608b7ef91f95fc74ec50dfa7db1faa25aadf4b57d2e8c9f58f5c65e01f98dc234
7
- data.tar.gz: 937d4b05a7ee6b3da3cdce1e98e3c389dc3eed82cc29a278dfb3d7c0d7907e795421caaec00f2a95112d99deb13fcfe1d81a70c291d0f00dd862021cbe036583
6
+ metadata.gz: d62d606f0688c485f79a38feed6b94841005fb6a70c5ab934c7b70cb7a7958066b85a496405959a7660da3f12f194d844f10660621ce6fb98c7aa898c38d855c
7
+ data.tar.gz: 42b46c44c4c864222f14235534be31db4eb5155716c542457178be010b227fdb391c095b009759e9c237d6320da7133123334cfc4b3d4dd6940ff58aa6df9f0e
@@ -0,0 +1,5 @@
1
+ # 0.19.6
2
+
3
+ ## Bugfixes
4
+
5
+ * fixed the root cause of the `faraday` adapter failing when used alongside the `webmock` integration.
@@ -0,0 +1,5 @@
1
+ # 0.19.7
2
+
3
+ ## Bugfixes
4
+
5
+ * fix: in `:proxy` plugin, user/pass credentials were not being used when passed as options (only when embedded in the URL). This was a regression introduced in the 0.19.x series.
@@ -0,0 +1,5 @@
1
+ # 0.19.7
2
+
3
+ ## Bugfixes
4
+
5
+ * `datadog` went v1, which broke `httpx` adapter. Now it supports both 1.0 and 0.x versions.
@@ -1,12 +1,52 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "ddtrace/contrib/integration"
4
- require "ddtrace/contrib/rest_client/configuration/settings"
5
- require "ddtrace/contrib/rest_client/patcher"
3
+ if defined?(::DDTrace) && ::DDTrace::VERSION::STRING >= "1.0.0"
4
+ require "datadog/tracing/contrib/integration"
5
+ require "datadog/tracing/contrib/configuration/settings"
6
+ require "datadog/tracing/contrib/patcher"
6
7
 
7
- module Datadog
8
+ TRACING_MODULE = Datadog::Tracing
9
+ else
10
+
11
+ require "ddtrace/contrib/integration"
12
+ require "ddtrace/contrib/configuration/settings"
13
+ require "ddtrace/contrib/patcher"
14
+
15
+ TRACING_MODULE = Datadog
16
+ end
17
+
18
+ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
8
19
  module Contrib
9
20
  module HTTPX
21
+ if defined?(::DDTrace) && ::DDTrace::VERSION::STRING >= "1.0.0"
22
+ METADATA_MODULE = TRACING_MODULE::Metadata
23
+
24
+ TYPE_OUTBOUND = TRACING_MODULE::Metadata::Ext::HTTP::TYPE_OUTBOUND
25
+
26
+ TAG_PEER_SERVICE = TRACING_MODULE::Metadata::Ext::TAG_PEER_SERVICE
27
+
28
+ TAG_URL = TRACING_MODULE::Metadata::Ext::HTTP::TAG_URL
29
+ TAG_METHOD = TRACING_MODULE::Metadata::Ext::HTTP::TAG_METHOD
30
+ TAG_TARGET_HOST = TRACING_MODULE::Metadata::Ext::NET::TAG_TARGET_HOST
31
+ TAG_TARGET_PORT = TRACING_MODULE::Metadata::Ext::NET::TAG_TARGET_PORT
32
+
33
+ TAG_STATUS_CODE = TRACING_MODULE::Metadata::Ext::HTTP::TAG_STATUS_CODE
34
+
35
+ else
36
+
37
+ METADATA_MODULE = Datadog
38
+
39
+ TYPE_OUTBOUND = TRACING_MODULE::Ext::HTTP::TYPE_OUTBOUND
40
+ TAG_PEER_SERVICE = TRACING_MODULE::Ext::Integration::TAG_PEER_SERVICE
41
+ TAG_URL = TRACING_MODULE::Ext::HTTP::URL
42
+ TAG_METHOD = TRACING_MODULE::Ext::HTTP::METHOD
43
+ TAG_TARGET_HOST = TRACING_MODULE::Ext::NET::TARGET_HOST
44
+ TAG_TARGET_PORT = TRACING_MODULE::Ext::NET::TARGET_PORT
45
+ TAG_STATUS_CODE = Datadog::Ext::HTTP::STATUS_CODE
46
+ PROPAGATOR = TRACING_MODULE::HTTPPropagator
47
+
48
+ end
49
+
10
50
  # HTTPX Datadog Plugin
11
51
  #
12
52
  # Enables tracing for httpx requests. A span will be created for each individual requests,
@@ -15,6 +55,8 @@ module Datadog
15
55
  #
16
56
  module Plugin
17
57
  class RequestTracer
58
+ include Contrib::HttpAnnotationHelper
59
+
18
60
  SPAN_REQUEST = "httpx.request"
19
61
 
20
62
  def initialize(request)
@@ -22,43 +64,37 @@ module Datadog
22
64
  end
23
65
 
24
66
  def call
25
- return if skip_tracing?
67
+ return unless tracing_enabled?
26
68
 
27
69
  @request.on(:response, &method(:finish))
28
70
 
29
71
  verb = @request.verb.to_s.upcase
30
72
  uri = @request.uri
31
73
 
32
- @span = datadog_pin.tracer.trace(SPAN_REQUEST)
33
- service_name = datadog_config[:split_by_domain] ? uri.host : datadog_pin.service_name
74
+ @span = build_span
34
75
 
35
- begin
36
- @span.service = service_name
37
- @span.span_type = Datadog::Ext::HTTP::TYPE_OUTBOUND
38
- @span.resource = verb
76
+ @span.resource = verb
39
77
 
40
- Datadog::HTTPPropagator.inject!(@span.context, @request.headers) if datadog_pin.tracer.enabled && !skip_distributed_tracing?
78
+ # Add additional request specific tags to the span.
41
79
 
42
- # Add additional request specific tags to the span.
80
+ @span.set_tag(TAG_URL, @request.path)
81
+ @span.set_tag(TAG_METHOD, verb)
43
82
 
44
- @span.set_tag(Datadog::Ext::HTTP::URL, @request.path)
45
- @span.set_tag(Datadog::Ext::HTTP::METHOD, verb)
83
+ @span.set_tag(TAG_TARGET_HOST, uri.host)
84
+ @span.set_tag(TAG_TARGET_PORT, uri.port.to_s)
46
85
 
47
- @span.set_tag(Datadog::Ext::NET::TARGET_HOST, uri.host)
48
- @span.set_tag(Datadog::Ext::NET::TARGET_PORT, uri.port.to_s)
86
+ # Tag as an external peer service
87
+ @span.set_tag(TAG_PEER_SERVICE, @span.service)
49
88
 
50
- # Tag as an external peer service
51
- @span.set_tag(Datadog::Ext::Integration::TAG_PEER_SERVICE, @span.service)
89
+ propagate_headers if @configuration[:distributed_tracing]
52
90
 
53
- # Set analytics sample rate
54
- if Contrib::Analytics.enabled?(datadog_config[:analytics_enabled])
55
- Contrib::Analytics.set_sample_rate(@span, datadog_config[:analytics_sample_rate])
56
- end
57
- rescue StandardError => e
58
- Datadog.logger.error("error preparing span for http request: #{e}")
91
+ # Set analytics sample rate
92
+ if Contrib::Analytics.enabled?(@configuration[:analytics_enabled])
93
+ Contrib::Analytics.set_sample_rate(@span, @configuration[:analytics_sample_rate])
59
94
  end
60
95
  rescue StandardError => e
61
- Datadog.logger.debug("Failed to start span: #{e}")
96
+ Datadog.logger.error("error preparing span for http request: #{e}")
97
+ Datadog.logger.error(e.backtrace)
62
98
  end
63
99
 
64
100
  def finish(response)
@@ -67,7 +103,7 @@ module Datadog
67
103
  if response.is_a?(::HTTPX::ErrorResponse)
68
104
  @span.set_error(response.error)
69
105
  else
70
- @span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, response.status.to_s)
106
+ @span.set_tag(TAG_STATUS_CODE, response.status.to_s)
71
107
 
72
108
  @span.set_error(::HTTPX::HTTPError.new(response)) if response.status >= 400 && response.status <= 599
73
109
  end
@@ -77,40 +113,48 @@ module Datadog
77
113
 
78
114
  private
79
115
 
80
- def skip_tracing?
81
- return true if @request.headers.key?(Datadog::Ext::Transport::HTTP::HEADER_META_TRACER_VERSION)
82
-
83
- return false unless @datadog_pin
84
-
85
- span = @datadog_pin.tracer.active_span
116
+ if defined?(::DDTrace) && ::DDTrace::VERSION::STRING >= "1.0.0"
86
117
 
87
- return true if span && (span.name == SPAN_REQUEST)
118
+ def build_span
119
+ TRACING_MODULE.trace(
120
+ SPAN_REQUEST,
121
+ service: service_name(@request.uri.host, configuration, Datadog.configuration_for(self)),
122
+ span_type: TYPE_OUTBOUND
123
+ )
124
+ end
88
125
 
89
- false
90
- end
126
+ def propagate_headers
127
+ TRACING_MODULE::Propagation::HTTP.inject!(TRACING_MODULE.active_trace, @request.headers)
128
+ end
91
129
 
92
- def skip_distributed_tracing?
93
- return !datadog_pin.config[:distributed_tracing] if datadog_pin.config && datadog_pin.config.key?(:distributed_tracing)
130
+ def configuration
131
+ @configuration ||= Datadog.configuration.tracing[:httpx, @request.uri.host]
132
+ end
94
133
 
95
- !Datadog.configuration[:httpx][:distributed_tracing]
96
- end
134
+ def tracing_enabled?
135
+ TRACING_MODULE.enabled?
136
+ end
137
+ else
138
+ def build_span
139
+ service_name = configuration[:split_by_domain] ? @request.uri.host : configuration[:service_name]
140
+ configuration[:tracer].trace(
141
+ SPAN_REQUEST,
142
+ service: service_name,
143
+ span_type: TYPE_OUTBOUND
144
+ )
145
+ end
97
146
 
98
- def datadog_pin
99
- @datadog_pin ||= begin
100
- service = datadog_config[:service_name]
101
- tracer = datadog_config[:tracer]
147
+ def propagate_headers
148
+ Datadog::HTTPPropagator.inject!(@span.context, @request.headers)
149
+ end
102
150
 
103
- Datadog::Pin.new(
104
- service,
105
- app: "httpx",
106
- app_type: Datadog::Ext::AppTypes::WEB,
107
- tracer: -> { tracer }
108
- )
151
+ def configuration
152
+ @configuration ||= Datadog.configuration[:httpx, @request.uri.host]
109
153
  end
110
- end
111
154
 
112
- def datadog_config
113
- @datadog_config ||= Datadog.configuration[:httpx, @request.uri.host]
155
+ def tracing_enabled?
156
+ configuration[:tracer].enabled
157
+ end
114
158
  end
115
159
  end
116
160
 
@@ -125,7 +169,11 @@ module Datadog
125
169
  module Configuration
126
170
  # Default settings for httpx
127
171
  #
128
- class Settings < Datadog::Contrib::Configuration::Settings
172
+ class Settings < TRACING_MODULE::Contrib::Configuration::Settings
173
+ DEFAULT_ERROR_HANDLER = lambda do |response|
174
+ Datadog::Ext::HTTP::ERROR_RANGE.cover?(response.status)
175
+ end
176
+
129
177
  option :service_name, default: "httpx"
130
178
  option :distributed_tracing, default: true
131
179
  option :split_by_domain, default: false
@@ -145,14 +193,14 @@ module Datadog
145
193
  o.lazy
146
194
  end
147
195
 
148
- option :error_handler, default: Datadog::Tracer::DEFAULT_ON_ERROR
196
+ option :error_handler, default: DEFAULT_ERROR_HANDLER
149
197
  end
150
198
  end
151
199
 
152
200
  # Patcher enables patching of 'httpx' with datadog components.
153
201
  #
154
202
  module Patcher
155
- include Datadog::Contrib::Patcher
203
+ include TRACING_MODULE::Contrib::Patcher
156
204
 
157
205
  module_function
158
206
 
@@ -192,8 +240,14 @@ module Datadog
192
240
  super && version >= MINIMUM_VERSION
193
241
  end
194
242
 
195
- def default_configuration
196
- Configuration::Settings.new
243
+ if defined?(::DDTrace) && ::DDTrace::VERSION::STRING >= "1.0.0"
244
+ def new_configuration
245
+ Configuration::Settings.new
246
+ end
247
+ else
248
+ def default_configuration
249
+ Configuration::Settings.new
250
+ end
197
251
  end
198
252
 
199
253
  def patcher
@@ -99,33 +99,31 @@ module Faraday
99
99
  end
100
100
  end
101
101
 
102
- class Session < ::HTTPX::Session
103
- plugin(:compression)
104
- plugin(:persistent)
105
-
106
- module ReasonPlugin
102
+ module ReasonPlugin
103
+ if RUBY_VERSION < "2.5"
104
+ def self.load_dependencies(*)
105
+ require "webrick"
106
+ end
107
+ else
108
+ def self.load_dependencies(*)
109
+ require "net/http/status"
110
+ end
111
+ end
112
+ module ResponseMethods
107
113
  if RUBY_VERSION < "2.5"
108
- def self.load_dependencies(*)
109
- require "webrick"
114
+ def reason
115
+ WEBrick::HTTPStatus::StatusMessage.fetch(@status)
110
116
  end
111
117
  else
112
- def self.load_dependencies(*)
113
- require "net/http/status"
114
- end
115
- end
116
- module ResponseMethods
117
- if RUBY_VERSION < "2.5"
118
- def reason
119
- WEBrick::HTTPStatus::StatusMessage.fetch(@status)
120
- end
121
- else
122
- def reason
123
- Net::HTTP::STATUS_CODES.fetch(@status)
124
- end
118
+ def reason
119
+ Net::HTTP::STATUS_CODES.fetch(@status)
125
120
  end
126
121
  end
127
122
  end
128
- plugin(ReasonPlugin)
123
+ end
124
+
125
+ def self.session
126
+ @session ||= ::HTTPX.plugin(:compression).plugin(:persistent).plugin(ReasonPlugin)
129
127
  end
130
128
 
131
129
  class ParallelManager
@@ -161,7 +159,6 @@ module Faraday
161
159
  include RequestMixin
162
160
 
163
161
  def initialize
164
- @session = Session.new
165
162
  @handlers = []
166
163
  end
167
164
 
@@ -174,7 +171,7 @@ module Faraday
174
171
  def run
175
172
  env = @handlers.last.env
176
173
 
177
- session = @session.with(options_from_env(env))
174
+ session = HTTPX.session.with(options_from_env(env))
178
175
  session = session.plugin(:proxy).with(proxy: { uri: env.request.proxy }) if env.request.proxy
179
176
  session = session.plugin(OnDataPlugin) if env.request.stream_response?
180
177
 
@@ -205,7 +202,7 @@ module Faraday
205
202
 
206
203
  def initialize(app, options = {})
207
204
  super(app)
208
- @session = Session.new(options)
205
+ @session_options = options
209
206
  end
210
207
 
211
208
  def call(env)
@@ -221,7 +218,9 @@ module Faraday
221
218
  return handler
222
219
  end
223
220
 
224
- session = @session.with(options_from_env(env))
221
+ session = HTTPX.session
222
+ session = session.with(@session_options) unless @session_options.empty?
223
+ session = session.with(options_from_env(env))
225
224
  session = session.plugin(:proxy).with(proxy: { uri: env.request.proxy }) if env.request.proxy
226
225
  session = session.plugin(OnDataPlugin) if env.request.stream_response?
227
226
 
@@ -81,7 +81,11 @@ module HTTPX
81
81
  end
82
82
  uris
83
83
  end
84
- { uri: @_proxy_uris.first } unless @_proxy_uris.empty?
84
+ return if @_proxy_uris.empty?
85
+
86
+ proxy_opts = { uri: @_proxy_uris.first }
87
+ proxy_opts = options.proxy.merge(proxy_opts) if options.proxy
88
+ proxy_opts
85
89
  end
86
90
 
87
91
  def find_connection(request, connections, options)
data/lib/httpx/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTPX
4
- VERSION = "0.19.5"
4
+ VERSION = "0.19.8"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.5
4
+ version: 0.19.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-30 00:00:00.000000000 Z
11
+ date: 2022-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-2-next
@@ -76,6 +76,9 @@ extra_rdoc_files:
76
76
  - doc/release_notes/0_19_3.md
77
77
  - doc/release_notes/0_19_4.md
78
78
  - doc/release_notes/0_19_5.md
79
+ - doc/release_notes/0_19_6.md
80
+ - doc/release_notes/0_19_7.md
81
+ - doc/release_notes/0_19_8.md
79
82
  - doc/release_notes/0_1_0.md
80
83
  - doc/release_notes/0_2_0.md
81
84
  - doc/release_notes/0_2_1.md
@@ -145,6 +148,9 @@ files:
145
148
  - doc/release_notes/0_19_3.md
146
149
  - doc/release_notes/0_19_4.md
147
150
  - doc/release_notes/0_19_5.md
151
+ - doc/release_notes/0_19_6.md
152
+ - doc/release_notes/0_19_7.md
153
+ - doc/release_notes/0_19_8.md
148
154
  - doc/release_notes/0_1_0.md
149
155
  - doc/release_notes/0_2_0.md
150
156
  - doc/release_notes/0_2_1.md