opentelemetry-instrumentation-excon 0.21.3 → 0.22.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/CHANGELOG.md +10 -0
- data/lib/opentelemetry/instrumentation/concerns/untraced_hosts.rb +41 -0
- data/lib/opentelemetry/instrumentation/excon/instrumentation.rb +11 -2
- data/lib/opentelemetry/instrumentation/excon/middlewares/tracer_middleware.rb +43 -45
- data/lib/opentelemetry/instrumentation/excon/patches/socket.rb +58 -0
- data/lib/opentelemetry/instrumentation/excon/version.rb +1 -1
- metadata +10 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b87892c862be889edceb174a7ff433f1d17257ed8a470bef0f50923f7ac9dc7
|
4
|
+
data.tar.gz: 5f39a8e5bc953eed8b7bcb22e67cd9e208a2cbfc1ef1ff7bdec7ab3d5de9e8b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2212da81629c284a23335393c2971075ee0631e77c3b91bdc8846dccec7db1722df1aab8c5e449daafacfe533d7e23ace497b7f27825d0311afd5f796fbad371
|
7
|
+
data.tar.gz: e6d2b792891f3119229805584bc2e1f3ca3f94f2011600c6a2f16bc8168cb8126a2191d657dd65422a6041ad8641ef2131b79497ea0b6d7c3108d5b8a6867d7b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Release History: opentelemetry-instrumentation-excon
|
2
2
|
|
3
|
+
### v0.22.1 / 2024-04-30
|
4
|
+
|
5
|
+
* FIXED: Bundler conflict warnings
|
6
|
+
|
7
|
+
### v0.22.0 / 2023-11-28
|
8
|
+
|
9
|
+
* BREAKING CHANGE: Add a connect span to excon
|
10
|
+
|
11
|
+
* ADDED: Add a connect span to excon
|
12
|
+
|
3
13
|
### v0.21.3 / 2023-11-23
|
4
14
|
|
5
15
|
* CHANGED: Applied Rubocop Performance Recommendations [#727](https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/727)
|
@@ -0,0 +1,41 @@
|
|
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 Concerns
|
10
|
+
# The untraced hosts concerns allows instrumentation to skip traces on hostnames in an exclusion list.
|
11
|
+
# If the current OpenTelemetry context is untraced, all hosts will be treated as untraced.
|
12
|
+
# When included in a class that extends OpenTelemetry::Instrumentation::Base, this module defines an option named :untraced_hosts.
|
13
|
+
module UntracedHosts
|
14
|
+
def self.included(klass)
|
15
|
+
klass.instance_eval do
|
16
|
+
# untraced_hosts: if a request's address matches any of the `String`
|
17
|
+
# or `Regexp` in this array, the instrumentation will not record a
|
18
|
+
# `kind = :client` representing the request and will not propagate
|
19
|
+
# context in the request.
|
20
|
+
option :untraced_hosts, default: [], validate: :array
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Checks whether the given host should be treated as untraced.
|
25
|
+
# If the current OpenTelemetry context is untraced, all hosts will be treated as untraced.
|
26
|
+
# The given host must be a String.
|
27
|
+
def untraced?(host)
|
28
|
+
OpenTelemetry::Common::Utilities.untraced? || untraced_host?(host)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def untraced_host?(host)
|
34
|
+
config[:untraced_hosts].any? do |rule|
|
35
|
+
rule.is_a?(Regexp) ? rule.match?(host) : rule == host
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -4,15 +4,20 @@
|
|
4
4
|
#
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
6
6
|
|
7
|
+
require_relative '../concerns/untraced_hosts'
|
8
|
+
|
7
9
|
module OpenTelemetry
|
8
10
|
module Instrumentation
|
9
11
|
module Excon
|
10
12
|
# The Instrumentation class contains logic to detect and install the Excon
|
11
13
|
# instrumentation
|
12
14
|
class Instrumentation < OpenTelemetry::Instrumentation::Base
|
15
|
+
include OpenTelemetry::Instrumentation::Concerns::UntracedHosts
|
16
|
+
|
13
17
|
install do |_config|
|
14
18
|
require_dependencies
|
15
19
|
add_middleware
|
20
|
+
patch
|
16
21
|
end
|
17
22
|
|
18
23
|
present do
|
@@ -25,11 +30,15 @@ module OpenTelemetry
|
|
25
30
|
|
26
31
|
def require_dependencies
|
27
32
|
require_relative 'middlewares/tracer_middleware'
|
33
|
+
require_relative 'patches/socket'
|
28
34
|
end
|
29
35
|
|
30
36
|
def add_middleware
|
31
|
-
::Excon.defaults[:middlewares] =
|
32
|
-
|
37
|
+
::Excon.defaults[:middlewares] = Middlewares::TracerMiddleware.around_default_stack
|
38
|
+
end
|
39
|
+
|
40
|
+
def patch
|
41
|
+
::Excon::Socket.prepend(Patches::Socket)
|
33
42
|
end
|
34
43
|
end
|
35
44
|
end
|
@@ -22,24 +22,30 @@ module OpenTelemetry
|
|
22
22
|
end.freeze
|
23
23
|
|
24
24
|
def request_call(datum)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
25
|
+
return @stack.request_call(datum) if untraced?(datum)
|
26
|
+
|
27
|
+
http_method = HTTP_METHODS_TO_UPPERCASE[datum[:method]]
|
28
|
+
|
29
|
+
attributes = {
|
30
|
+
OpenTelemetry::SemanticConventions::Trace::HTTP_METHOD => http_method,
|
31
|
+
OpenTelemetry::SemanticConventions::Trace::HTTP_SCHEME => datum[:scheme],
|
32
|
+
OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET => datum[:path],
|
33
|
+
OpenTelemetry::SemanticConventions::Trace::HTTP_HOST => datum[:host],
|
34
|
+
OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => datum[:hostname],
|
35
|
+
OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => datum[:port]
|
36
|
+
}
|
37
|
+
|
38
|
+
peer_service = Excon::Instrumentation.instance.config[:peer_service]
|
39
|
+
attributes[OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = peer_service if peer_service
|
40
|
+
attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
|
41
|
+
|
42
|
+
span = tracer.start_span(HTTP_METHODS_TO_SPAN_NAMES[http_method], attributes: attributes, kind: :client)
|
43
|
+
ctx = OpenTelemetry::Trace.context_with_span(span)
|
44
|
+
|
45
|
+
datum[:otel_span] = span
|
46
|
+
datum[:otel_token] = OpenTelemetry::Context.attach(ctx)
|
47
|
+
|
48
|
+
OpenTelemetry.propagation.inject(datum[:headers])
|
43
49
|
|
44
50
|
@stack.request_call(datum)
|
45
51
|
end
|
@@ -71,43 +77,35 @@ module OpenTelemetry
|
|
71
77
|
private
|
72
78
|
|
73
79
|
def handle_response(datum)
|
74
|
-
|
75
|
-
|
76
|
-
return span if span.end_timestamp
|
80
|
+
datum.delete(:otel_span)&.tap do |span|
|
81
|
+
return unless span.recording?
|
77
82
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
span.status = OpenTelemetry::Trace::Status.error("Request has failed: #{datum[:error]}") if datum.key?(:error)
|
83
|
+
if datum.key?(:response)
|
84
|
+
response = datum[:response]
|
85
|
+
span.set_attribute(OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE, response[:status])
|
86
|
+
span.status = OpenTelemetry::Trace::Status.error unless (100..399).cover?(response[:status].to_i)
|
87
|
+
end
|
85
88
|
|
86
|
-
|
87
|
-
|
89
|
+
if datum.key?(:error)
|
90
|
+
span.status = OpenTelemetry::Trace::Status.error('Request has failed')
|
91
|
+
span.record_exception(datum[:error])
|
88
92
|
end
|
93
|
+
|
94
|
+
span.finish
|
95
|
+
|
96
|
+
OpenTelemetry::Context.detach(datum.delete(:otel_token)) if datum.include?(:otel_token)
|
89
97
|
end
|
90
98
|
rescue StandardError => e
|
91
|
-
OpenTelemetry.
|
92
|
-
end
|
93
|
-
|
94
|
-
def span_creation_attributes(datum, http_method)
|
95
|
-
instrumentation_attrs = {
|
96
|
-
'http.host' => datum[:host],
|
97
|
-
'http.method' => http_method,
|
98
|
-
'http.scheme' => datum[:scheme],
|
99
|
-
'http.target' => datum[:path]
|
100
|
-
}
|
101
|
-
config = Excon::Instrumentation.instance.config
|
102
|
-
instrumentation_attrs['peer.service'] = config[:peer_service] if config[:peer_service]
|
103
|
-
instrumentation_attrs.merge!(
|
104
|
-
OpenTelemetry::Common::HTTP::ClientContext.attributes
|
105
|
-
)
|
99
|
+
OpenTelemetry.handle_error(e)
|
106
100
|
end
|
107
101
|
|
108
102
|
def tracer
|
109
103
|
Excon::Instrumentation.instance.tracer
|
110
104
|
end
|
105
|
+
|
106
|
+
def untraced?(datum)
|
107
|
+
datum.key?(:otel_span) || Excon::Instrumentation.instance.untraced?(datum[:host])
|
108
|
+
end
|
111
109
|
end
|
112
110
|
end
|
113
111
|
end
|
@@ -0,0 +1,58 @@
|
|
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 Excon
|
10
|
+
module Patches
|
11
|
+
# Module to prepend to an Excon Socket for instrumentation
|
12
|
+
module Socket
|
13
|
+
private
|
14
|
+
|
15
|
+
def connect
|
16
|
+
return super if untraced?
|
17
|
+
|
18
|
+
if @data[:proxy]
|
19
|
+
conn_address = @data.dig(:proxy, :hostname)
|
20
|
+
conn_port = @data.dig(:proxy, :port)
|
21
|
+
else
|
22
|
+
conn_address = @data[:hostname]
|
23
|
+
conn_port = @port
|
24
|
+
end
|
25
|
+
|
26
|
+
attributes = { OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => conn_address, OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => conn_port }.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
|
27
|
+
|
28
|
+
if is_a?(::Excon::SSLSocket) && @data[:proxy]
|
29
|
+
span_name = 'HTTP CONNECT'
|
30
|
+
span_kind = :client
|
31
|
+
else
|
32
|
+
span_name = 'connect'
|
33
|
+
span_kind = :internal
|
34
|
+
end
|
35
|
+
|
36
|
+
tracer.in_span(span_name, attributes: attributes, kind: span_kind) do
|
37
|
+
super
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def tracer
|
42
|
+
Excon::Instrumentation.instance.tracer
|
43
|
+
end
|
44
|
+
|
45
|
+
def untraced?
|
46
|
+
address = if @data[:proxy]
|
47
|
+
@data.dig(:proxy, :hostname)
|
48
|
+
else
|
49
|
+
@data[:hostname]
|
50
|
+
end
|
51
|
+
|
52
|
+
Excon::Instrumentation.instance.untraced?(address)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opentelemetry-instrumentation-excon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.22.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OpenTelemetry Authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opentelemetry-api
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '2.4'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: excon
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.71.0
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.71.0
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: minitest
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,28 +128,28 @@ dependencies:
|
|
142
128
|
requirements:
|
143
129
|
- - "~>"
|
144
130
|
- !ruby/object:Gem::Version
|
145
|
-
version: 1.
|
131
|
+
version: '1.62'
|
146
132
|
type: :development
|
147
133
|
prerelease: false
|
148
134
|
version_requirements: !ruby/object:Gem::Requirement
|
149
135
|
requirements:
|
150
136
|
- - "~>"
|
151
137
|
- !ruby/object:Gem::Version
|
152
|
-
version: 1.
|
138
|
+
version: '1.62'
|
153
139
|
- !ruby/object:Gem::Dependency
|
154
140
|
name: rubocop-performance
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|
156
142
|
requirements:
|
157
143
|
- - "~>"
|
158
144
|
- !ruby/object:Gem::Version
|
159
|
-
version: 1.
|
145
|
+
version: '1.20'
|
160
146
|
type: :development
|
161
147
|
prerelease: false
|
162
148
|
version_requirements: !ruby/object:Gem::Requirement
|
163
149
|
requirements:
|
164
150
|
- - "~>"
|
165
151
|
- !ruby/object:Gem::Version
|
166
|
-
version: 1.
|
152
|
+
version: '1.20'
|
167
153
|
- !ruby/object:Gem::Dependency
|
168
154
|
name: simplecov
|
169
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -219,18 +205,20 @@ files:
|
|
219
205
|
- README.md
|
220
206
|
- lib/opentelemetry-instrumentation-excon.rb
|
221
207
|
- lib/opentelemetry/instrumentation.rb
|
208
|
+
- lib/opentelemetry/instrumentation/concerns/untraced_hosts.rb
|
222
209
|
- lib/opentelemetry/instrumentation/excon.rb
|
223
210
|
- lib/opentelemetry/instrumentation/excon/instrumentation.rb
|
224
211
|
- lib/opentelemetry/instrumentation/excon/middlewares/tracer_middleware.rb
|
212
|
+
- lib/opentelemetry/instrumentation/excon/patches/socket.rb
|
225
213
|
- lib/opentelemetry/instrumentation/excon/version.rb
|
226
214
|
homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
|
227
215
|
licenses:
|
228
216
|
- Apache-2.0
|
229
217
|
metadata:
|
230
|
-
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-excon/0.
|
218
|
+
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-excon/0.22.1/file/CHANGELOG.md
|
231
219
|
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/excon
|
232
220
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
|
233
|
-
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-excon/0.
|
221
|
+
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-excon/0.22.1
|
234
222
|
post_install_message:
|
235
223
|
rdoc_options: []
|
236
224
|
require_paths:
|