opentelemetry-instrumentation-http 0.26.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8fd6c8748e9cedb916f60eca92745adc4e5a5d5c05c5543cd90e08d148e22d4
4
- data.tar.gz: 10adf837f0b138ddcaec5834289233dcc485b4e2aede461c07efff56e4a97da3
3
+ metadata.gz: 850cb2d0a9d8d18cf00cade03d86e379a2338f626a0f1468e32b37c186de0869
4
+ data.tar.gz: d89c15de55426a730fdaef82e1b8212fa20981b645b9985f66712ceff7cab2b3
5
5
  SHA512:
6
- metadata.gz: bb23413aeb8be027f59457ec033699ef9c8d67ad8843934f590d441e80080a5e53570940c7700d12227e4df77ce4e336f95598eb5280d6046eae35c7f68120e9
7
- data.tar.gz: e32a4d3431f9eccc65800e7e242c01f01d19450e7dc1ae1d9658991e86224415ec18d642c1aa3b216165322dc92963c5304375ea2db3e8f9db94d864e89f50fc
6
+ metadata.gz: 676dd8c1071ed0c9f0927c6def794f71637919a3303be4df314ebfe2cdb8037f04e64c5ccbdc649326f51c920437714cd504699a59e26dbfeb33569aed5172e0
7
+ data.tar.gz: a681dc2912300b21a16e1d7d069cf8e35eb3f9899917e87f89522f15e7b949de8f963bb894eb5efd887cc0a2cd8120077b25b3c29dc125dd0beffd7a150e3bb8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
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
+
3
13
  ### v0.26.1 / 2025-09-30
4
14
 
5
15
  * FIXED: Min OTel Ruby API 1.7
@@ -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
@@ -16,26 +16,28 @@ module OpenTelemetry
16
16
  HTTP_STATUS_SUCCESS_RANGE = (100..399)
17
17
 
18
18
  def perform(req, options)
19
+ span_data = HttpHelper.span_attrs_for(req.verb)
20
+
19
21
  uri = req.uri
20
- request_method = req.verb.to_s.upcase
21
- span_name = create_request_span_name(request_method, uri.path)
22
+ span_name = create_span_name(span_data, uri.path)
22
23
 
23
24
  attributes = {
24
25
  # old semconv
25
- 'http.method' => request_method,
26
+ 'http.method' => span_data.normalized_method,
26
27
  'http.scheme' => uri.scheme,
27
28
  'http.target' => uri.path,
28
29
  'http.url' => "#{uri.scheme}://#{uri.host}",
29
30
  'net.peer.name' => uri.host,
30
31
  'net.peer.port' => uri.port,
31
32
  # stable semconv
32
- 'http.request.method' => request_method,
33
+ 'http.request.method' => span_data.normalized_method,
33
34
  'url.scheme' => uri.scheme,
34
35
  'url.path' => uri.path,
35
36
  'url.full' => "#{uri.scheme}://#{uri.host}",
36
37
  'server.address' => uri.host,
37
38
  'server.port' => uri.port
38
39
  }
40
+ attributes['http.request.method_original'] = span_data.original_method if span_data.original_method
39
41
  attributes['url.query'] = uri.query unless uri.query.nil?
40
42
  attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
41
43
 
@@ -62,15 +64,17 @@ module OpenTelemetry
62
64
  span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(status_code)
63
65
  end
64
66
 
65
- def create_request_span_name(request_method, request_path)
67
+ def create_span_name(span_data, request_path)
68
+ default_span_name = span_data.span_name
69
+
66
70
  if (implementation = config[:span_name_formatter])
67
- updated_span_name = implementation.call(request_method, request_path)
68
- updated_span_name.is_a?(String) ? updated_span_name : request_method.to_s
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
69
73
  else
70
- request_method.to_s
74
+ default_span_name
71
75
  end
72
76
  rescue StandardError
73
- request_method.to_s
77
+ default_span_name
74
78
  end
75
79
 
76
80
  def tracer
@@ -16,12 +16,13 @@ module OpenTelemetry
16
16
  HTTP_STATUS_SUCCESS_RANGE = (100..399)
17
17
 
18
18
  def perform(req, options)
19
+ span_data = HttpHelper.span_attrs_for(req.verb, semconv: :old)
20
+
19
21
  uri = req.uri
20
- request_method = req.verb.to_s.upcase
21
- span_name = create_request_span_name(request_method, uri.path)
22
+ span_name = create_span_name(span_data, uri.path)
22
23
 
