opentelemetry-instrumentation-httpx 0.4.1 → 0.5.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: 400d9f06d6aaaa7e8b79c56f44f66afe9362f781bc935c8e21aeaee060cecbb3
4
- data.tar.gz: dfd74ea46554ef59ba0077fb6569b9fb6e056036b9cb9b9f9fd6f29081607ad2
3
+ metadata.gz: 30dd73d1b0e1e1a0ad8c6d11c942a62e97402dd249b26217782761c14ae19002
4
+ data.tar.gz: d9d6c07a9518e9558af0801a26ae999bfcf785854bfa0c5c6f7ae75a91124b15
5
5
  SHA512:
6
- metadata.gz: 48345860d208c92a864d9c54fd07fe77ad4947087036901b96be3c457173129b8eaad61cf130bd4709af37fa84949a530aa795d493c1573c4f2bd77c60dfa151
7
- data.tar.gz: 0d83c7cd19c2bde555783f244f2be8cd4aa9a4287673f3dbc9298d038433c5c3b3dd6d157f5e3558eec483e4b6f5ad24cd351bd31c4ddccb5838c3239b70854b
6
+ metadata.gz: 7568738e6532da2c0b7f1f765d5e3e7174a78b69d352a046ff22bcab8a833bded5e0c3b5fca1e12afce3badad44e2e3666398f9dd716f485a7126737e19b2519
7
+ data.tar.gz: eff4bb80b79ecc1e1b54e7dc22a4785435754fe08356ab0cccccbb145062bca309e4dd0813f6796697c420ef97f256b7b22e37bf6f4a6b7ccb9e9fd9f08fdff7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Release History: opentelemetry-instrumentation-httpx
2
2
 
3
+ ### v0.5.1 / 2025-11-25
4
+
5
+ * FIXED: Update support for unknown HTTP methods to match semantic conventions
6
+
7
+ ### v0.5.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.4.1 / 2025-09-30
4
14
 
5
15
  * FIXED: Min OTel Ruby API 1.7
@@ -72,17 +72,19 @@ module OpenTelemetry
72
72
  verb = request.verb
73
73
  uri = request.uri
74
74
 
75
+ span_data = HttpHelper.span_attrs_for(verb)
76
+
75
77
  config = HTTPX::Instrumentation.instance.config
76
78
 
77
79
  attributes = {
78
80
  OpenTelemetry::SemanticConventions::Trace::HTTP_HOST => uri.host,
79
- OpenTelemetry::SemanticConventions::Trace::HTTP_METHOD => verb,
81
+ OpenTelemetry::SemanticConventions::Trace::HTTP_METHOD => span_data.normalized_method,
80
82
  OpenTelemetry::SemanticConventions::Trace::HTTP_SCHEME => uri.scheme,
81
83
  OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET => uri.path,
82
84
  OpenTelemetry::SemanticConventions::Trace::HTTP_URL => "#{uri.scheme}://#{uri.host}",
83
85
  OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => uri.host,
84
86
  OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => uri.port,
85
- 'http.request.method' => verb,
87
+ 'http.request.method' => span_data.normalized_method,
86
88
  'url.scheme' => uri.scheme,
87
89
  'url.path' => uri.path,
88
90
  'url.full' => "#{uri.scheme}://#{uri.host}",
@@ -90,11 +92,12 @@ module OpenTelemetry
90
92
  'server.port' => uri.port
91
93
  }
92
94
 
95
+ attributes['http.request.method_original'] = span_data.original_method if span_data.original_method
93
96
  attributes['url.query'] = uri.query unless uri.query.nil?
