httpx 0.20.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +0 -48
- data/README.md +54 -45
- data/doc/release_notes/0_10_0.md +2 -2
- data/doc/release_notes/0_11_0.md +3 -5
- data/doc/release_notes/0_12_0.md +5 -5
- data/doc/release_notes/0_13_0.md +5 -5
- data/doc/release_notes/0_14_0.md +2 -2
- data/doc/release_notes/0_16_0.md +3 -3
- data/doc/release_notes/0_17_0.md +1 -1
- data/doc/release_notes/0_18_0.md +4 -4
- data/doc/release_notes/0_18_2.md +1 -1
- data/doc/release_notes/0_19_0.md +1 -1
- data/doc/release_notes/0_19_8.md +1 -1
- data/doc/release_notes/0_20_0.md +2 -2
- data/doc/release_notes/0_20_1.md +5 -0
- data/doc/release_notes/0_20_2.md +7 -0
- data/doc/release_notes/0_20_3.md +6 -0
- data/doc/release_notes/0_20_4.md +17 -0
- data/doc/release_notes/0_20_5.md +3 -0
- data/doc/release_notes/0_21_0.md +96 -0
- data/doc/release_notes/0_21_1.md +12 -0
- data/doc/release_notes/0_22_0.md +13 -0
- data/doc/release_notes/0_22_1.md +11 -0
- data/doc/release_notes/0_22_2.md +5 -0
- data/doc/release_notes/0_22_3.md +55 -0
- data/doc/release_notes/0_22_4.md +6 -0
- data/doc/release_notes/0_22_5.md +6 -0
- data/doc/release_notes/0_23_0.md +42 -0
- data/doc/release_notes/0_23_1.md +5 -0
- data/doc/release_notes/0_23_2.md +5 -0
- data/doc/release_notes/0_23_3.md +6 -0
- data/doc/release_notes/0_23_4.md +5 -0
- data/doc/release_notes/0_24_0.md +48 -0
- data/doc/release_notes/0_24_1.md +12 -0
- data/doc/release_notes/0_24_2.md +12 -0
- data/doc/release_notes/0_24_3.md +12 -0
- data/doc/release_notes/0_24_4.md +18 -0
- data/doc/release_notes/0_24_5.md +6 -0
- data/doc/release_notes/0_24_6.md +5 -0
- data/doc/release_notes/0_24_7.md +10 -0
- data/doc/release_notes/1_0_0.md +60 -0
- data/doc/release_notes/1_0_1.md +5 -0
- data/doc/release_notes/1_0_2.md +7 -0
- data/doc/release_notes/1_1_0.md +32 -0
- data/doc/release_notes/1_1_1.md +17 -0
- data/doc/release_notes/1_1_2.md +12 -0
- data/doc/release_notes/1_1_3.md +18 -0
- data/doc/release_notes/1_1_4.md +6 -0
- data/doc/release_notes/1_1_5.md +12 -0
- data/doc/release_notes/1_2_0.md +49 -0
- data/doc/release_notes/1_2_1.md +6 -0
- data/doc/release_notes/1_2_2.md +10 -0
- data/doc/release_notes/1_2_3.md +16 -0
- data/doc/release_notes/1_2_4.md +8 -0
- data/doc/release_notes/1_2_5.md +7 -0
- data/doc/release_notes/1_2_6.md +13 -0
- data/doc/release_notes/1_3_0.md +18 -0
- data/doc/release_notes/1_3_1.md +17 -0
- data/lib/httpx/adapters/datadog.rb +215 -122
- data/lib/httpx/adapters/faraday.rb +145 -107
- data/lib/httpx/adapters/sentry.rb +26 -7
- data/lib/httpx/adapters/webmock.rb +34 -18
- data/lib/httpx/altsvc.rb +63 -26
- data/lib/httpx/base64.rb +27 -0
- data/lib/httpx/buffer.rb +12 -0
- data/lib/httpx/callbacks.rb +5 -3
- data/lib/httpx/chainable.rb +54 -39
- data/lib/httpx/connection/http1.rb +75 -44
- data/lib/httpx/connection/http2.rb +31 -38
- data/lib/httpx/connection.rb +287 -117
- data/lib/httpx/domain_name.rb +10 -13
- data/lib/httpx/errors.rb +52 -2
- data/lib/httpx/extensions.rb +24 -131
- data/lib/httpx/io/ssl.rb +83 -77
- data/lib/httpx/io/tcp.rb +48 -71
- data/lib/httpx/io/udp.rb +18 -52
- data/lib/httpx/io/unix.rb +10 -15
- data/lib/httpx/io.rb +3 -9
- data/lib/httpx/loggable.rb +4 -19
- data/lib/httpx/options.rb +176 -118
- data/lib/httpx/parser/http1.rb +4 -0
- data/lib/httpx/plugins/{authentication → auth}/basic.rb +1 -5
- data/lib/httpx/plugins/{authentication → auth}/digest.rb +14 -14
- data/lib/httpx/plugins/{authentication → auth}/ntlm.rb +1 -3
- data/lib/httpx/plugins/{authentication → auth}/socks5.rb +0 -2
- data/lib/httpx/plugins/auth.rb +25 -0
- data/lib/httpx/plugins/aws_sdk_authentication.rb +4 -3
- data/lib/httpx/plugins/aws_sigv4.rb +12 -9
- data/lib/httpx/plugins/basic_auth.rb +29 -0
- data/lib/httpx/plugins/brotli.rb +50 -0
- data/lib/httpx/plugins/callbacks.rb +91 -0
- data/lib/httpx/plugins/circuit_breaker/circuit.rb +100 -0
- data/lib/httpx/plugins/circuit_breaker/circuit_store.rb +53 -0
- data/lib/httpx/plugins/circuit_breaker.rb +148 -0
- data/lib/httpx/plugins/cookies/set_cookie_parser.rb +0 -2
- data/lib/httpx/plugins/cookies.rb +30 -17
- data/lib/httpx/plugins/{digest_authentication.rb → digest_auth.rb} +14 -12
- data/lib/httpx/plugins/expect.rb +21 -14
- data/lib/httpx/plugins/follow_redirects.rb +140 -41
- data/lib/httpx/plugins/grpc/call.rb +2 -3
- data/lib/httpx/plugins/grpc/grpc_encoding.rb +88 -0
- data/lib/httpx/plugins/grpc/message.rb +7 -37
- data/lib/httpx/plugins/grpc.rb +36 -29
- data/lib/httpx/plugins/h2c.rb +26 -19
- data/lib/httpx/plugins/internal_telemetry.rb +16 -0
- data/lib/httpx/plugins/{ntlm_authentication.rb → ntlm_auth.rb} +7 -5
- data/lib/httpx/plugins/oauth.rb +175 -0
- data/lib/httpx/plugins/persistent.rb +1 -1
- data/lib/httpx/plugins/proxy/http.rb +23 -13
- data/lib/httpx/plugins/proxy/socks4.rb +9 -7
- data/lib/httpx/plugins/proxy/socks5.rb +11 -9
- data/lib/httpx/plugins/proxy.rb +80 -61
- data/lib/httpx/plugins/push_promise.rb +1 -1
- data/lib/httpx/plugins/rate_limiter.rb +5 -1
- data/lib/httpx/plugins/response_cache/file_store.rb +40 -0
- data/lib/httpx/plugins/response_cache/store.rb +62 -25
- data/lib/httpx/plugins/response_cache.rb +105 -12
- data/lib/httpx/plugins/retries.rb +87 -17
- data/lib/httpx/plugins/ssrf_filter.rb +145 -0
- data/lib/httpx/plugins/stream.rb +27 -23
- data/lib/httpx/plugins/upgrade/h2.rb +4 -4
- data/lib/httpx/plugins/upgrade.rb +8 -10
- data/lib/httpx/plugins/webdav.rb +80 -0
- data/lib/httpx/pool/synch_pool.rb +93 -0
- data/lib/httpx/pool.rb +102 -27
- data/lib/httpx/punycode.rb +9 -291
- data/lib/httpx/request/body.rb +154 -0
- data/lib/httpx/request.rb +130 -146
- data/lib/httpx/resolver/https.rb +62 -27
- data/lib/httpx/resolver/multi.rb +9 -13
- data/lib/httpx/resolver/native.rb +192 -76
- data/lib/httpx/resolver/resolver.rb +34 -9
- data/lib/httpx/resolver/system.rb +16 -11
- data/lib/httpx/resolver.rb +38 -16
- data/lib/httpx/response/body.rb +242 -0
- data/lib/httpx/response/buffer.rb +96 -0
- data/lib/httpx/response.rb +159 -217
- data/lib/httpx/selector.rb +9 -4
- data/lib/httpx/session.rb +137 -89
- data/lib/httpx/session_extensions.rb +4 -1
- data/lib/httpx/timers.rb +34 -8
- data/lib/httpx/transcoder/body.rb +0 -2
- data/lib/httpx/transcoder/chunker.rb +0 -1
- data/lib/httpx/transcoder/deflate.rb +37 -0
- data/lib/httpx/transcoder/form.rb +52 -33
- data/lib/httpx/transcoder/gzip.rb +74 -0
- data/lib/httpx/transcoder/json.rb +21 -8
- data/lib/httpx/transcoder/multipart/decoder.rb +139 -0
- data/lib/httpx/{plugins → transcoder}/multipart/encoder.rb +4 -4
- data/lib/httpx/{plugins → transcoder}/multipart/mime_type_detector.rb +1 -1
- data/lib/httpx/{plugins → transcoder}/multipart/part.rb +3 -2
- data/lib/httpx/transcoder/multipart.rb +17 -0
- data/lib/httpx/transcoder/utils/body_reader.rb +46 -0
- data/lib/httpx/transcoder/utils/deflater.rb +72 -0
- data/lib/httpx/transcoder/utils/inflater.rb +19 -0
- data/lib/httpx/transcoder/xml.rb +52 -0
- data/lib/httpx/transcoder.rb +5 -6
- data/lib/httpx/utils.rb +36 -16
- data/lib/httpx/version.rb +1 -1
- data/lib/httpx.rb +12 -14
- data/sig/altsvc.rbs +33 -0
- data/sig/buffer.rbs +2 -1
- data/sig/callbacks.rbs +3 -3
- data/sig/chainable.rbs +11 -9
- data/sig/connection/http1.rbs +8 -7
- data/sig/connection/http2.rbs +19 -19
- data/sig/connection.rbs +64 -24
- data/sig/errors.rbs +22 -3
- data/sig/httpx.rbs +5 -4
- data/sig/io/ssl.rbs +27 -0
- data/sig/io/tcp.rbs +60 -0
- data/sig/io/udp.rbs +20 -0
- data/sig/io/unix.rbs +27 -0
- data/sig/io.rbs +6 -0
- data/sig/options.rbs +32 -22
- data/sig/parser/http1.rbs +1 -1
- data/sig/plugins/{authentication → auth}/basic.rbs +0 -2
- data/sig/plugins/{authentication → auth}/digest.rbs +2 -1
- data/sig/plugins/auth.rbs +13 -0
- data/sig/plugins/{basic_authentication.rbs → basic_auth.rbs} +2 -2
- data/sig/plugins/brotli.rbs +22 -0
- data/sig/plugins/callbacks.rbs +38 -0
- data/sig/plugins/circuit_breaker.rbs +71 -0
- data/sig/plugins/compression.rbs +7 -5
- data/sig/plugins/cookies/jar.rbs +2 -2
- data/sig/plugins/cookies.rbs +2 -0
- data/sig/plugins/{digest_authentication.rbs → digest_auth.rbs} +2 -2
- data/sig/plugins/follow_redirects.rbs +18 -4
- data/sig/plugins/grpc/call.rbs +19 -0
- data/sig/plugins/grpc/grpc_encoding.rbs +37 -0
- data/sig/plugins/grpc/message.rbs +17 -0
- data/sig/plugins/grpc.rbs +7 -32
- data/sig/plugins/h2c.rbs +1 -1
- data/sig/plugins/{ntlm_authentication.rbs → ntlm_auth.rbs} +2 -2
- data/sig/plugins/oauth.rbs +54 -0
- data/sig/plugins/proxy/http.rbs +3 -0
- data/sig/plugins/proxy/socks4.rbs +9 -6
- data/sig/plugins/proxy/socks5.rbs +10 -6
- data/sig/plugins/proxy/ssh.rbs +1 -1
- data/sig/plugins/proxy.rbs +13 -5
- data/sig/plugins/push_promise.rbs +3 -3
- data/sig/plugins/rate_limiter.rbs +1 -1
- data/sig/plugins/response_cache.rbs +36 -7
- data/sig/plugins/retries.rbs +30 -8
- data/sig/plugins/stream.rbs +24 -17
- data/sig/plugins/upgrade.rbs +5 -3
- data/sig/pool.rbs +10 -7
- data/sig/request/body.rbs +38 -0
- data/sig/request.rbs +15 -24
- data/sig/resolver/https.rbs +8 -3
- data/sig/resolver/native.rbs +17 -4
- data/sig/resolver/resolver.rbs +8 -6
- data/sig/resolver/system.rbs +2 -0
- data/sig/resolver.rbs +9 -5
- data/sig/response/body.rbs +53 -0
- data/sig/response/buffer.rbs +24 -0
- data/sig/response.rbs +24 -39
- data/sig/selector.rbs +1 -1
- data/sig/session.rbs +29 -18
- data/sig/timers.rbs +18 -8
- data/sig/transcoder/body.rbs +4 -3
- data/sig/transcoder/deflate.rbs +11 -0
- data/sig/transcoder/form.rbs +5 -3
- data/sig/transcoder/gzip.rbs +24 -0
- data/sig/transcoder/json.rbs +8 -3
- data/sig/{plugins → transcoder}/multipart.rbs +15 -19
- data/sig/transcoder/utils/body_reader.rbs +15 -0
- data/sig/transcoder/utils/deflater.rbs +29 -0
- data/sig/transcoder/utils/inflater.rbs +12 -0
- data/sig/transcoder/xml.rbs +22 -0
- data/sig/transcoder.rbs +24 -9
- data/sig/utils.rbs +8 -2
- metadata +163 -41
- data/lib/httpx/plugins/authentication.rb +0 -20
- data/lib/httpx/plugins/basic_authentication.rb +0 -30
- data/lib/httpx/plugins/compression/brotli.rb +0 -54
- data/lib/httpx/plugins/compression/deflate.rb +0 -49
- data/lib/httpx/plugins/compression/gzip.rb +0 -88
- data/lib/httpx/plugins/compression.rb +0 -164
- data/lib/httpx/plugins/multipart/decoder.rb +0 -187
- data/lib/httpx/plugins/multipart.rb +0 -84
- data/lib/httpx/registry.rb +0 -85
- data/sig/plugins/authentication.rbs +0 -11
- data/sig/plugins/compression/brotli.rbs +0 -21
- data/sig/plugins/compression/deflate.rbs +0 -17
- data/sig/plugins/compression/gzip.rbs +0 -29
- data/sig/registry.rbs +0 -12
- /data/sig/plugins/{authentication → auth}/ntlm.rbs +0 -0
- /data/sig/plugins/{authentication → auth}/socks5.rbs +0 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
# 1.3.0
|
2
|
+
|
3
|
+
## Dependencies
|
4
|
+
|
5
|
+
`http-2` v1.0.0 is replacing `http-2-next` as the HTTP/2 parser.
|
6
|
+
|
7
|
+
`http-2-next` was forked from `http-2` 5 years ago; its improvements have been merged back to `http-2` recently though, so `http-2-next` willl therefore no longer be maintained.
|
8
|
+
|
9
|
+
## Improvements
|
10
|
+
|
11
|
+
Request-specific options (`:params`, `:form`, `:json` and `:xml`) are now separately kept by the request, which allows them to share `HTTPX::Options`, and reduce the number of copying / allocations.
|
12
|
+
|
13
|
+
This means that `HTTPX::Options` will throw an error if you initialize an object which such keys; this should not happen, as this class is considered internal and you should not be using it directly.
|
14
|
+
|
15
|
+
## Fixes
|
16
|
+
|
17
|
+
* support for the `datadog` gem v2.0.0 in its adapter has been unblocked, now that the gem has been released.
|
18
|
+
* loading the `:cookies` plugin was making the `Session#build_request` private.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# 1.3.1
|
2
|
+
|
3
|
+
## Improvements
|
4
|
+
|
5
|
+
* `:request_timeout` will be applied to all HTTP interactions until the final responses returned to the caller. That includes:
|
6
|
+
* all redirect requests/responses (when using the `:follow_redirects` plugin)
|
7
|
+
* all retried requests/responses (when using the `:retries` plugin)
|
8
|
+
* intermediate requests (such as "100-continue")
|
9
|
+
* faraday adapter: allow further plugins of internal session (ex: `builder.adapter(:httpx) { |sess| sess.plugin(:follow_redirects) }...`)
|
10
|
+
|
11
|
+
## Bugfixes
|
12
|
+
|
13
|
+
* fix connection leak on proxy auth failed (407) handling
|
14
|
+
* fix busy loop on deferred requests for the duration interval
|
15
|
+
* do not further enqueue deferred requests if they have terminated meanwhile.
|
16
|
+
* fix busy loop caused by coalescing connections when one of them is on the DNS resolution phase still.
|
17
|
+
* faraday adapter: on parallel mode, skip calling `on_complete` when not defined.
|
@@ -1,57 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
require "datadog/tracing/contrib/patcher"
|
3
|
+
require "datadog/tracing/contrib/integration"
|
4
|
+
require "datadog/tracing/contrib/configuration/settings"
|
5
|
+
require "datadog/tracing/contrib/patcher"
|
7
6
|
|
8
|
-
|
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
|
7
|
+
module Datadog::Tracing
|
19
8
|
module Contrib
|
20
9
|
module HTTPX
|
21
|
-
|
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
|
10
|
+
DATADOG_VERSION = defined?(::DDTrace) ? ::DDTrace::VERSION : ::Datadog::VERSION
|
27
11
|
|
28
|
-
|
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
|
12
|
+
METADATA_MODULE = Datadog::Tracing::Metadata
|
32
13
|
|
33
|
-
|
14
|
+
TYPE_OUTBOUND = Datadog::Tracing::Metadata::Ext::HTTP::TYPE_OUTBOUND
|
34
15
|
|
35
|
-
|
16
|
+
TAG_PEER_SERVICE = Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE
|
36
17
|
|
37
|
-
|
18
|
+
TAG_URL = Datadog::Tracing::Metadata::Ext::HTTP::TAG_URL
|
19
|
+
TAG_METHOD = Datadog::Tracing::Metadata::Ext::HTTP::TAG_METHOD
|
20
|
+
TAG_TARGET_HOST = Datadog::Tracing::Metadata::Ext::NET::TAG_TARGET_HOST
|
21
|
+
TAG_TARGET_PORT = Datadog::Tracing::Metadata::Ext::NET::TAG_TARGET_PORT
|
38
22
|
|
39
|
-
|
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
|
23
|
+
TAG_STATUS_CODE = Datadog::Tracing::Metadata::Ext::HTTP::TAG_STATUS_CODE
|
49
24
|
|
50
25
|
# HTTPX Datadog Plugin
|
51
26
|
#
|
52
|
-
# Enables tracing for httpx requests.
|
53
|
-
#
|
54
|
-
#
|
27
|
+
# Enables tracing for httpx requests.
|
28
|
+
#
|
29
|
+
# A span will be created for each request transaction; the span is created lazily only when
|
30
|
+
# receiving a response, and it is fed the start time stored inside the tracer object.
|
55
31
|
#
|
56
32
|
module Plugin
|
57
33
|
class RequestTracer
|
@@ -59,108 +35,179 @@ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
|
|
59
35
|
|
60
36
|
SPAN_REQUEST = "httpx.request"
|
61
37
|
|
38
|
+
# initializes the tracer object on the +request+.
|
62
39
|
def initialize(request)
|
63
40
|
@request = request
|
41
|
+
@start_time = nil
|
42
|
+
|
43
|
+
# request objects are reused, when already buffered requests get rerouted to a different
|
44
|
+
# connection due to connection issues, or when they already got a response, but need to
|
45
|
+
# be retried. In such situations, the original span needs to be extended for the former,
|
46
|
+
# while a new is required for the latter.
|
47
|
+
request.on(:idle) { reset }
|
48
|
+
# the span is initialized when the request is buffered in the parser, which is the closest
|
49
|
+
# one gets to actually sending the request.
|
50
|
+
request.on(:headers) { call }
|
51
|
+
end
|
52
|
+
|
53
|
+
# sets up the span start time, while preparing the on response callback.
|
54
|
+
def call(*args)
|
55
|
+
return if @start_time
|
56
|
+
|
57
|
+
start(*args)
|
58
|
+
|
59
|
+
@request.once(:response, &method(:finish))
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
# just sets the span init time. It can be passed a +start_time+ in cases where
|
65
|
+
# this is collected outside the request transaction.
|
66
|
+
def start(start_time = now)
|
67
|
+
@start_time = start_time
|
64
68
|
end
|
65
69
|
|
66
|
-
|
67
|
-
|
70
|
+
# resets the start time for already finished request transactions.
|
71
|
+
def reset
|
72
|
+
return unless @start_time
|
73
|
+
|
74
|
+
start
|
75
|
+
end
|
76
|
+
|
77
|
+
# creates the span from the collected +@start_time+ to what the +response+ state
|
78
|
+
# contains. It also resets internal state to allow this object to be reused.
|
79
|
+
def finish(response)
|
80
|
+
return unless @start_time
|
81
|
+
|
82
|
+
span = initialize_span
|
68
83
|
|
69
|
-
|
84
|
+
return unless span
|
70
85
|
|
71
|
-
|
86
|
+
if response.is_a?(::HTTPX::ErrorResponse)
|
87
|
+
span.set_error(response.error)
|
88
|
+
else
|
89
|
+
span.set_tag(TAG_STATUS_CODE, response.status.to_s)
|
90
|
+
|
91
|
+
span.set_error(::HTTPX::HTTPError.new(response)) if response.status >= 400 && response.status <= 599
|
92
|
+
end
|
93
|
+
|
94
|
+
span.finish
|
95
|
+
ensure
|
96
|
+
@start_time = nil
|
97
|
+
end
|
98
|
+
|
99
|
+
# return a span initialized with the +@request+ state.
|
100
|
+
def initialize_span
|
101
|
+
verb = @request.verb
|
72
102
|
uri = @request.uri
|
73
103
|
|
74
|
-
|
104
|
+
span = create_span(@request)
|
75
105
|
|
76
|
-
|
106
|
+
span.resource = verb
|
77
107
|
|
78
108
|
# Add additional request specific tags to the span.
|
79
109
|
|
80
|
-
|
81
|
-
|
110
|
+
span.set_tag(TAG_URL, @request.path)
|
111
|
+
span.set_tag(TAG_METHOD, verb)
|
82
112
|
|
83
|
-
|
84
|
-
|
113
|
+
span.set_tag(TAG_TARGET_HOST, uri.host)
|
114
|
+
span.set_tag(TAG_TARGET_PORT, uri.port.to_s)
|
85
115
|
|
86
116
|
# Tag as an external peer service
|
87
|
-
|
117
|
+
span.set_tag(TAG_PEER_SERVICE, span.service)
|
88
118
|
|
89
|
-
|
119
|
+
if configuration[:distributed_tracing]
|
120
|
+
propagate_trace_http(
|
121
|
+
Datadog::Tracing.active_trace.to_digest,
|
122
|
+
@request.headers
|
123
|
+
)
|
124
|
+
end
|
90
125
|
|
91
126
|
# Set analytics sample rate
|
92
|
-
if Contrib::Analytics.enabled?(
|
93
|
-
Contrib::Analytics.set_sample_rate(
|
127
|
+
if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
|
128
|
+
Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate])
|
94
129
|
end
|
130
|
+
|
131
|
+
span
|
95
132
|
rescue StandardError => e
|
96
133
|
Datadog.logger.error("error preparing span for http request: #{e}")
|
97
134
|
Datadog.logger.error(e.backtrace)
|
98
135
|
end
|
99
136
|
|
100
|
-
def
|
101
|
-
|
102
|
-
|
103
|
-
if response.is_a?(::HTTPX::ErrorResponse)
|
104
|
-
@span.set_error(response.error)
|
105
|
-
else
|
106
|
-
@span.set_tag(TAG_STATUS_CODE, response.status.to_s)
|
107
|
-
|
108
|
-
@span.set_error(::HTTPX::HTTPError.new(response)) if response.status >= 400 && response.status <= 599
|
109
|
-
end
|
110
|
-
|
111
|
-
@span.finish
|
137
|
+
def now
|
138
|
+
::Datadog::Core::Utils::Time.now.utc
|
112
139
|
end
|
113
140
|
|
114
|
-
|
141
|
+
def configuration
|
142
|
+
@configuration ||= Datadog.configuration.tracing[:httpx, @request.uri.host]
|
143
|
+
end
|
115
144
|
|
116
|
-
if
|
145
|
+
if Gem::Version.new(DATADOG_VERSION::STRING) >= Gem::Version.new("2.0.0")
|
146
|
+
def propagate_trace_http(digest, headers)
|
147
|
+
Datadog::Tracing::Contrib::HTTP.inject(digest, headers)
|
148
|
+
end
|
117
149
|
|
118
|
-
def
|
119
|
-
|
150
|
+
def create_span(request)
|
151
|
+
Datadog::Tracing.trace(
|
120
152
|
SPAN_REQUEST,
|
121
|
-
service: service_name(
|
122
|
-
|
153
|
+
service: service_name(request.uri.host, configuration, Datadog.configuration_for(self)),
|
154
|
+
type: TYPE_OUTBOUND,
|
155
|
+
start_time: @start_time
|
123
156
|
)
|
124
157
|
end
|
125
|
-
|
126
|
-
def
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
def configuration
|
131
|
-
@configuration ||= Datadog.configuration.tracing[:httpx, @request.uri.host]
|
158
|
+
else
|
159
|
+
def propagate_trace_http(digest, headers)
|
160
|
+
Datadog::Tracing::Propagation::HTTP.inject!(digest, headers)
|
132
161
|
end
|
133
162
|
|
134
|
-
def
|
135
|
-
|
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(
|
163
|
+
def create_span(request)
|
164
|
+
Datadog::Tracing.trace(
|
141
165
|
SPAN_REQUEST,
|
142
|
-
service: service_name,
|
143
|
-
span_type: TYPE_OUTBOUND
|
166
|
+
service: service_name(request.uri.host, configuration, Datadog.configuration_for(self)),
|
167
|
+
span_type: TYPE_OUTBOUND,
|
168
|
+
start_time: @start_time
|
144
169
|
)
|
145
170
|
end
|
171
|
+
end
|
172
|
+
end
|
146
173
|
|
147
|
-
|
148
|
-
|
149
|
-
|
174
|
+
module RequestMethods
|
175
|
+
# intercepts request initialization to inject the tracing logic.
|
176
|
+
def initialize(*)
|
177
|
+
super
|
150
178
|
|
151
|
-
|
152
|
-
@configuration ||= Datadog.configuration[:httpx, @request.uri.host]
|
153
|
-
end
|
179
|
+
return unless Datadog::Tracing.enabled?
|
154
180
|
|
155
|
-
|
156
|
-
configuration[:tracer].enabled
|
157
|
-
end
|
181
|
+
RequestTracer.new(self)
|
158
182
|
end
|
159
183
|
end
|
160
184
|
|
161
185
|
module ConnectionMethods
|
162
|
-
|
163
|
-
|
186
|
+
attr_reader :init_time
|
187
|
+
|
188
|
+
def initialize(*)
|
189
|
+
super
|
190
|
+
|
191
|
+
@init_time = ::Datadog::Core::Utils::Time.now.utc
|
192
|
+
end
|
193
|
+
|
194
|
+
# handles the case when the +error+ happened during name resolution, which meanns
|
195
|
+
# that the tracing logic hasn't been injected yet; in such cases, the approximate
|
196
|
+
# initial resolving time is collected from the connection, and used as span start time,
|
197
|
+
# and the tracing object in inserted before the on response callback is called.
|
198
|
+
def handle_error(error, request = nil)
|
199
|
+
return super unless Datadog::Tracing.enabled?
|
200
|
+
|
201
|
+
return super unless error.respond_to?(:connection)
|
202
|
+
|
203
|
+
@pending.each do |req|
|
204
|
+
next if request and request == req
|
205
|
+
|
206
|
+
RequestTracer.new(req).call(error.connection.init_time)
|
207
|
+
end
|
208
|
+
|
209
|
+
RequestTracer.new(request).call(error.connection.init_time) if request
|
210
|
+
|
164
211
|
super
|
165
212
|
end
|
166
213
|
end
|
@@ -169,7 +216,7 @@ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
|
|
169
216
|
module Configuration
|
170
217
|
# Default settings for httpx
|
171
218
|
#
|
172
|
-
class Settings <
|
219
|
+
class Settings < Datadog::Tracing::Contrib::Configuration::Settings
|
173
220
|
DEFAULT_ERROR_HANDLER = lambda do |response|
|
174
221
|
Datadog::Ext::HTTP::ERROR_RANGE.cover?(response.status)
|
175
222
|
end
|
@@ -178,29 +225,82 @@ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
|
|
178
225
|
option :distributed_tracing, default: true
|
179
226
|
option :split_by_domain, default: false
|
180
227
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
228
|
+
if Gem::Version.new(DATADOG_VERSION::STRING) >= Gem::Version.new("1.13.0")
|
229
|
+
option :enabled do |o|
|
230
|
+
o.type :bool
|
231
|
+
o.env "DD_TRACE_HTTPX_ENABLED"
|
232
|
+
o.default true
|
233
|
+
end
|
234
|
+
|
235
|
+
option :analytics_enabled do |o|
|
236
|
+
o.type :bool
|
237
|
+
o.env "DD_TRACE_HTTPX_ANALYTICS_ENABLED"
|
238
|
+
o.default false
|
239
|
+
end
|
185
240
|
|
186
|
-
|
187
|
-
|
188
|
-
|
241
|
+
option :analytics_sample_rate do |o|
|
242
|
+
o.type :float
|
243
|
+
o.env "DD_TRACE_HTTPX_ANALYTICS_SAMPLE_RATE"
|
244
|
+
o.default 1.0
|
245
|
+
end
|
246
|
+
else
|
247
|
+
option :enabled do |o|
|
248
|
+
o.default { env_to_bool("DD_TRACE_HTTPX_ENABLED", true) }
|
249
|
+
o.lazy
|
250
|
+
end
|
251
|
+
|
252
|
+
option :analytics_enabled do |o|
|
253
|
+
o.default { env_to_bool(%w[DD_TRACE_HTTPX_ANALYTICS_ENABLED DD_HTTPX_ANALYTICS_ENABLED], false) }
|
254
|
+
o.lazy
|
255
|
+
end
|
256
|
+
|
257
|
+
option :analytics_sample_rate do |o|
|
258
|
+
o.default { env_to_float(%w[DD_TRACE_HTTPX_ANALYTICS_SAMPLE_RATE DD_HTTPX_ANALYTICS_SAMPLE_RATE], 1.0) }
|
259
|
+
o.lazy
|
260
|
+
end
|
189
261
|
end
|
190
262
|
|
191
|
-
|
192
|
-
|
193
|
-
|
263
|
+
if defined?(Datadog::Tracing::Contrib::SpanAttributeSchema)
|
264
|
+
option :service_name do |o|
|
265
|
+
o.default do
|
266
|
+
Datadog::Tracing::Contrib::SpanAttributeSchema.fetch_service_name(
|
267
|
+
"DD_TRACE_HTTPX_SERVICE_NAME",
|
268
|
+
"httpx"
|
269
|
+
)
|
270
|
+
end
|
271
|
+
o.lazy unless Gem::Version.new(DATADOG_VERSION::STRING) >= Gem::Version.new("1.13.0")
|
272
|
+
end
|
273
|
+
else
|
274
|
+
option :service_name do |o|
|
275
|
+
o.default do
|
276
|
+
ENV.fetch("DD_TRACE_HTTPX_SERVICE_NAME", "httpx")
|
277
|
+
end
|
278
|
+
o.lazy unless Gem::Version.new(DATADOG_VERSION::STRING) >= Gem::Version.new("1.13.0")
|
279
|
+
end
|
194
280
|
end
|
195
281
|
|
196
|
-
option :
|
282
|
+
option :distributed_tracing, default: true
|
283
|
+
|
284
|
+
if Gem::Version.new(DATADOG_VERSION::STRING) >= Gem::Version.new("1.15.0")
|
285
|
+
option :error_handler do |o|
|
286
|
+
o.type :proc
|
287
|
+
o.default_proc(&DEFAULT_ERROR_HANDLER)
|
288
|
+
end
|
289
|
+
elsif Gem::Version.new(DATADOG_VERSION::STRING) >= Gem::Version.new("1.13.0")
|
290
|
+
option :error_handler do |o|
|
291
|
+
o.type :proc
|
292
|
+
o.experimental_default_proc(&DEFAULT_ERROR_HANDLER)
|
293
|
+
end
|
294
|
+
else
|
295
|
+
option :error_handler, default: DEFAULT_ERROR_HANDLER
|
296
|
+
end
|
197
297
|
end
|
198
298
|
end
|
199
299
|
|
200
300
|
# Patcher enables patching of 'httpx' with datadog components.
|
201
301
|
#
|
202
302
|
module Patcher
|
203
|
-
include
|
303
|
+
include Datadog::Tracing::Contrib::Patcher
|
204
304
|
|
205
305
|
module_function
|
206
306
|
|
@@ -223,7 +323,6 @@ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
|
|
223
323
|
class Integration
|
224
324
|
include Contrib::Integration
|
225
325
|
|
226
|
-
# MINIMUM_VERSION = Gem::Version.new('0.11.0')
|
227
326
|
MINIMUM_VERSION = Gem::Version.new("0.10.2")
|
228
327
|
|
229
328
|
register_as :httpx
|
@@ -240,14 +339,8 @@ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
|
|
240
339
|
super && version >= MINIMUM_VERSION
|
241
340
|
end
|
242
341
|
|
243
|
-
|
244
|
-
|
245
|
-
Configuration::Settings.new
|
246
|
-
end
|
247
|
-
else
|
248
|
-
def default_configuration
|
249
|
-
Configuration::Settings.new
|
250
|
-
end
|
342
|
+
def new_configuration
|
343
|
+
Configuration::Settings.new
|
251
344
|
end
|
252
345
|
|
253
346
|
def patcher
|