opentelemetry-instrumentation-net_http 0.29.2 → 0.30.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 +4 -0
- data/README.md +26 -7
- data/lib/opentelemetry/instrumentation/net/http/http_helper.rb +25 -1
- data/lib/opentelemetry/instrumentation/net/http/instrumentation.rb +14 -0
- data/lib/opentelemetry/instrumentation/net/http/patches/stable/instrumentation.rb +27 -4
- data/lib/opentelemetry/instrumentation/net/http/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 79c616a7a19eae46e1d1d616a306b867d07123bc11aa3b014bfdba34efe9d9d3
|
|
4
|
+
data.tar.gz: 0a1c47a29fe97f8b570b35004f19affaf92ebf9d3b6076471f37ad12bbd28072
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cb7a07a3954739a3e40fc8cd1969c98388f38b63f389c6b68e6b4943bbb69555d1db922960b7ba4dae56143b31df50d8e60d27bee4bc3e421ae419d290a18656
|
|
7
|
+
data.tar.gz: 37cc7d3675e221e77f934ff0666f18527b7bf04218f6fbc9abaf202e4b0f55c4d44789bc970a797bdca5936641cb8a8f9e997db76118814df237b8d4dc262aa1
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Release History: opentelemetry-instrumentation-net_http
|
|
2
2
|
|
|
3
|
+
## v0.30.0 / 2026-11-03
|
|
4
|
+
|
|
5
|
+
- ADDED: Add http.client.request.duration metric to Net::HTTP instrumentation (#2630)
|
|
6
|
+
|
|
3
7
|
## v0.29.2 / 2026-10-06
|
|
4
8
|
|
|
5
9
|
- FIXED: Normalize URI-like request paths on `Net::HTTP` instrumentation (#2591)
|
data/README.md
CHANGED
|
@@ -34,11 +34,33 @@ end
|
|
|
34
34
|
|
|
35
35
|
An example of usage can be seen in [`example/net_http.rb`](https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/instrumentation/net_http/example/net_http.rb).
|
|
36
36
|
|
|
37
|
+
## Metrics
|
|
38
|
+
|
|
39
|
+
This instrumentation can record the [`http.client.request.duration`](https://opentelemetry.io/docs/specs/semconv/http/http-metrics/#metric-httpclientrequestduration) histogram.
|
|
40
|
+
|
|
41
|
+
To record the metric, two things must be true:
|
|
42
|
+
|
|
43
|
+
- Stable HTTP semantic conventions are in use (it is not recorded in `old` or `http/dup` modes).
|
|
44
|
+
- A metrics SDK (such as `opentelemetry-metrics-sdk`) is installed and configured.
|
|
45
|
+
|
|
46
|
+
Requests to `untraced_hosts` or requests made in an untraced context are not measured.
|
|
47
|
+
|
|
48
|
+
Semantic conventions recommends using the following bucket boundaries: `[0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10]`. If your metrics SDK does not apply advisory parameters, configure a view with these boundaries.
|
|
49
|
+
|
|
50
|
+
| Attribute | Notes |
|
|
51
|
+
| --------------------------- | ------------------------------------------------------------------------------------------------- |
|
|
52
|
+
| `http.request.method` | `_OTHER` for unknown methods |
|
|
53
|
+
| `server.address` | |
|
|
54
|
+
| `server.port` | |
|
|
55
|
+
| `http.response.status_code` | When a response is received |
|
|
56
|
+
| `network.protocol.version` | When a response is received |
|
|
57
|
+
| `error.type` | The status code as a string for status codes outside 100–399, or the class name of a raised error |
|
|
58
|
+
|
|
37
59
|
## How can I get involved?
|
|
38
60
|
|
|
39
|
-
The `opentelemetry-instrumentation-net_http` gem source is [on github][repo-github], along with related gems
|
|
61
|
+
The `opentelemetry-instrumentation-net_http` gem source is [on github][repo-github], along with related gems.
|
|
40
62
|
|
|
41
|
-
The OpenTelemetry Ruby gems are maintained by the OpenTelemetry Ruby
|
|
63
|
+
The OpenTelemetry Ruby gems are maintained by the OpenTelemetry Ruby Special Interest Group (SIG). You can find details on our weekly meeting times, GitHub Discussions, and CNCF Slack channels on the [Ruby SDK SIG page][ruby-sig].
|
|
42
64
|
|
|
43
65
|
## License
|
|
44
66
|
|
|
@@ -46,12 +68,9 @@ Apache 2.0 license. See [LICENSE][license-github] for more information.
|
|
|
46
68
|
|
|
47
69
|
[net-http-home]: https://docs.ruby-lang.org/en/2.0.0/Net/HTTP.html
|
|
48
70
|
[bundler-home]: https://bundler.io
|
|
49
|
-
[repo-github]: https://github.com/open-telemetry/opentelemetry-ruby
|
|
71
|
+
[repo-github]: https://github.com/open-telemetry/opentelemetry-ruby-contrib
|
|
50
72
|
[license-github]: https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/LICENSE
|
|
51
|
-
[ruby-sig]: https://github.com/open-telemetry/community#ruby-
|
|
52
|
-
[community-meetings]: https://github.com/open-telemetry/community#community-meetings
|
|
53
|
-
[slack-channel]: https://cloud-native.slack.com/archives/C01NWKKMKMY
|
|
54
|
-
[discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions
|
|
73
|
+
[ruby-sig]: https://github.com/open-telemetry/community/blob/main/sigs.md#ruby-sdk
|
|
55
74
|
|
|
56
75
|
## HTTP semantic convention stability
|
|
57
76
|
|
|
@@ -10,10 +10,13 @@ module OpenTelemetry
|
|
|
10
10
|
module HTTP
|
|
11
11
|
# Utility module for HTTP-related helper methods
|
|
12
12
|
# @api private
|
|
13
|
-
module HttpHelper
|
|
13
|
+
module HttpHelper # rubocop:disable Metrics/ModuleLength
|
|
14
14
|
# Lightweight struct to hold span creation attributes
|
|
15
15
|
SpanCreationAttributes = Struct.new(:span_name, :attributes)
|
|
16
16
|
|
|
17
|
+
# Constant for the HTTP status range
|
|
18
|
+
HTTP_STATUS_SUCCESS_RANGE = (100..399)
|
|
19
|
+
|
|
17
20
|
# Returns the request path for strings and URI-like objects.
|
|
18
21
|
# @param path [String, #request_uri] The request path
|
|
19
22
|
# @return [String, nil] The normalized request path
|
|
@@ -121,6 +124,27 @@ module OpenTelemetry
|
|
|
121
124
|
SpanCreationAttributes.new(span_name: span_name, attributes: attributes)
|
|
122
125
|
end
|
|
123
126
|
|
|
127
|
+
# Prepares `http.client.request.duration` attributes using stable semantic conventions.
|
|
128
|
+
# @param method [String] The normalized HTTP method
|
|
129
|
+
# @param address [String, nil] The server address
|
|
130
|
+
# @param port [Integer, nil] The server port
|
|
131
|
+
# @param response [Net::HTTPResponse, nil] The response, if received
|
|
132
|
+
# @param error_type [String, nil] The class name of a raised error, if any
|
|
133
|
+
# @return [Hash] the metric attributes
|
|
134
|
+
def self.metric_attrs(method, address, port, response, error_type)
|
|
135
|
+
attributes = { 'http.request.method' => method, 'server.address' => address, 'server.port' => port }
|
|
136
|
+
|
|
137
|
+
if response&.code
|
|
138
|
+
status_code = response.code.to_i
|
|
139
|
+
attributes['http.response.status_code'] = status_code
|
|
140
|
+
attributes['network.protocol.version'] = response.http_version
|
|
141
|
+
error_type ||= response.code unless HttpHelper::HTTP_STATUS_SUCCESS_RANGE.cover?(status_code)
|
|
142
|
+
end
|
|
143
|
+
attributes['error.type'] = error_type if error_type
|
|
144
|
+
|
|
145
|
+
attributes.compact
|
|
146
|
+
end
|
|
147
|
+
|
|
124
148
|
# Prepares span data using both old and stable semantic conventions
|
|
125
149
|
# @param method [String, Symbol] The HTTP method
|
|
126
150
|
# @return [SpanCreationAttributes] struct containing span_name and attributes hash
|
|
@@ -29,6 +29,14 @@ module OpenTelemetry
|
|
|
29
29
|
# context in the request.
|
|
30
30
|
option :untraced_hosts, default: [], validate: :array
|
|
31
31
|
|
|
32
|
+
# Bucket boundaries recommended by the stable HTTP semantic conventions
|
|
33
|
+
CLIENT_REQUEST_DURATION_BUCKETS = [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10].freeze
|
|
34
|
+
|
|
35
|
+
# The `http.client.request.duration` histogram, only created when
|
|
36
|
+
# the stable HTTP semantic conventions are in use.
|
|
37
|
+
# @api private
|
|
38
|
+
attr_reader :client_request_duration_histogram
|
|
39
|
+
|
|
32
40
|
private
|
|
33
41
|
|
|
34
42
|
def determine_semconv
|
|
@@ -71,6 +79,12 @@ module OpenTelemetry
|
|
|
71
79
|
end
|
|
72
80
|
|
|
73
81
|
def patch_stable
|
|
82
|
+
@client_request_duration_histogram ||= meter.create_histogram(
|
|
83
|
+
'http.client.request.duration',
|
|
84
|
+
unit: 's',
|
|
85
|
+
description: 'Duration of HTTP client requests.',
|
|
86
|
+
advisory: { explicit_bucket_boundaries: CLIENT_REQUEST_DURATION_BUCKETS }
|
|
87
|
+
)
|
|
74
88
|
::Net::HTTP.prepend(Patches::Stable::Instrumentation)
|
|
75
89
|
end
|
|
76
90
|
end
|
|
@@ -14,7 +14,7 @@ module OpenTelemetry
|
|
|
14
14
|
module Instrumentation
|
|
15
15
|
USE_SSL_TO_SCHEME = { false => 'http', true => 'https' }.freeze
|
|
16
16
|
|
|
17
|
-
# Constant for the HTTP status range
|
|
17
|
+
# Constant for the HTTP status range. Deprecated. Use HttpHelper::HTTP_STATUS_SUCCESS_RANGE
|
|
18
18
|
HTTP_STATUS_SUCCESS_RANGE = (100..399)
|
|
19
19
|
|
|
20
20
|
def request(req, body = nil, &)
|
|
@@ -39,10 +39,21 @@ module OpenTelemetry
|
|
|
39
39
|
attributes: attributes,
|
|
40
40
|
kind: :client
|
|
41
41
|
) do |span|
|
|
42
|
-
|
|
42
|
+
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
43
|
+
response = nil
|
|
44
|
+
error_type = nil
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
begin
|
|
47
|
+
OpenTelemetry.propagation.inject(req)
|
|
48
|
+
|
|
49
|
+
response = super
|
|
45
50
|
annotate_span_with_response!(span, response)
|
|
51
|
+
response
|
|
52
|
+
rescue StandardError => e
|
|
53
|
+
error_type = e.class.name
|
|
54
|
+
raise
|
|
55
|
+
ensure
|
|
56
|
+
record_duration_metric(start_time, attributes['http.request.method'], response, error_type)
|
|
46
57
|
end
|
|
47
58
|
end
|
|
48
59
|
end
|
|
@@ -84,13 +95,25 @@ module OpenTelemetry
|
|
|
84
95
|
status_code = response.code.to_i
|
|
85
96
|
|
|
86
97
|
span.set_attribute('http.response.status_code', status_code)
|
|
87
|
-
span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(status_code)
|
|
98
|
+
span.status = OpenTelemetry::Trace::Status.error unless HttpHelper::HTTP_STATUS_SUCCESS_RANGE.cover?(status_code)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def record_duration_metric(start_time, method, response, error_type)
|
|
102
|
+
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
|
|
103
|
+
histogram = client_request_duration_histogram
|
|
104
|
+
return unless histogram
|
|
105
|
+
|
|
106
|
+
histogram.record(duration, attributes: HttpHelper.metric_attrs(method, @address, @port, response, error_type))
|
|
88
107
|
end
|
|
89
108
|
|
|
90
109
|
def tracer
|
|
91
110
|
Net::HTTP::Instrumentation.instance.tracer
|
|
92
111
|
end
|
|
93
112
|
|
|
113
|
+
def client_request_duration_histogram
|
|
114
|
+
Net::HTTP::Instrumentation.instance.client_request_duration_histogram
|
|
115
|
+
end
|
|
116
|
+
|
|
94
117
|
def untraced?
|
|
95
118
|
untraced_context? || untraced_host?
|
|
96
119
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: opentelemetry-instrumentation-net_http
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.30.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- OpenTelemetry Authors
|
|
@@ -47,10 +47,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
|
|
|
47
47
|
licenses:
|
|
48
48
|
- Apache-2.0
|
|
49
49
|
metadata:
|
|
50
|
-
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-net_http/0.
|
|
51
|
-
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/opentelemetry-instrumentation-net_http/v0.
|
|
50
|
+
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-net_http/0.30.0/file/CHANGELOG.md
|
|
51
|
+
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/opentelemetry-instrumentation-net_http/v0.30.0/instrumentation/net_http
|
|
52
52
|
bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
|
|
53
|
-
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-net_http/0.
|
|
53
|
+
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-net_http/0.30.0
|
|
54
54
|
rdoc_options: []
|
|
55
55
|
require_paths:
|
|
56
56
|
- lib
|
|
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
65
65
|
- !ruby/object:Gem::Version
|
|
66
66
|
version: '0'
|
|
67
67
|
requirements: []
|
|
68
|
-
rubygems_version: 4.0.
|
|
68
|
+
rubygems_version: 4.0.20
|
|
69
69
|
specification_version: 4
|
|
70
70
|
summary: Net::HTTP instrumentation for the OpenTelemetry framework
|
|
71
71
|
test_files: []
|