opentelemetry-instrumentation-http 0.23.5 → 0.27.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 +45 -13
- data/README.md +17 -1
- data/lib/opentelemetry/instrumentation/http/http_helper.rb +86 -0
- data/lib/opentelemetry/instrumentation/http/instrumentation.rb +42 -8
- data/lib/opentelemetry/instrumentation/http/patches/dup/client.rb +88 -0
- data/lib/opentelemetry/instrumentation/http/patches/dup/connection.rb +40 -0
- data/lib/opentelemetry/instrumentation/http/patches/old/client.rb +76 -0
- data/lib/opentelemetry/instrumentation/http/patches/old/connection.rb +36 -0
- data/lib/opentelemetry/instrumentation/http/patches/stable/client.rb +79 -0
- data/lib/opentelemetry/instrumentation/http/patches/stable/connection.rb +36 -0
- data/lib/opentelemetry/instrumentation/http/version.rb +1 -1
- data/lib/opentelemetry/instrumentation/http.rb +1 -0
- metadata +18 -195
- data/lib/opentelemetry/instrumentation/http/patches/client.rb +0 -70
- data/lib/opentelemetry/instrumentation/http/patches/connection.rb +0 -33
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 850cb2d0a9d8d18cf00cade03d86e379a2338f626a0f1468e32b37c186de0869
|
|
4
|
+
data.tar.gz: d89c15de55426a730fdaef82e1b8212fa20981b645b9985f66712ceff7cab2b3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 676dd8c1071ed0c9f0927c6def794f71637919a3303be4df314ebfe2cdb8037f04e64c5ccbdc649326f51c920437714cd504699a59e26dbfeb33569aed5172e0
|
|
7
|
+
data.tar.gz: a681dc2912300b21a16e1d7d069cf8e35eb3f9899917e87f89522f15e7b949de8f963bb894eb5efd887cc0a2cd8120077b25b3c29dc125dd0beffd7a150e3bb8
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# Release History: opentelemetry-instrumentation-http
|
|
2
2
|
|
|
3
|
+
### v0.27.1 / 2025-11-25
|
|
4
|
+
|
|
5
|
+
* FIXED: Update support for unknown HTTP methods to match semantic conventions
|
|
6
|
+
|
|
7
|
+
### v0.27.0 / 2025-10-22
|
|
8
|
+
|
|
9
|
+
* BREAKING CHANGE: Min Ruby Version 3.2
|
|
10
|
+
|
|
11
|
+
* ADDED: Min Ruby Version 3.2
|
|
12
|
+
|
|
13
|
+
### v0.26.1 / 2025-09-30
|
|
14
|
+
|
|
15
|
+
* FIXED: Min OTel Ruby API 1.7
|
|
16
|
+
|
|
17
|
+
### v0.26.0 / 2025-09-30
|
|
18
|
+
|
|
19
|
+
* ADDED: Bump minimum API Version to 1.7
|
|
20
|
+
|
|
21
|
+
### v0.25.1 / 2025-07-01
|
|
22
|
+
|
|
23
|
+
* FIXED: Update span name when semconv stability is enabled
|
|
24
|
+
|
|
25
|
+
### v0.25.0 / 2025-06-17
|
|
26
|
+
|
|
27
|
+
* ADDED: Add `OTEL_SEMCONV_STABILITY_OPT_IN` environment variable [#1547](https://github.com/open-telemetry/opentelemetry-ruby-contrib/pull/1547)
|
|
28
|
+
|
|
29
|
+
### v0.24.0 / 2025-01-16
|
|
30
|
+
|
|
31
|
+
* BREAKING CHANGE: Set minimum supported version to Ruby 3.1
|
|
32
|
+
|
|
33
|
+
* ADDED: Set minimum supported version to Ruby 3.1
|
|
34
|
+
|
|
3
35
|
### v0.23.5 / 2024-11-26
|
|
4
36
|
|
|
5
37
|
* CHANGED: Performance Freeze all range objects #1222
|
|
@@ -18,28 +50,28 @@
|
|
|
18
50
|
|
|
19
51
|
### v0.23.1 / 2023-06-05
|
|
20
52
|
|
|
21
|
-
* FIXED: Base config options
|
|
53
|
+
* FIXED: Base config options
|
|
22
54
|
|
|
23
55
|
### v0.23.0 / 2023-05-15
|
|
24
56
|
|
|
25
|
-
* ADDED: Add span_preprocessor hook
|
|
57
|
+
* ADDED: Add span_preprocessor hook
|
|
26
58
|
|
|
27
59
|
### v0.22.0 / 2023-04-17
|
|
28
60
|
|
|
29
|
-
* BREAKING CHANGE: Drop support for EoL Ruby 2.7
|
|
61
|
+
* BREAKING CHANGE: Drop support for EoL Ruby 2.7
|
|
30
62
|
|
|
31
|
-
* ADDED: Drop support for EoL Ruby 2.7
|
|
63
|
+
* ADDED: Drop support for EoL Ruby 2.7
|
|
32
64
|
|
|
33
65
|
### v0.21.0 / 2023-01-14
|
|
34
66
|
|
|
35
|
-
* ADDED: Add request/response hooks to more http clients
|
|
36
|
-
* DOCS: Fix gem homepage
|
|
37
|
-
* DOCS: More gem documentation fixes
|
|
67
|
+
* ADDED: Add request/response hooks to more http clients
|
|
68
|
+
* DOCS: Fix gem homepage
|
|
69
|
+
* DOCS: More gem documentation fixes
|
|
38
70
|
|
|
39
71
|
### v0.20.0 / 2022-06-09
|
|
40
72
|
|
|
41
73
|
* Upgrading Base dependency version
|
|
42
|
-
* FIXED: Broken test file requirements
|
|
74
|
+
* FIXED: Broken test file requirements
|
|
43
75
|
|
|
44
76
|
### v0.19.6 / 2022-05-05
|
|
45
77
|
|
|
@@ -47,15 +79,15 @@
|
|
|
47
79
|
|
|
48
80
|
### v0.19.5 / 2022-05-02
|
|
49
81
|
|
|
50
|
-
* FIXED: RubyGems Fallback
|
|
82
|
+
* FIXED: RubyGems Fallback
|
|
51
83
|
|
|
52
84
|
### v0.19.4 / 2022-02-02
|
|
53
85
|
|
|
54
|
-
* FIXED: Excessive hash creation on context attr merging
|
|
86
|
+
* FIXED: Excessive hash creation on context attr merging
|
|
55
87
|
|
|
56
88
|
### v0.19.3 / 2021-12-01
|
|
57
89
|
|
|
58
|
-
* FIXED: Change net attribute names to match the semantic conventions spec for http
|
|
90
|
+
* FIXED: Change net attribute names to match the semantic conventions spec for http
|
|
59
91
|
|
|
60
92
|
### v0.19.2 / 2021-09-29
|
|
61
93
|
|
|
@@ -67,9 +99,9 @@
|
|
|
67
99
|
|
|
68
100
|
### v0.19.0 / 2021-06-23
|
|
69
101
|
|
|
70
|
-
* BREAKING CHANGE: Total order constraint on span.status=
|
|
102
|
+
* BREAKING CHANGE: Total order constraint on span.status=
|
|
71
103
|
|
|
72
|
-
* FIXED: Total order constraint on span.status=
|
|
104
|
+
* FIXED: Total order constraint on span.status=
|
|
73
105
|
|
|
74
106
|
### v0.18.0 / 2021-05-21
|
|
75
107
|
|
data/README.md
CHANGED
|
@@ -44,7 +44,7 @@ end
|
|
|
44
44
|
|
|
45
45
|
## Examples
|
|
46
46
|
|
|
47
|
-
Example usage can be seen in the `./example/trace_demonstration.rb` file
|
|
47
|
+
Example usage can be seen in the [`./example/trace_demonstration.rb` file](https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/instrumentation/http/example/trace_demonstration.rb)
|
|
48
48
|
|
|
49
49
|
## How can I get involved?
|
|
50
50
|
|
|
@@ -64,3 +64,19 @@ The `opentelemetry-instrumentation-http` gem is distributed under the Apache 2.0
|
|
|
64
64
|
[community-meetings]: https://github.com/open-telemetry/community#community-meetings
|
|
65
65
|
[slack-channel]: https://cloud-native.slack.com/archives/C01NWKKMKMY
|
|
66
66
|
[discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions
|
|
67
|
+
|
|
68
|
+
## HTTP semantic convention stability
|
|
69
|
+
|
|
70
|
+
In the OpenTelemetry ecosystem, HTTP semantic conventions have now reached a stable state. However, the initial HTTP instrumentation was introduced before this stability was achieved, which resulted in HTTP attributes being based on an older version of the semantic conventions.
|
|
71
|
+
|
|
72
|
+
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.
|
|
73
|
+
|
|
74
|
+
When setting the value for `OTEL_SEMCONV_STABILITY_OPT_IN`, you can specify which conventions you wish to adopt:
|
|
75
|
+
|
|
76
|
+
- `http` - Emits the stable HTTP and networking conventions and ceases emitting the old conventions previously emitted by the instrumentation.
|
|
77
|
+
- `http/dup` - Emits both the old and stable HTTP and networking conventions, enabling a phased rollout of the stable semantic conventions.
|
|
78
|
+
- Default behavior (in the absence of either value) is to continue emitting the old HTTP and networking conventions the instrumentation previously emitted.
|
|
79
|
+
|
|
80
|
+
During the transition from old to stable conventions, HTTP instrumentation code comes in three patch versions: `dup`, `old`, and `stable`. These versions are identical except for the attributes they send. Any changes to HTTP instrumentation should consider all three patches.
|
|
81
|
+
|
|
82
|
+
For additional information on migration, please refer to our [documentation](https://opentelemetry.io/docs/specs/semconv/non-normative/http-migration/).
|
|
@@ -0,0 +1,86 @@
|
|
|
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 HTTP
|
|
10
|
+
# Module for normalizing HTTP methods
|
|
11
|
+
# @api private
|
|
12
|
+
module HttpHelper
|
|
13
|
+
# Lightweight struct to hold span creation attributes
|
|
14
|
+
SpanCreationAttributes = Struct.new(:span_name, :normalized_method, :original_method, keyword_init: true)
|
|
15
|
+
|
|
16
|
+
# Pre-computed mapping to avoid string allocations during normalization
|
|
17
|
+
METHOD_CACHE = {
|
|
18
|
+
'CONNECT' => 'CONNECT',
|
|
19
|
+
'DELETE' => 'DELETE',
|
|
20
|
+
'GET' => 'GET',
|
|
21
|
+
'HEAD' => 'HEAD',
|
|
22
|
+
'OPTIONS' => 'OPTIONS',
|
|
23
|
+
'PATCH' => 'PATCH',
|
|
24
|
+
'POST' => 'POST',
|
|
25
|
+
'PUT' => 'PUT',
|
|
26
|
+
'TRACE' => 'TRACE',
|
|
27
|
+
'connect' => 'CONNECT',
|
|
28
|
+
'delete' => 'DELETE',
|
|
29
|
+
'get' => 'GET',
|
|
30
|
+
'head' => 'HEAD',
|
|
31
|
+
'options' => 'OPTIONS',
|
|
32
|
+
'patch' => 'PATCH',
|
|
33
|
+
'post' => 'POST',
|
|
34
|
+
'put' => 'PUT',
|
|
35
|
+
'trace' => 'TRACE',
|
|
36
|
+
:connect => 'CONNECT',
|
|
37
|
+
:delete => 'DELETE',
|
|
38
|
+
:get => 'GET',
|
|
39
|
+
:head => 'HEAD',
|
|
40
|
+
:options => 'OPTIONS',
|
|
41
|
+
:patch => 'PATCH',
|
|
42
|
+
:post => 'POST',
|
|
43
|
+
:put => 'PUT',
|
|
44
|
+
:trace => 'TRACE'
|
|
45
|
+
}.freeze
|
|
46
|
+
|
|
47
|
+
# Pre-computed span names for old semantic conventions to avoid allocations
|
|
48
|
+
OLD_SPAN_NAMES = {
|
|
49
|
+
'CONNECT' => 'HTTP CONNECT',
|
|
50
|
+
'DELETE' => 'HTTP DELETE',
|
|
51
|
+
'GET' => 'HTTP GET',
|
|
52
|
+
'HEAD' => 'HTTP HEAD',
|
|
53
|
+
'OPTIONS' => 'HTTP OPTIONS',
|
|
54
|
+
'PATCH' => 'HTTP PATCH',
|
|
55
|
+
'POST' => 'HTTP POST',
|
|
56
|
+
'PUT' => 'HTTP PUT',
|
|
57
|
+
'TRACE' => 'HTTP TRACE'
|
|
58
|
+
}.freeze
|
|
59
|
+
|
|
60
|
+
private_constant :METHOD_CACHE, :OLD_SPAN_NAMES
|
|
61
|
+
|
|
62
|
+
# Prepares all span data for the specified semantic convention in a single call
|
|
63
|
+
# @param method [String, Symbol] The HTTP method
|
|
64
|
+
# @param semconv [Symbol] The semantic convention to use (:stable or :old)
|
|
65
|
+
# @return [SpanCreationAttributes] struct containing span_name, normalized_method, and original_method
|
|
66
|
+
def self.span_attrs_for(method, semconv: :stable)
|
|
67
|
+
normalized = METHOD_CACHE[method]
|
|
68
|
+
if normalized
|
|
69
|
+
span_name = semconv == :old ? OLD_SPAN_NAMES[normalized] : normalized
|
|
70
|
+
SpanCreationAttributes.new(
|
|
71
|
+
span_name: span_name,
|
|
72
|
+
normalized_method: normalized,
|
|
73
|
+
original_method: nil
|
|
74
|
+
)
|
|
75
|
+
else
|
|
76
|
+
SpanCreationAttributes.new(
|
|
77
|
+
span_name: 'HTTP',
|
|
78
|
+
normalized_method: '_OTHER',
|
|
79
|
+
original_method: method.to_s
|
|
80
|
+
)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -10,8 +10,9 @@ module OpenTelemetry
|
|
|
10
10
|
# The Instrumentation class contains logic to detect and install the Http instrumentation
|
|
11
11
|
class Instrumentation < OpenTelemetry::Instrumentation::Base
|
|
12
12
|
install do |_config|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
patch_type = determine_semconv
|
|
14
|
+
send(:"require_dependencies_#{patch_type}")
|
|
15
|
+
send(:"patch_#{patch_type}")
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
present do
|
|
@@ -20,14 +21,47 @@ module OpenTelemetry
|
|
|
20
21
|
|
|
21
22
|
option :span_name_formatter, default: nil, validate: :callable
|
|
22
23
|
|
|
23
|
-
def
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
def determine_semconv
|
|
25
|
+
stability_opt_in = ENV.fetch('OTEL_SEMCONV_STABILITY_OPT_IN', '')
|
|
26
|
+
values = stability_opt_in.split(',').map(&:strip)
|
|
27
|
+
|
|
28
|
+
if values.include?('http/dup')
|
|
29
|
+
'dup'
|
|
30
|
+
elsif values.include?('http')
|
|
31
|
+
'stable'
|
|
32
|
+
else
|
|
33
|
+
'old'
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def patch_old
|
|
38
|
+
::HTTP::Client.prepend(Patches::Old::Client)
|
|
39
|
+
::HTTP::Connection.prepend(Patches::Old::Connection)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def patch_dup
|
|
43
|
+
::HTTP::Client.prepend(Patches::Dup::Client)
|
|
44
|
+
::HTTP::Connection.prepend(Patches::Dup::Connection)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def patch_stable
|
|
48
|
+
::HTTP::Client.prepend(Patches::Stable::Client)
|
|
49
|
+
::HTTP::Connection.prepend(Patches::Stable::Connection)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def require_dependencies_dup
|
|
53
|
+
require_relative 'patches/dup/client'
|
|
54
|
+
require_relative 'patches/dup/connection'
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def require_dependencies_old
|
|
58
|
+
require_relative 'patches/old/client'
|
|
59
|
+
require_relative 'patches/old/connection'
|
|
26
60
|
end
|
|
27
61
|
|
|
28
|
-
def
|
|
29
|
-
require_relative 'patches/client'
|
|
30
|
-
require_relative 'patches/connection'
|
|
62
|
+
def require_dependencies_stable
|
|
63
|
+
require_relative 'patches/stable/client'
|
|
64
|
+
require_relative 'patches/stable/connection'
|
|
31
65
|
end
|
|
32
66
|
end
|
|
33
67
|
end
|
|
@@ -0,0 +1,88 @@
|
|
|
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 HTTP
|
|
10
|
+
module Patches
|
|
11
|
+
# Module using old and stable HTTP semantic conventions
|
|
12
|
+
module Dup
|
|
13
|
+
# Module to prepend to HTTP::Client for instrumentation
|
|
14
|
+
module Client
|
|
15
|
+
# Constant for the HTTP status range
|
|
16
|
+
HTTP_STATUS_SUCCESS_RANGE = (100..399)
|
|
17
|
+
|
|
18
|
+
def perform(req, options)
|
|
19
|
+
span_data = HttpHelper.span_attrs_for(req.verb)
|
|
20
|
+
|
|
21
|
+
uri = req.uri
|
|
22
|
+
span_name = create_span_name(span_data, uri.path)
|
|
23
|
+
|
|
24
|
+
attributes = {
|
|
25
|
+
# old semconv
|
|
26
|
+
'http.method' => span_data.normalized_method,
|
|
27
|
+
'http.scheme' => uri.scheme,
|
|
28
|
+
'http.target' => uri.path,
|
|
29
|
+
'http.url' => "#{uri.scheme}://#{uri.host}",
|
|
30
|
+
'net.peer.name' => uri.host,
|
|
31
|
+
'net.peer.port' => uri.port,
|
|
32
|
+
# stable semconv
|
|
33
|
+
'http.request.method' => span_data.normalized_method,
|
|
34
|
+
'url.scheme' => uri.scheme,
|
|
35
|
+
'url.path' => uri.path,
|
|
36
|
+
'url.full' => "#{uri.scheme}://#{uri.host}",
|
|
37
|
+
'server.address' => uri.host,
|
|
38
|
+
'server.port' => uri.port
|
|
39
|
+
}
|
|
40
|
+
attributes['http.request.method_original'] = span_data.original_method if span_data.original_method
|
|
41
|
+
attributes['url.query'] = uri.query unless uri.query.nil?
|
|
42
|
+
attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
|
|
43
|
+
|
|
44
|
+
tracer.in_span(span_name, attributes: attributes, kind: :client) do |span|
|
|
45
|
+
OpenTelemetry.propagation.inject(req.headers)
|
|
46
|
+
super.tap do |response|
|
|
47
|
+
annotate_span_with_response!(span, response)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def config
|
|
55
|
+
OpenTelemetry::Instrumentation::HTTP::Instrumentation.instance.config
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def annotate_span_with_response!(span, response)
|
|
59
|
+
return unless response&.status
|
|
60
|
+
|
|
61
|
+
status_code = response.status.to_i
|
|
62
|
+
span.set_attribute('http.status_code', status_code) # old semconv
|
|
63
|
+
span.set_attribute('http.response.status_code', status_code) # stable semconv
|
|
64
|
+
span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(status_code)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def create_span_name(span_data, request_path)
|
|
68
|
+
default_span_name = span_data.span_name
|
|
69
|
+
|
|
70
|
+
if (implementation = config[:span_name_formatter])
|
|
71
|
+
updated_span_name = implementation.call(span_data.normalized_method, request_path)
|
|
72
|
+
updated_span_name.is_a?(String) ? updated_span_name : default_span_name
|
|
73
|
+
else
|
|
74
|
+
default_span_name
|
|
75
|
+
end
|
|
76
|
+
rescue StandardError
|
|
77
|
+
default_span_name
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def tracer
|
|
81
|
+
HTTP::Instrumentation.instance.tracer
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
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 HTTP
|
|
10
|
+
module Patches
|
|
11
|
+
# Module using old and stable HTTP semantic conventions
|
|
12
|
+
module Dup
|
|
13
|
+
# Module to prepend to HTTP::Connection for instrumentation
|
|
14
|
+
module Connection
|
|
15
|
+
def initialize(req, options)
|
|
16
|
+
attributes = {
|
|
17
|
+
# old semconv
|
|
18
|
+
'net.peer.name' => req.uri.host,
|
|
19
|
+
'net.peer.port' => req.uri.port,
|
|
20
|
+
# stable semconv
|
|
21
|
+
'server.address' => req.uri.host,
|
|
22
|
+
'server.port' => req.uri.port
|
|
23
|
+
}.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
|
|
24
|
+
|
|
25
|
+
tracer.in_span('CONNECT', attributes: attributes) do
|
|
26
|
+
super
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def tracer
|
|
33
|
+
HTTP::Instrumentation.instance.tracer
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
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 HTTP
|
|
10
|
+
module Patches
|
|
11
|
+
# Module using old HTTP semantic conventions
|
|
12
|
+
module Old
|
|
13
|
+
# Module to prepend to HTTP::Client for instrumentation
|
|
14
|
+
module Client
|
|
15
|
+
# Constant for the HTTP status range
|
|
16
|
+
HTTP_STATUS_SUCCESS_RANGE = (100..399)
|
|
17
|
+
|
|
18
|
+
def perform(req, options)
|
|
19
|
+
span_data = HttpHelper.span_attrs_for(req.verb, semconv: :old)
|
|
20
|
+
|
|
21
|
+
uri = req.uri
|
|
22
|
+
span_name = create_span_name(span_data, uri.path)
|
|
23
|
+
|
|
24
|
+
attributes = {
|
|
25
|
+
'http.method' => span_data.normalized_method,
|
|
26
|
+
'http.scheme' => uri.scheme,
|
|
27
|
+
'http.target' => uri.path,
|
|
28
|
+
'http.url' => "#{uri.scheme}://#{uri.host}",
|
|
29
|
+
'net.peer.name' => uri.host,
|
|
30
|
+
'net.peer.port' => uri.port
|
|
31
|
+
}.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
|
|
32
|
+
|
|
33
|
+
tracer.in_span(span_name, attributes: attributes, kind: :client) do |span|
|
|
34
|
+
OpenTelemetry.propagation.inject(req.headers)
|
|
35
|
+
super.tap do |response|
|
|
36
|
+
annotate_span_with_response!(span, response)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def config
|
|
44
|
+
OpenTelemetry::Instrumentation::HTTP::Instrumentation.instance.config
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def annotate_span_with_response!(span, response)
|
|
48
|
+
return unless response&.status
|
|
49
|
+
|
|
50
|
+
status_code = response.status.to_i
|
|
51
|
+
span.set_attribute('http.status_code', status_code)
|
|
52
|
+
span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(status_code)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def create_span_name(span_data, request_path)
|
|
56
|
+
default_span_name = span_data.span_name
|
|
57
|
+
|
|
58
|
+
if (implementation = config[:span_name_formatter])
|
|
59
|
+
updated_span_name = implementation.call(span_data.normalized_method, request_path)
|
|
60
|
+
updated_span_name.is_a?(String) ? updated_span_name : default_span_name
|
|
61
|
+
else
|
|
62
|
+
default_span_name
|
|
63
|
+
end
|
|
64
|
+
rescue StandardError
|
|
65
|
+
default_span_name
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def tracer
|
|
69
|
+
HTTP::Instrumentation.instance.tracer
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
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 HTTP
|
|
10
|
+
module Patches
|
|
11
|
+
# Module using old HTTP semantic conventions
|
|
12
|
+
module Old
|
|
13
|
+
# Module to prepend to HTTP::Connection for instrumentation
|
|
14
|
+
module Connection
|
|
15
|
+
def initialize(req, options)
|
|
16
|
+
attributes = {
|
|
17
|
+
'net.peer.name' => req.uri.host,
|
|
18
|
+
'net.peer.port' => req.uri.port
|
|
19
|
+
}.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
|
|
20
|
+
|
|
21
|
+
tracer.in_span('HTTP CONNECT', attributes: attributes) do
|
|
22
|
+
super
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def tracer
|
|
29
|
+
HTTP::Instrumentation.instance.tracer
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
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 HTTP
|
|
10
|
+
module Patches
|
|
11
|
+
# Module using stable HTTP semantic conventions
|
|
12
|
+
module Stable
|
|
13
|
+
# Module to prepend to HTTP::Client for instrumentation
|
|
14
|
+
module Client
|
|
15
|
+
# Constant for the HTTP status range
|
|
16
|
+
HTTP_STATUS_SUCCESS_RANGE = (100..399)
|
|
17
|
+
|
|
18
|
+
def perform(req, options)
|
|
19
|
+
span_data = HttpHelper.span_attrs_for(req.verb)
|
|
20
|
+
|
|
21
|
+
uri = req.uri
|
|
22
|
+
span_name = create_span_name(span_data, uri.path)
|
|
23
|
+
|
|
24
|
+
attributes = {
|
|
25
|
+
'http.request.method' => span_data.normalized_method,
|
|
26
|
+
'url.scheme' => uri.scheme,
|
|
27
|
+
'url.path' => uri.path,
|
|
28
|
+
'url.full' => "#{uri.scheme}://#{uri.host}",
|
|
29
|
+
'server.address' => uri.host,
|
|
30
|
+
'server.port' => uri.port
|
|
31
|
+
}
|
|
32
|
+
attributes['http.request.method_original'] = span_data.original_method if span_data.original_method
|
|
33
|
+
attributes['url.query'] = uri.query unless uri.query.nil?
|
|
34
|
+
attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
|
|
35
|
+
|
|
36
|
+
tracer.in_span(span_name, attributes: attributes, kind: :client) do |span|
|
|
37
|
+
OpenTelemetry.propagation.inject(req.headers)
|
|
38
|
+
super.tap do |response|
|
|
39
|
+
annotate_span_with_response!(span, response)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def config
|
|
47
|
+
OpenTelemetry::Instrumentation::HTTP::Instrumentation.instance.config
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def annotate_span_with_response!(span, response)
|
|
51
|
+
return unless response&.status
|
|
52
|
+
|
|
53
|
+
status_code = response.status.to_i
|
|
54
|
+
span.set_attribute('http.response.status_code', status_code)
|
|
55
|
+
span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(status_code)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def create_span_name(span_data, request_path)
|
|
59
|
+
default_span_name = span_data.span_name
|
|
60
|
+
|
|
61
|
+
if (implementation = config[:span_name_formatter])
|
|
62
|
+
updated_span_name = implementation.call(span_data.normalized_method, request_path)
|
|
63
|
+
updated_span_name.is_a?(String) ? updated_span_name : default_span_name
|
|
64
|
+
else
|
|
65
|
+
default_span_name
|
|
66
|
+
end
|
|
67
|
+
rescue StandardError
|
|
68
|
+
default_span_name
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def tracer
|
|
72
|
+
HTTP::Instrumentation.instance.tracer
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
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 HTTP
|
|
10
|
+
module Patches
|
|
11
|
+
# Module using stable HTTP semantic conventions
|
|
12
|
+
module Stable
|
|
13
|
+
# Module to prepend to HTTP::Connection for instrumentation
|
|
14
|
+
module Connection
|
|
15
|
+
def initialize(req, options)
|
|
16
|
+
attributes = {
|
|
17
|
+
'server.address' => req.uri.host,
|
|
18
|
+
'server.port' => req.uri.port
|
|
19
|
+
}.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
|
|
20
|
+
|
|
21
|
+
tracer.in_span('CONNECT', attributes: attributes) do
|
|
22
|
+
super
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def tracer
|
|
29
|
+
HTTP::Instrumentation.instance.tracer
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
metadata
CHANGED
|
@@ -1,211 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: opentelemetry-instrumentation-http
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.27.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- OpenTelemetry Authors
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2025-11-25 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.
|
|
19
|
+
version: '0.25'
|
|
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.
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: appraisal
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - "~>"
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '2.5'
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - "~>"
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '2.5'
|
|
55
|
-
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: bundler
|
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
|
58
|
-
requirements:
|
|
59
|
-
- - "~>"
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: '2.4'
|
|
62
|
-
type: :development
|
|
63
|
-
prerelease: false
|
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
-
requirements:
|
|
66
|
-
- - "~>"
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: '2.4'
|
|
69
|
-
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: minitest
|
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
|
72
|
-
requirements:
|
|
73
|
-
- - "~>"
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
version: '5.0'
|
|
76
|
-
type: :development
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - "~>"
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: '5.0'
|
|
83
|
-
- !ruby/object:Gem::Dependency
|
|
84
|
-
name: opentelemetry-sdk
|
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
|
86
|
-
requirements:
|
|
87
|
-
- - "~>"
|
|
88
|
-
- !ruby/object:Gem::Version
|
|
89
|
-
version: '1.1'
|
|
90
|
-
type: :development
|
|
91
|
-
prerelease: false
|
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
-
requirements:
|
|
94
|
-
- - "~>"
|
|
95
|
-
- !ruby/object:Gem::Version
|
|
96
|
-
version: '1.1'
|
|
97
|
-
- !ruby/object:Gem::Dependency
|
|
98
|
-
name: opentelemetry-test-helpers
|
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
|
100
|
-
requirements:
|
|
101
|
-
- - "~>"
|
|
102
|
-
- !ruby/object:Gem::Version
|
|
103
|
-
version: '0.3'
|
|
104
|
-
type: :development
|
|
105
|
-
prerelease: false
|
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
-
requirements:
|
|
108
|
-
- - "~>"
|
|
109
|
-
- !ruby/object:Gem::Version
|
|
110
|
-
version: '0.3'
|
|
111
|
-
- !ruby/object:Gem::Dependency
|
|
112
|
-
name: rake
|
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
|
114
|
-
requirements:
|
|
115
|
-
- - "~>"
|
|
116
|
-
- !ruby/object:Gem::Version
|
|
117
|
-
version: '13.0'
|
|
118
|
-
type: :development
|
|
119
|
-
prerelease: false
|
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
-
requirements:
|
|
122
|
-
- - "~>"
|
|
123
|
-
- !ruby/object:Gem::Version
|
|
124
|
-
version: '13.0'
|
|
125
|
-
- !ruby/object:Gem::Dependency
|
|
126
|
-
name: rspec-mocks
|
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
|
128
|
-
requirements:
|
|
129
|
-
- - ">="
|
|
130
|
-
- !ruby/object:Gem::Version
|
|
131
|
-
version: '0'
|
|
132
|
-
type: :development
|
|
133
|
-
prerelease: false
|
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
-
requirements:
|
|
136
|
-
- - ">="
|
|
137
|
-
- !ruby/object:Gem::Version
|
|
138
|
-
version: '0'
|
|
139
|
-
- !ruby/object:Gem::Dependency
|
|
140
|
-
name: rubocop
|
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
|
142
|
-
requirements:
|
|
143
|
-
- - "~>"
|
|
144
|
-
- !ruby/object:Gem::Version
|
|
145
|
-
version: 1.68.0
|
|
146
|
-
type: :development
|
|
147
|
-
prerelease: false
|
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
-
requirements:
|
|
150
|
-
- - "~>"
|
|
151
|
-
- !ruby/object:Gem::Version
|
|
152
|
-
version: 1.68.0
|
|
153
|
-
- !ruby/object:Gem::Dependency
|
|
154
|
-
name: rubocop-performance
|
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
|
156
|
-
requirements:
|
|
157
|
-
- - "~>"
|
|
158
|
-
- !ruby/object:Gem::Version
|
|
159
|
-
version: 1.23.0
|
|
160
|
-
type: :development
|
|
161
|
-
prerelease: false
|
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
163
|
-
requirements:
|
|
164
|
-
- - "~>"
|
|
165
|
-
- !ruby/object:Gem::Version
|
|
166
|
-
version: 1.23.0
|
|
167
|
-
- !ruby/object:Gem::Dependency
|
|
168
|
-
name: simplecov
|
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
|
170
|
-
requirements:
|
|
171
|
-
- - "~>"
|
|
172
|
-
- !ruby/object:Gem::Version
|
|
173
|
-
version: 0.17.1
|
|
174
|
-
type: :development
|
|
175
|
-
prerelease: false
|
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
177
|
-
requirements:
|
|
178
|
-
- - "~>"
|
|
179
|
-
- !ruby/object:Gem::Version
|
|
180
|
-
version: 0.17.1
|
|
181
|
-
- !ruby/object:Gem::Dependency
|
|
182
|
-
name: webmock
|
|
183
|
-
requirement: !ruby/object:Gem::Requirement
|
|
184
|
-
requirements:
|
|
185
|
-
- - "~>"
|
|
186
|
-
- !ruby/object:Gem::Version
|
|
187
|
-
version: 3.24.0
|
|
188
|
-
type: :development
|
|
189
|
-
prerelease: false
|
|
190
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
191
|
-
requirements:
|
|
192
|
-
- - "~>"
|
|
193
|
-
- !ruby/object:Gem::Version
|
|
194
|
-
version: 3.24.0
|
|
195
|
-
- !ruby/object:Gem::Dependency
|
|
196
|
-
name: yard
|
|
197
|
-
requirement: !ruby/object:Gem::Requirement
|
|
198
|
-
requirements:
|
|
199
|
-
- - "~>"
|
|
200
|
-
- !ruby/object:Gem::Version
|
|
201
|
-
version: '0.9'
|
|
202
|
-
type: :development
|
|
203
|
-
prerelease: false
|
|
204
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
205
|
-
requirements:
|
|
206
|
-
- - "~>"
|
|
207
|
-
- !ruby/object:Gem::Version
|
|
208
|
-
version: '0.9'
|
|
26
|
+
version: '0.25'
|
|
209
27
|
description: HTTP instrumentation for the OpenTelemetry framework
|
|
210
28
|
email:
|
|
211
29
|
- cncf-opentelemetry-contributors@lists.cncf.io
|
|
@@ -220,19 +38,24 @@ files:
|
|
|
220
38
|
- lib/opentelemetry-instrumentation-http.rb
|
|
221
39
|
- lib/opentelemetry/instrumentation.rb
|
|
222
40
|
- lib/opentelemetry/instrumentation/http.rb
|
|
41
|
+
- lib/opentelemetry/instrumentation/http/http_helper.rb
|
|
223
42
|
- lib/opentelemetry/instrumentation/http/instrumentation.rb
|
|
224
|
-
- lib/opentelemetry/instrumentation/http/patches/client.rb
|
|
225
|
-
- lib/opentelemetry/instrumentation/http/patches/connection.rb
|
|
43
|
+
- lib/opentelemetry/instrumentation/http/patches/dup/client.rb
|
|
44
|
+
- lib/opentelemetry/instrumentation/http/patches/dup/connection.rb
|
|
45
|
+
- lib/opentelemetry/instrumentation/http/patches/old/client.rb
|
|
46
|
+
- lib/opentelemetry/instrumentation/http/patches/old/connection.rb
|
|
47
|
+
- lib/opentelemetry/instrumentation/http/patches/stable/client.rb
|
|
48
|
+
- lib/opentelemetry/instrumentation/http/patches/stable/connection.rb
|
|
226
49
|
- lib/opentelemetry/instrumentation/http/version.rb
|
|
227
50
|
homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
|
|
228
51
|
licenses:
|
|
229
52
|
- Apache-2.0
|
|
230
53
|
metadata:
|
|
231
|
-
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-http/0.
|
|
54
|
+
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-http/0.27.1/file/CHANGELOG.md
|
|
232
55
|
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/http
|
|
233
56
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
|
|
234
|
-
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-http/0.
|
|
235
|
-
post_install_message:
|
|
57
|
+
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-http/0.27.1
|
|
58
|
+
post_install_message:
|
|
236
59
|
rdoc_options: []
|
|
237
60
|
require_paths:
|
|
238
61
|
- lib
|
|
@@ -240,15 +63,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
240
63
|
requirements:
|
|
241
64
|
- - ">="
|
|
242
65
|
- !ruby/object:Gem::Version
|
|
243
|
-
version: '3.
|
|
66
|
+
version: '3.2'
|
|
244
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
245
68
|
requirements:
|
|
246
69
|
- - ">="
|
|
247
70
|
- !ruby/object:Gem::Version
|
|
248
71
|
version: '0'
|
|
249
72
|
requirements: []
|
|
250
|
-
rubygems_version: 3.
|
|
251
|
-
signing_key:
|
|
73
|
+
rubygems_version: 3.4.19
|
|
74
|
+
signing_key:
|
|
252
75
|
specification_version: 4
|
|
253
76
|
summary: HTTP instrumentation for the OpenTelemetry framework
|
|
254
77
|
test_files: []
|
|
@@ -1,70 +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 HTTP
|
|
10
|
-
module Patches
|
|
11
|
-
# Module to prepend to HTTP::Client for instrumentation
|
|
12
|
-
module Client
|
|
13
|
-
# Constant for the HTTP status range
|
|
14
|
-
HTTP_STATUS_SUCCESS_RANGE = (100..399)
|
|
15
|
-
|
|
16
|
-
def perform(req, options)
|
|
17
|
-
uri = req.uri
|
|
18
|
-
request_method = req.verb.to_s.upcase
|
|
19
|
-
span_name = create_request_span_name(request_method, uri.path)
|
|
20
|
-
|
|
21
|
-
attributes = {
|
|
22
|
-
'http.method' => request_method,
|
|
23
|
-
'http.scheme' => uri.scheme,
|
|
24
|
-
'http.target' => uri.path,
|
|
25
|
-
'http.url' => "#{uri.scheme}://#{uri.host}",
|
|
26
|
-
'net.peer.name' => uri.host,
|
|
27
|
-
'net.peer.port' => uri.port
|
|
28
|
-
}.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
|
|
29
|
-
|
|
30
|
-
tracer.in_span(span_name, attributes: attributes, kind: :client) do |span|
|
|
31
|
-
OpenTelemetry.propagation.inject(req.headers)
|
|
32
|
-
super.tap do |response|
|
|
33
|
-
annotate_span_with_response!(span, response)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
private
|
|
39
|
-
|
|
40
|
-
def config
|
|
41
|
-
OpenTelemetry::Instrumentation::HTTP::Instrumentation.instance.config
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def annotate_span_with_response!(span, response)
|
|
45
|
-
return unless response&.status
|
|
46
|
-
|
|
47
|
-
status_code = response.status.to_i
|
|
48
|
-
span.set_attribute('http.status_code', status_code)
|
|
49
|
-
span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(status_code)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def create_request_span_name(request_method, request_path)
|
|
53
|
-
if (implementation = config[:span_name_formatter])
|
|
54
|
-
updated_span_name = implementation.call(request_method, request_path)
|
|
55
|
-
updated_span_name.is_a?(String) ? updated_span_name : "HTTP #{request_method}"
|
|
56
|
-
else
|
|
57
|
-
"HTTP #{request_method}"
|
|
58
|
-
end
|
|
59
|
-
rescue StandardError
|
|
60
|
-
"HTTP #{request_method}"
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def tracer
|
|
64
|
-
HTTP::Instrumentation.instance.tracer
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
@@ -1,33 +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 HTTP
|
|
10
|
-
module Patches
|
|
11
|
-
# Module to prepend to HTTP::Connection for instrumentation
|
|
12
|
-
module Connection
|
|
13
|
-
def initialize(req, options)
|
|
14
|
-
attributes = {
|
|
15
|
-
'net.peer.name' => req.uri.host,
|
|
16
|
-
'net.peer.port' => req.uri.port
|
|
17
|
-
}.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
|
|
18
|
-
|
|
19
|
-
tracer.in_span('HTTP CONNECT', attributes: attributes) do
|
|
20
|
-
super
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
private
|
|
25
|
-
|
|
26
|
-
def tracer
|
|
27
|
-
HTTP::Instrumentation.instance.tracer
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|