23
24
  attributes = {
24
- 'http.method' => request_method,
25
+ 'http.method' => span_data.normalized_method,
25
26
  'http.scheme' => uri.scheme,
26
27
  'http.target' => uri.path,
27
28
  'http.url' => "#{uri.scheme}://#{uri.host}",
@@ -51,15 +52,17 @@ module OpenTelemetry
51
52
  span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(status_code)
52
53
  end
53
54
 
54
- def create_request_span_name(request_method, request_path)
55
+ def create_span_name(span_data, request_path)
56
+ default_span_name = span_data.span_name
57
+
55
58
  if (implementation = config[:span_name_formatter])
56
- updated_span_name = implementation.call(request_method, request_path)
57
- updated_span_name.is_a?(String) ? updated_span_name : "HTTP #{request_method}"
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
58
61
  else
59
- "HTTP #{request_method}"
62
+ default_span_name
60
63
  end
61
64
  rescue StandardError
62
- "HTTP #{request_method}"
65
+ default_span_name
63
66
  end
64
67
 
65
68
  def tracer
@@ -16,18 +16,20 @@ module OpenTelemetry
16
16
  HTTP_STATUS_SUCCESS_RANGE = (100..399)
17
17
 
18
18
  def perform(req, options)
19
+ span_data = HttpHelper.span_attrs_for(req.verb)
20
+
19
21
  uri = req.uri
20
- request_method = req.verb.to_s.upcase
21
- span_name = create_request_span_name(request_method, uri.path)
22
+ span_name = create_span_name(span_data, uri.path)
22
23
 
23
24
  attributes = {
24
- 'http.request.method' => request_method,
25
+ 'http.request.method' => span_data.normalized_method,
25
26
  'url.scheme' => uri.scheme,
26
27
  'url.path' => uri.path,
27
28
  'url.full' => "#{uri.scheme}://#{uri.host}",
28
29
  'server.address' => uri.host,
29
30
  'server.port' => uri.port
30
31
  }
32
+ attributes['http.request.method_original'] = span_data.original_method if span_data.original_method
31
33
  attributes['url.query'] = uri.query unless uri.query.nil?
32
34
  attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
33
35
 
@@ -53,15 +55,17 @@ module OpenTelemetry
53
55
  span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(status_code)
54
56
  end
55
57
 
56
- def create_request_span_name(request_method, request_path)
58
+ def create_span_name(span_data, request_path)
59
+ default_span_name = span_data.span_name
60
+
57
61
  if (implementation = config[:span_name_formatter])
58
- updated_span_name = implementation.call(request_method, request_path)
59
- updated_span_name.is_a?(String) ? updated_span_name : request_method.to_s
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
60
64
  else
61
- request_method.to_s
65
+ default_span_name
62
66
  end
63
67
  rescue StandardError
64
- request_method.to_s
68
+ default_span_name
65
69
  end
66
70
 
67
71
  def tracer
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module HTTP
10
- VERSION = '0.26.1'
10
+ VERSION = '0.27.1'
11
11
  end
12
12
  end
13
13
  end
@@ -15,5 +15,6 @@ module OpenTelemetry
15
15
  end
16
16
  end
17
17
 
18
+ require_relative 'http/http_helper'
18
19
  require_relative 'http/instrumentation'
19
20
  require_relative 'http/version'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-instrumentation-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.1
4
+ version: 0.27.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: 2025-10-01 00:00:00.000000000 Z
11
+ date: 2025-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-instrumentation-base
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.24'
19
+ version: '0.25'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.24'
26
+ version: '0.25'
27
27
  description: HTTP instrumentation for the OpenTelemetry framework
28
28
  email:
29
29
  - cncf-opentelemetry-contributors@lists.cncf.io
@@ -38,6 +38,7 @@ files:
38
38
  - lib/opentelemetry-instrumentation-http.rb
39
39
  - lib/opentelemetry/instrumentation.rb
40
40
  - lib/opentelemetry/instrumentation/http.rb
41
+ - lib/opentelemetry/instrumentation/http/http_helper.rb
41
42
  - lib/opentelemetry/instrumentation/http/instrumentation.rb
42
43
  - lib/opentelemetry/instrumentation/http/patches/dup/client.rb
43
44
  - lib/opentelemetry/instrumentation/http/patches/dup/connection.rb
@@ -50,10 +51,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
50
51
  licenses:
51
52
  - Apache-2.0
52
53
  metadata:
53
- changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-http/0.26.1/file/CHANGELOG.md
54
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-http/0.27.1/file/CHANGELOG.md
54
55
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/http
55
56
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
56
- documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-http/0.26.1
57
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-http/0.27.1
57
58
  post_install_message:
58
59
  rdoc_options: []
59
60
  require_paths:
@@ -62,14 +63,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
63
  requirements:
63
64
  - - ">="
64
65
  - !ruby/object:Gem::Version
65
- version: '3.1'
66
+ version: '3.2'
66
67
  required_rubygems_version: !ruby/object:Gem::Requirement
67
68
  requirements:
68
69
  - - ">="
69
70
  - !ruby/object:Gem::Version
70
71
  version: '0'
71
72
  requirements: []
72
- rubygems_version: 3.3.27
73
+ rubygems_version: 3.4.19
73
74
  signing_key:
74
75
  specification_version: 4
75
76
  summary: HTTP instrumentation for the OpenTelemetry framework