94
97
  attributes[OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = config[:peer_service] if config[:peer_service]
95
98
  attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
96
99
 
97
- span = tracer.start_span(verb, attributes: attributes, kind: :client, start_timestamp: start_time)
100
+ span = tracer.start_span(span_data.span_name, attributes: attributes, kind: :client, start_timestamp: start_time)
98
101
 
99
102
  OpenTelemetry::Trace.with_span(span) do
100
103
  OpenTelemetry.propagation.inject(request.headers)
@@ -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 HTTPX
10
+ # Utility module for normalizing HTTP methods according to OpenTelemetry semantic conventions
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
@@ -71,11 +71,13 @@ module OpenTelemetry
71
71
  verb = request.verb
72
72
  uri = request.uri
73
73
 
74
+ span_data = HttpHelper.span_attrs_for(verb, semconv: :old)
75
+
74
76
  config = HTTPX::Instrumentation.instance.config
75
77
 
76
78
  attributes = {
77
79
  OpenTelemetry::SemanticConventions::Trace::HTTP_HOST => uri.host,
78
- OpenTelemetry::SemanticConventions::Trace::HTTP_METHOD => verb,
80
+ OpenTelemetry::SemanticConventions::Trace::HTTP_METHOD => span_data.normalized_method,
79
81
  OpenTelemetry::SemanticConventions::Trace::HTTP_SCHEME => uri.scheme,
80
82
  OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET => uri.path,
81
83
  OpenTelemetry::SemanticConventions::Trace::HTTP_URL => "#{uri.scheme}://#{uri.host}",
@@ -86,7 +88,7 @@ module OpenTelemetry
86
88
  attributes[OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = config[:peer_service] if config[:peer_service]
87
89
  attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
88
90
 
89
- span = tracer.start_span("HTTP #{verb}", attributes: attributes, kind: :client, start_timestamp: start_time)
91
+ span = tracer.start_span(span_data.span_name, attributes: attributes, kind: :client, start_timestamp: start_time)
90
92
 
91
93
  OpenTelemetry::Trace.with_span(span) do
92
94
  OpenTelemetry.propagation.inject(request.headers)
@@ -71,21 +71,24 @@ module OpenTelemetry
71
71
  verb = request.verb
72
72
  uri = request.uri
73
73
 
74
+ span_data = HttpHelper.span_attrs_for(verb)
75
+
74
76
  config = HTTPX::Instrumentation.instance.config
75
77
 
76
78
  attributes = {
77
- 'http.request.method' => verb,
79
+ 'http.request.method' => span_data.normalized_method,
78
80
  'url.scheme' => uri.scheme,
79
81
  'url.path' => uri.path,
80
82
  'url.full' => "#{uri.scheme}://#{uri.host}",
81
83
  'server.address' => uri.host,
82
84
  'server.port' => uri.port
83
85
  }
86
+ attributes['http.request.method_original'] = span_data.original_method if span_data.original_method
84
87
  attributes['url.query'] = uri.query unless uri.query.nil?
85
88
  attributes[OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = config[:peer_service] if config[:peer_service]
86
89
  attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
87
90
 
88
- span = tracer.start_span(verb, attributes: attributes, kind: :client, start_timestamp: start_time)
91
+ span = tracer.start_span(span_data.span_name, attributes: attributes, kind: :client, start_timestamp: start_time)
89
92
 
90
93
  OpenTelemetry::Trace.with_span(span) do
91
94
  OpenTelemetry.propagation.inject(request.headers)
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module HTTPX
10
- VERSION = '0.4.1'
10
+ VERSION = '0.5.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 'httpx/http_helper'
18
19
  require_relative 'httpx/instrumentation'
19
20
  require_relative 'httpx/version'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-instrumentation-httpx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.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: HTTPX instrumentation for the OpenTelemetry framework
28
28
  email:
29
29
  - cncf-opentelemetry-contributors@lists.cncf.io
@@ -39,6 +39,7 @@ files:
39
39
  - lib/opentelemetry/instrumentation.rb
40
40
  - lib/opentelemetry/instrumentation/httpx.rb
41
41
  - lib/opentelemetry/instrumentation/httpx/dup/plugin.rb
42
+ - lib/opentelemetry/instrumentation/httpx/http_helper.rb
42
43
  - lib/opentelemetry/instrumentation/httpx/instrumentation.rb
43
44
  - lib/opentelemetry/instrumentation/httpx/old/plugin.rb
44
45
  - lib/opentelemetry/instrumentation/httpx/stable/plugin.rb
@@ -47,10 +48,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
47
48
  licenses:
48
49
  - Apache-2.0
49
50
  metadata:
50
- changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-httpx/0.4.1/file/CHANGELOG.md
51
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-httpx/0.5.1/file/CHANGELOG.md
51
52
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/http
52
53
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
53
- documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-httpx/0.4.1
54
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-httpx/0.5.1
54
55
  post_install_message:
55
56
  rdoc_options: []
56
57
  require_paths:
@@ -59,14 +60,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
60
  requirements:
60
61
  - - ">="
61
62
  - !ruby/object:Gem::Version
62
- version: '3.1'
63
+ version: '3.2'
63
64
  required_rubygems_version: !ruby/object:Gem::Requirement
64
65
  requirements:
65
66
  - - ">="
66
67
  - !ruby/object:Gem::Version
67
68
  version: '0'
68
69
  requirements: []
69
- rubygems_version: 3.3.27
70
+ rubygems_version: 3.4.19
70
71
  signing_key:
71
72
  specification_version: 4
72
73
  summary: HTTPX instrumentation for the OpenTelemetry framework