opentelemetry-instrumentation-faraday 0.27.0 → 0.29.0
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/CHANGELOG.md +22 -14
- data/README.md +16 -0
- data/lib/opentelemetry/instrumentation/faraday/instrumentation.rb +54 -10
- data/lib/opentelemetry/instrumentation/faraday/middlewares/dup/tracer_middleware.rb +98 -0
- data/lib/opentelemetry/instrumentation/faraday/middlewares/old/tracer_middleware.rb +91 -0
- data/lib/opentelemetry/instrumentation/faraday/middlewares/stable/tracer_middleware.rb +91 -0
- data/lib/opentelemetry/instrumentation/faraday/patches/dup/connection.rb +29 -0
- data/lib/opentelemetry/instrumentation/faraday/patches/old/connection.rb +29 -0
- data/lib/opentelemetry/instrumentation/faraday/patches/stable/connection.rb +29 -0
- data/lib/opentelemetry/instrumentation/faraday/version.rb +1 -1
- metadata +12 -22
- data/lib/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware.rb +0 -89
- data/lib/opentelemetry/instrumentation/faraday/patches/connection.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b85e3681f3964e94c187ba4f13c261e49d65857fef62b7591a72d14355086d70
|
4
|
+
data.tar.gz: 0ff2b06c0b51e59e1331d923079ed97598b39a17f8bc964d3caaf1d0e7ef1812
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 573d2502499da5b6a1281962358b02284413074f42a37d74fa22e7ca76f450eae533fe0c93406e6a0265afda1f3bc6c6129e126e0eeec42d6d0c4db38cf67eb7
|
7
|
+
data.tar.gz: cf22b7a0da102962250a603db1705b3ad4588e50ea9f322595e5511646bc9af284c20e319543b252ed170c03cac4057c950d165ff12bf786085a666fe2bded18
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Release History: opentelemetry-instrumentation-faraday
|
2
2
|
|
3
|
+
### v0.29.0 / 2025-09-30
|
4
|
+
|
5
|
+
* ADDED: Bump minimum API Version to 1.7
|
6
|
+
|
7
|
+
### v0.28.0 / 2025-08-13
|
8
|
+
|
9
|
+
* ADDED: Add Faraday `OTEL_SEMCONV_STABILITY_OPT_IN` environment variable [#1592](https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/1592)
|
10
|
+
|
3
11
|
### v0.27.0 / 2025-06-03
|
4
12
|
|
5
13
|
* ADDED: Suppress internal spans with Faraday instrumentation
|
@@ -64,25 +72,25 @@
|
|
64
72
|
|
65
73
|
### v0.23.1 / 2023-06-05
|
66
74
|
|
67
|
-
* FIXED: Base config options
|
75
|
+
* FIXED: Base config options
|
68
76
|
|
69
77
|
### v0.23.0 / 2023-04-17
|
70
78
|
|
71
|
-
* BREAKING CHANGE: Drop support for EoL Ruby 2.7
|
79
|
+
* BREAKING CHANGE: Drop support for EoL Ruby 2.7
|
72
80
|
|
73
|
-
* ADDED: Drop support for EoL Ruby 2.7
|
81
|
+
* ADDED: Drop support for EoL Ruby 2.7
|
74
82
|
|
75
83
|
### v0.22.0 / 2023-01-14
|
76
84
|
|
77
|
-
* ADDED: Add request/response hooks to more http clients
|
78
|
-
* FIXED: Stop leaking basic authentication credentials in Faraday instrumentation
|
79
|
-
* DOCS: Fix gem homepage
|
80
|
-
* DOCS: More gem documentation fixes
|
85
|
+
* ADDED: Add request/response hooks to more http clients
|
86
|
+
* FIXED: Stop leaking basic authentication credentials in Faraday instrumentation
|
87
|
+
* DOCS: Fix gem homepage
|
88
|
+
* DOCS: More gem documentation fixes
|
81
89
|
|
82
90
|
### v0.21.0 / 2022-06-09
|
83
91
|
|
84
92
|
* Upgrading Base dependency version
|
85
|
-
* FIXED: Broken test file requirements
|
93
|
+
* FIXED: Broken test file requirements
|
86
94
|
|
87
95
|
### v0.20.1 / 2022-05-03
|
88
96
|
|
@@ -90,8 +98,8 @@
|
|
90
98
|
|
91
99
|
### v0.20.0 / 2022-02-02
|
92
100
|
|
93
|
-
* ADDED: Add net.peer.name to faraday instrumentation
|
94
|
-
* FIXED: Excessive hash creation on context attr merging
|
101
|
+
* ADDED: Add net.peer.name to faraday instrumentation
|
102
|
+
* FIXED: Excessive hash creation on context attr merging
|
95
103
|
|
96
104
|
### v0.19.3 / 2021-12-02
|
97
105
|
|
@@ -103,17 +111,17 @@
|
|
103
111
|
|
104
112
|
### v0.19.1 / 2021-08-12
|
105
113
|
|
106
|
-
* DOCS: Update docs to rely more on environment variable configuration
|
114
|
+
* DOCS: Update docs to rely more on environment variable configuration
|
107
115
|
|
108
116
|
### v0.19.0 / 2021-06-23
|
109
117
|
|
110
|
-
* BREAKING CHANGE: Total order constraint on span.status=
|
118
|
+
* BREAKING CHANGE: Total order constraint on span.status=
|
111
119
|
|
112
|
-
* FIXED: Total order constraint on span.status=
|
120
|
+
* FIXED: Total order constraint on span.status=
|
113
121
|
|
114
122
|
### v0.18.1 / 2021-06-08
|
115
123
|
|
116
|
-
* FIXED: Missing require to common in faraday
|
124
|
+
* FIXED: Missing require to common in faraday
|
117
125
|
|
118
126
|
### v0.18.0 / 2021-05-21
|
119
127
|
|
data/README.md
CHANGED
@@ -59,3 +59,19 @@ Apache 2.0 license. See [LICENSE][license-github] for more information.
|
|
59
59
|
[community-meetings]: https://github.com/open-telemetry/community#community-meetings
|
60
60
|
[slack-channel]: https://cloud-native.slack.com/archives/C01NWKKMKMY
|
61
61
|
[discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions
|
62
|
+
|
63
|
+
## HTTP semantic convention stability
|
64
|
+
|
65
|
+
In the OpenTelemetry ecosystem, HTTP semantic conventions have now reached a stable state. However, the initial Faraday instrumentation was introduced before this stability was achieved, which resulted in HTTP attributes being based on an older version of the semantic conventions.
|
66
|
+
|
67
|
+
To facilitate the migration to stable semantic conventions, you can use the `OTEL_SEMCONV_STABILITY_OPT_IN` environment variable. This variable allows you to opt-in to the new stable conventions, ensuring compatibility and future-proofing your instrumentation.
|
68
|
+
|
69
|
+
When setting the value for `OTEL_SEMCONV_STABILITY_OPT_IN`, you can specify which conventions you wish to adopt:
|
70
|
+
|
71
|
+
- `http` - Emits the stable HTTP and networking conventions and ceases emitting the old conventions previously emitted by the instrumentation.
|
72
|
+
- `http/dup` - Emits both the old and stable HTTP and networking conventions, enabling a phased rollout of the stable semantic conventions.
|
73
|
+
- Default behavior (in the absence of either value) is to continue emitting the old HTTP and networking conventions the instrumentation previously emitted.
|
74
|
+
|
75
|
+
During the transition from old to stable conventions, Faraday instrumentation code comes in three patch versions: `dup`, `old`, and `stable`. These versions are identical except for the attributes they send. Any changes to Faraday instrumentation should consider all three patches.
|
76
|
+
|
77
|
+
For additional information on migration, please refer to our [documentation](https://opentelemetry.io/docs/specs/semconv/non-normative/http-migration/).
|
@@ -13,9 +13,10 @@ module OpenTelemetry
|
|
13
13
|
MINIMUM_VERSION = Gem::Version.new('1.0')
|
14
14
|
|
15
15
|
install do |_config|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
patch_type = determine_semconv
|
17
|
+
send(:"require_dependencies_#{patch_type}")
|
18
|
+
send(:"register_tracer_middleware_#{patch_type}")
|
19
|
+
send(:"use_middleware_by_default_#{patch_type}")
|
19
20
|
end
|
20
21
|
|
21
22
|
compatible do
|
@@ -36,19 +37,62 @@ module OpenTelemetry
|
|
36
37
|
Gem::Version.new(::Faraday::VERSION)
|
37
38
|
end
|
38
39
|
|
39
|
-
def
|
40
|
-
|
41
|
-
|
40
|
+
def determine_semconv
|
41
|
+
stability_opt_in = ENV.fetch('OTEL_SEMCONV_STABILITY_OPT_IN', '')
|
42
|
+
values = stability_opt_in.split(',').map(&:strip)
|
43
|
+
|
44
|
+
if values.include?('http/dup')
|
45
|
+
'dup'
|
46
|
+
elsif values.include?('http')
|
47
|
+
'stable'
|
48
|
+
else
|
49
|
+
'old'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def require_dependencies_dup
|
54
|
+
require_relative 'middlewares/dup/tracer_middleware'
|
55
|
+
require_relative 'patches/dup/connection'
|
56
|
+
end
|
57
|
+
|
58
|
+
def require_dependencies_old
|
59
|
+
require_relative 'middlewares/old/tracer_middleware'
|
60
|
+
require_relative 'patches/old/connection'
|
42
61
|
end
|
43
62
|
|
44
|
-
def
|
63
|
+
def require_dependencies_stable
|
64
|
+
require_relative 'middlewares/stable/tracer_middleware'
|
65
|
+
require_relative 'patches/stable/connection'
|
66
|
+
end
|
67
|
+
|
68
|
+
def register_tracer_middleware_dup
|
45
69
|
::Faraday::Middleware.register_middleware(
|
46
|
-
open_telemetry: Middlewares::TracerMiddleware
|
70
|
+
open_telemetry: Middlewares::Dup::TracerMiddleware
|
47
71
|
)
|
48
72
|
end
|
49
73
|
|
50
|
-
def
|
51
|
-
::Faraday::
|
74
|
+
def register_tracer_middleware_old
|
75
|
+
::Faraday::Middleware.register_middleware(
|
76
|
+
open_telemetry: Middlewares::Old::TracerMiddleware
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
def register_tracer_middleware_stable
|
81
|
+
::Faraday::Middleware.register_middleware(
|
82
|
+
open_telemetry: Middlewares::Stable::TracerMiddleware
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
def use_middleware_by_default_dup
|
87
|
+
::Faraday::Connection.prepend(Patches::Dup::Connection)
|
88
|
+
end
|
89
|
+
|
90
|
+
def use_middleware_by_default_old
|
91
|
+
::Faraday::Connection.prepend(Patches::Old::Connection)
|
92
|
+
end
|
93
|
+
|
94
|
+
def use_middleware_by_default_stable
|
95
|
+
::Faraday::Connection.prepend(Patches::Stable::Connection)
|
52
96
|
end
|
53
97
|
end
|
54
98
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
module OpenTelemetry
|
8
|
+
module Instrumentation
|
9
|
+
module Faraday
|
10
|
+
module Middlewares
|
11
|
+
module Dup
|
12
|
+
# TracerMiddleware propagates context and instruments Faraday requests
|
13
|
+
# by way of its middleware system
|
14
|
+
class TracerMiddleware < ::Faraday::Middleware
|
15
|
+
HTTP_METHODS_SYMBOL_TO_STRING = {
|
16
|
+
connect: 'CONNECT',
|
17
|
+
delete: 'DELETE',
|
18
|
+
get: 'GET',
|
19
|
+
head: 'HEAD',
|
20
|
+
options: 'OPTIONS',
|
21
|
+
patch: 'PATCH',
|
22
|
+
post: 'POST',
|
23
|
+
put: 'PUT',
|
24
|
+
trace: 'TRACE'
|
25
|
+
}.freeze
|
26
|
+
|
27
|
+
# Constant for the HTTP status range
|
28
|
+
HTTP_STATUS_SUCCESS_RANGE = (100..399)
|
29
|
+
|
30
|
+
def call(env)
|
31
|
+
http_method = HTTP_METHODS_SYMBOL_TO_STRING[env.method]
|
32
|
+
config = Faraday::Instrumentation.instance.config
|
33
|
+
|
34
|
+
attributes = span_creation_attributes(
|
35
|
+
http_method: http_method, url: env.url, config: config
|
36
|
+
)
|
37
|
+
|
38
|
+
OpenTelemetry::Common::HTTP::ClientContext.with_attributes(attributes) do |attrs, _|
|
39
|
+
tracer.in_span(
|
40
|
+
http_method, attributes: attrs, kind: config.fetch(:span_kind)
|
41
|
+
) do |span|
|
42
|
+
OpenTelemetry.propagation.inject(env.request_headers)
|
43
|
+
|
44
|
+
if config[:enable_internal_instrumentation] == false
|
45
|
+
OpenTelemetry::Common::Utilities.untraced do
|
46
|
+
app.call(env).on_complete { |resp| trace_response(span, resp.status) }
|
47
|
+
end
|
48
|
+
else
|
49
|
+
app.call(env).on_complete { |resp| trace_response(span, resp.status) }
|
50
|
+
end
|
51
|
+
rescue ::Faraday::Error => e
|
52
|
+
trace_response(span, e.response[:status]) if e.response
|
53
|
+
|
54
|
+
raise
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def span_creation_attributes(http_method:, url:, config:)
|
62
|
+
cleansed_url = OpenTelemetry::Common::Utilities.cleanse_url(url.to_s)
|
63
|
+
attrs = {
|
64
|
+
'http.method' => http_method,
|
65
|
+
'http.request.method' => http_method,
|
66
|
+
'http.url' => cleansed_url,
|
67
|
+
'url.full' => cleansed_url,
|
68
|
+
'faraday.adapter.name' => app.class.name
|
69
|
+
}
|
70
|
+
if url.host
|
71
|
+
attrs['net.peer.name'] = url.host
|
72
|
+
attrs['server.address'] = url.host
|
73
|
+
end
|
74
|
+
attrs['peer.service'] = config[:peer_service] if config[:peer_service]
|
75
|
+
|
76
|
+
attrs.merge!(
|
77
|
+
OpenTelemetry::Common::HTTP::ClientContext.attributes
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Versions prior to 1.0 do not define an accessor for app
|
82
|
+
attr_reader :app if Gem::Version.new(Faraday::VERSION) < Gem::Version.new('1.0.0')
|
83
|
+
|
84
|
+
def tracer
|
85
|
+
Faraday::Instrumentation.instance.tracer
|
86
|
+
end
|
87
|
+
|
88
|
+
def trace_response(span, status)
|
89
|
+
span.set_attribute('http.status_code', status)
|
90
|
+
span.set_attribute('http.response.status_code', status)
|
91
|
+
span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(status.to_i)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
module OpenTelemetry
|
8
|
+
module Instrumentation
|
9
|
+
module Faraday
|
10
|
+
module Middlewares
|
11
|
+
module Old
|
12
|
+
# TracerMiddleware propagates context and instruments Faraday requests
|
13
|
+
# by way of its middleware system
|
14
|
+
class TracerMiddleware < ::Faraday::Middleware
|
15
|
+
HTTP_METHODS_SYMBOL_TO_STRING = {
|
16
|
+
connect: 'CONNECT',
|
17
|
+
delete: 'DELETE',
|
18
|
+
get: 'GET',
|
19
|
+
head: 'HEAD',
|
20
|
+
options: 'OPTIONS',
|
21
|
+
patch: 'PATCH',
|
22
|
+
post: 'POST',
|
23
|
+
put: 'PUT',
|
24
|
+
trace: 'TRACE'
|
25
|
+
}.freeze
|
26
|
+
|
27
|
+
# Constant for the HTTP status range
|
28
|
+
HTTP_STATUS_SUCCESS_RANGE = (100..399)
|
29
|
+
|
30
|
+
def call(env)
|
31
|
+
http_method = HTTP_METHODS_SYMBOL_TO_STRING[env.method]
|
32
|
+
config = Faraday::Instrumentation.instance.config
|
33
|
+
|
34
|
+
attributes = span_creation_attributes(
|
35
|
+
http_method: http_method, url: env.url, config: config
|
36
|
+
)
|
37
|
+
|
38
|
+
OpenTelemetry::Common::HTTP::ClientContext.with_attributes(attributes) do |attrs, _|
|
39
|
+
tracer.in_span(
|
40
|
+
"HTTP #{http_method}", attributes: attrs, kind: config.fetch(:span_kind)
|
41
|
+
) do |span|
|
42
|
+
OpenTelemetry.propagation.inject(env.request_headers)
|
43
|
+
|
44
|
+
if config[:enable_internal_instrumentation] == false
|
45
|
+
OpenTelemetry::Common::Utilities.untraced do
|
46
|
+
app.call(env).on_complete { |resp| trace_response(span, resp.status) }
|
47
|
+
end
|
48
|
+
else
|
49
|
+
app.call(env).on_complete { |resp| trace_response(span, resp.status) }
|
50
|
+
end
|
51
|
+
rescue ::Faraday::Error => e
|
52
|
+
trace_response(span, e.response[:status]) if e.response
|
53
|
+
|
54
|
+
raise
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def span_creation_attributes(http_method:, url:, config:)
|
62
|
+
attrs = {
|
63
|
+
'http.method' => http_method,
|
64
|
+
'http.url' => OpenTelemetry::Common::Utilities.cleanse_url(url.to_s),
|
65
|
+
'faraday.adapter.name' => app.class.name
|
66
|
+
}
|
67
|
+
attrs['net.peer.name'] = url.host if url.host
|
68
|
+
attrs['peer.service'] = config[:peer_service] if config[:peer_service]
|
69
|
+
|
70
|
+
attrs.merge!(
|
71
|
+
OpenTelemetry::Common::HTTP::ClientContext.attributes
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Versions prior to 1.0 do not define an accessor for app
|
76
|
+
attr_reader :app if Gem::Version.new(Faraday::VERSION) < Gem::Version.new('1.0.0')
|
77
|
+
|
78
|
+
def tracer
|
79
|
+
Faraday::Instrumentation.instance.tracer
|
80
|
+
end
|
81
|
+
|
82
|
+
def trace_response(span, status)
|
83
|
+
span.set_attribute('http.status_code', status)
|
84
|
+
span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(status.to_i)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
module OpenTelemetry
|
8
|
+
module Instrumentation
|
9
|
+
module Faraday
|
10
|
+
module Middlewares
|
11
|
+
module Stable
|
12
|
+
# TracerMiddleware propagates context and instruments Faraday requests
|
13
|
+
# by way of its middleware system
|
14
|
+
class TracerMiddleware < ::Faraday::Middleware
|
15
|
+
HTTP_METHODS_SYMBOL_TO_STRING = {
|
16
|
+
connect: 'CONNECT',
|
17
|
+
delete: 'DELETE',
|
18
|
+
get: 'GET',
|
19
|
+
head: 'HEAD',
|
20
|
+
options: 'OPTIONS',
|
21
|
+
patch: 'PATCH',
|
22
|
+
post: 'POST',
|
23
|
+
put: 'PUT',
|
24
|
+
trace: 'TRACE'
|
25
|
+
}.freeze
|
26
|
+
|
27
|
+
# Constant for the HTTP status range
|
28
|
+
HTTP_STATUS_SUCCESS_RANGE = (100..399)
|
29
|
+
|
30
|
+
def call(env)
|
31
|
+
http_method = HTTP_METHODS_SYMBOL_TO_STRING[env.method]
|
32
|
+
config = Faraday::Instrumentation.instance.config
|
33
|
+
|
34
|
+
attributes = span_creation_attributes(
|
35
|
+
http_method: http_method, url: env.url, config: config
|
36
|
+
)
|
37
|
+
|
38
|
+
OpenTelemetry::Common::HTTP::ClientContext.with_attributes(attributes) do |attrs, _|
|
39
|
+
tracer.in_span(
|
40
|
+
http_method, attributes: attrs, kind: config.fetch(:span_kind)
|
41
|
+
) do |span|
|
42
|
+
OpenTelemetry.propagation.inject(env.request_headers)
|
43
|
+
|
44
|
+
if config[:enable_internal_instrumentation] == false
|
45
|
+
OpenTelemetry::Common::Utilities.untraced do
|
46
|
+
app.call(env).on_complete { |resp| trace_response(span, resp.status) }
|
47
|
+
end
|
48
|
+
else
|
49
|
+
app.call(env).on_complete { |resp| trace_response(span, resp.status) }
|
50
|
+
end
|
51
|
+
rescue ::Faraday::Error => e
|
52
|
+
trace_response(span, e.response[:status]) if e.response
|
53
|
+
|
54
|
+
raise
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def span_creation_attributes(http_method:, url:, config:)
|
62
|
+
attrs = {
|
63
|
+
'http.request.method' => http_method,
|
64
|
+
'url.full' => OpenTelemetry::Common::Utilities.cleanse_url(url.to_s),
|
65
|
+
'faraday.adapter.name' => app.class.name
|
66
|
+
}
|
67
|
+
attrs['server.address'] = url.host if url.host
|
68
|
+
attrs['peer.service'] = config[:peer_service] if config[:peer_service]
|
69
|
+
|
70
|
+
attrs.merge!(
|
71
|
+
OpenTelemetry::Common::HTTP::ClientContext.attributes
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Versions prior to 1.0 do not define an accessor for app
|
76
|
+
attr_reader :app if Gem::Version.new(Faraday::VERSION) < Gem::Version.new('1.0.0')
|
77
|
+
|
78
|
+
def tracer
|
79
|
+
Faraday::Instrumentation.instance.tracer
|
80
|
+
end
|
81
|
+
|
82
|
+
def trace_response(span, status)
|
83
|
+
span.set_attribute('http.response.status_code', status)
|
84
|
+
span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(status.to_i)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
module OpenTelemetry
|
8
|
+
module Instrumentation
|
9
|
+
module Faraday
|
10
|
+
module Patches
|
11
|
+
module Dup
|
12
|
+
# Module to be prepended to force Faraday to use the middleware by
|
13
|
+
# default so the user doesn't have to call `use` for every connection.
|
14
|
+
module Connection
|
15
|
+
# Wraps Faraday::Connection#initialize:
|
16
|
+
# https://github.com/lostisland/faraday/blob/ff9dc1d1219a1bbdba95a9a4cf5d135b97247ee2/lib/faraday/connection.rb#L62-L92
|
17
|
+
def initialize(...)
|
18
|
+
super.tap do
|
19
|
+
use(:open_telemetry) unless builder.handlers.any? do |handler|
|
20
|
+
handler.klass == Middlewares::Dup::TracerMiddleware
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
module OpenTelemetry
|
8
|
+
module Instrumentation
|
9
|
+
module Faraday
|
10
|
+
module Patches
|
11
|
+
module Old
|
12
|
+
# Module to be prepended to force Faraday to use the middleware by
|
13
|
+
# default so the user doesn't have to call `use` for every connection.
|
14
|
+
module Connection
|
15
|
+
# Wraps Faraday::Connection#initialize:
|
16
|
+
# https://github.com/lostisland/faraday/blob/ff9dc1d1219a1bbdba95a9a4cf5d135b97247ee2/lib/faraday/connection.rb#L62-L92
|
17
|
+
def initialize(...)
|
18
|
+
super.tap do
|
19
|
+
use(:open_telemetry) unless builder.handlers.any? do |handler|
|
20
|
+
handler.klass == Middlewares::Old::TracerMiddleware
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright The OpenTelemetry Authors
|
4
|
+
#
|
5
|
+
# SPDX-License-Identifier: Apache-2.0
|
6
|
+
|
7
|
+
module OpenTelemetry
|
8
|
+
module Instrumentation
|
9
|
+
module Faraday
|
10
|
+
module Patches
|
11
|
+
module Stable
|
12
|
+
# Module to be prepended to force Faraday to use the middleware by
|
13
|
+
# default so the user doesn't have to call `use` for every connection.
|
14
|
+
module Connection
|
15
|
+
# Wraps Faraday::Connection#initialize:
|
16
|
+
# https://github.com/lostisland/faraday/blob/ff9dc1d1219a1bbdba95a9a4cf5d135b97247ee2/lib/faraday/connection.rb#L62-L92
|
17
|
+
def initialize(...)
|
18
|
+
super.tap do
|
19
|
+
use(:open_telemetry) unless builder.handlers.any? do |handler|
|
20
|
+
handler.klass == Middlewares::Stable::TracerMiddleware
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opentelemetry-instrumentation-faraday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.29.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OpenTelemetry Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: opentelemetry-api
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: opentelemetry-instrumentation-base
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - "~>"
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.23
|
19
|
+
version: '0.23'
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.23
|
26
|
+
version: '0.23'
|
41
27
|
description: Faraday instrumentation for the OpenTelemetry framework
|
42
28
|
email:
|
43
29
|
- cncf-opentelemetry-contributors@lists.cncf.io
|
@@ -53,17 +39,21 @@ files:
|
|
53
39
|
- lib/opentelemetry/instrumentation.rb
|
54
40
|
- lib/opentelemetry/instrumentation/faraday.rb
|
55
41
|
- lib/opentelemetry/instrumentation/faraday/instrumentation.rb
|
56
|
-
- lib/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware.rb
|
57
|
-
- lib/opentelemetry/instrumentation/faraday/
|
42
|
+
- lib/opentelemetry/instrumentation/faraday/middlewares/dup/tracer_middleware.rb
|
43
|
+
- lib/opentelemetry/instrumentation/faraday/middlewares/old/tracer_middleware.rb
|
44
|
+
- lib/opentelemetry/instrumentation/faraday/middlewares/stable/tracer_middleware.rb
|
45
|
+
- lib/opentelemetry/instrumentation/faraday/patches/dup/connection.rb
|
46
|
+
- lib/opentelemetry/instrumentation/faraday/patches/old/connection.rb
|
47
|
+
- lib/opentelemetry/instrumentation/faraday/patches/stable/connection.rb
|
58
48
|
- lib/opentelemetry/instrumentation/faraday/version.rb
|
59
49
|
homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
|
60
50
|
licenses:
|
61
51
|
- Apache-2.0
|
62
52
|
metadata:
|
63
|
-
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-faraday/0.
|
53
|
+
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-faraday/0.29.0/file/CHANGELOG.md
|
64
54
|
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/faraday
|
65
55
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
|
66
|
-
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-faraday/0.
|
56
|
+
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-faraday/0.29.0
|
67
57
|
post_install_message:
|
68
58
|
rdoc_options: []
|
69
59
|
require_paths:
|
@@ -1,89 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright The OpenTelemetry Authors
|
4
|
-
#
|
5
|
-
# SPDX-License-Identifier: Apache-2.0
|
6
|
-
|
7
|
-
module OpenTelemetry
|
8
|
-
module Instrumentation
|
9
|
-
module Faraday
|
10
|
-
module Middlewares
|
11
|
-
# TracerMiddleware propagates context and instruments Faraday requests
|
12
|
-
# by way of its middleware system
|
13
|
-
class TracerMiddleware < ::Faraday::Middleware
|
14
|
-
HTTP_METHODS_SYMBOL_TO_STRING = {
|
15
|
-
connect: 'CONNECT',
|
16
|
-
delete: 'DELETE',
|
17
|
-
get: 'GET',
|
18
|
-
head: 'HEAD',
|
19
|
-
options: 'OPTIONS',
|
20
|
-
patch: 'PATCH',
|
21
|
-
post: 'POST',
|
22
|
-
put: 'PUT',
|
23
|
-
trace: 'TRACE'
|
24
|
-
}.freeze
|
25
|
-
|
26
|
-
# Constant for the HTTP status range
|
27
|
-
HTTP_STATUS_SUCCESS_RANGE = (100..399)
|
28
|
-
|
29
|
-
def call(env)
|
30
|
-
http_method = HTTP_METHODS_SYMBOL_TO_STRING[env.method]
|
31
|
-
config = Faraday::Instrumentation.instance.config
|
32
|
-
|
33
|
-
attributes = span_creation_attributes(
|
34
|
-
http_method: http_method, url: env.url, config: config
|
35
|
-
)
|
36
|
-
|
37
|
-
OpenTelemetry::Common::HTTP::ClientContext.with_attributes(attributes) do |attrs, _|
|
38
|
-
tracer.in_span(
|
39
|
-
"HTTP #{http_method}", attributes: attrs, kind: config.fetch(:span_kind)
|
40
|
-
) do |span|
|
41
|
-
OpenTelemetry.propagation.inject(env.request_headers)
|
42
|
-
|
43
|
-
if config[:enable_internal_instrumentation] == false
|
44
|
-
OpenTelemetry::Common::Utilities.untraced do
|
45
|
-
app.call(env).on_complete { |resp| trace_response(span, resp.status) }
|
46
|
-
end
|
47
|
-
else
|
48
|
-
app.call(env).on_complete { |resp| trace_response(span, resp.status) }
|
49
|
-
end
|
50
|
-
rescue ::Faraday::Error => e
|
51
|
-
trace_response(span, e.response[:status]) if e.response
|
52
|
-
|
53
|
-
raise
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def span_creation_attributes(http_method:, url:, config:)
|
61
|
-
attrs = {
|
62
|
-
'http.method' => http_method,
|
63
|
-
'http.url' => OpenTelemetry::Common::Utilities.cleanse_url(url.to_s),
|
64
|
-
'faraday.adapter.name' => app.class.name
|
65
|
-
}
|
66
|
-
attrs['net.peer.name'] = url.host if url.host
|
67
|
-
attrs['peer.service'] = config[:peer_service] if config[:peer_service]
|
68
|
-
|
69
|
-
attrs.merge!(
|
70
|
-
OpenTelemetry::Common::HTTP::ClientContext.attributes
|
71
|
-
)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Versions prior to 1.0 do not define an accessor for app
|
75
|
-
attr_reader :app if Gem::Version.new(Faraday::VERSION) < Gem::Version.new('1.0.0')
|
76
|
-
|
77
|
-
def tracer
|
78
|
-
Faraday::Instrumentation.instance.tracer
|
79
|
-
end
|
80
|
-
|
81
|
-
def trace_response(span, status)
|
82
|
-
span.set_attribute('http.status_code', status)
|
83
|
-
span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(status.to_i)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright The OpenTelemetry Authors
|
4
|
-
#
|
5
|
-
# SPDX-License-Identifier: Apache-2.0
|
6
|
-
|
7
|
-
module OpenTelemetry
|
8
|
-
module Instrumentation
|
9
|
-
module Faraday
|
10
|
-
module Patches
|
11
|
-
# Module to be prepended to force Faraday to use the middleware by
|
12
|
-
# default so the user doesn't have to call `use` for every connection.
|
13
|
-
module Connection
|
14
|
-
# Wraps Faraday::Connection#initialize:
|
15
|
-
# https://github.com/lostisland/faraday/blob/ff9dc1d1219a1bbdba95a9a4cf5d135b97247ee2/lib/faraday/connection.rb#L62-L92
|
16
|
-
def initialize(...)
|
17
|
-
super.tap do
|
18
|
-
use(:open_telemetry) unless builder.handlers.any? do |handler|
|
19
|
-
handler.klass == Middlewares::TracerMiddleware
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|