opentelemetry-instrumentation-httpx 0.5.1 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30dd73d1b0e1e1a0ad8c6d11c942a62e97402dd249b26217782761c14ae19002
4
- data.tar.gz: d9d6c07a9518e9558af0801a26ae999bfcf785854bfa0c5c6f7ae75a91124b15
3
+ metadata.gz: b345154080244595e374a9c5c73dc2bb6a3d3772c9e689aff17197d5d2745f00
4
+ data.tar.gz: b2b03b233c59c2291e429a95838f2e7bbbf23a28374784f9bd969e3ec201a589
5
5
  SHA512:
6
- metadata.gz: 7568738e6532da2c0b7f1f765d5e3e7174a78b69d352a046ff22bcab8a833bded5e0c3b5fca1e12afce3badad44e2e3666398f9dd716f485a7126737e19b2519
7
- data.tar.gz: eff4bb80b79ecc1e1b54e7dc22a4785435754fe08356ab0cccccbb145062bca309e4dd0813f6796697c420ef97f256b7b22e37bf6f4a6b7ccb9e9fd9f08fdff7
6
+ metadata.gz: fe41c4e43b96bef2caaf39830ab4a7d14ffb0ec5955f96fd71d3bb6039c06d74d9bd7fb5b8a7c547bb692a47d0e1b011fa42ea46ab76e24f705f12fe2f212c58
7
+ data.tar.gz: ac11915108072d027abe9383e0eb4cccba42b9dd891772f4f93dd4dcfc87c261918c37447357c999bc49a80b0583dfacabd8ae404075a04b40c498032a2fd711
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Release History: opentelemetry-instrumentation-httpx
2
2
 
3
+ ### v0.6.0 / 2026-01-13
4
+
5
+ * ADDED: HTTP Client Semconv v1.17 Span Naming
6
+
3
7
  ### v0.5.1 / 2025-11-25
4
8
 
5
9
  * FIXED: Update support for unknown HTTP methods to match semantic conventions
data/README.md CHANGED
@@ -63,4 +63,4 @@ When setting the value for `OTEL_SEMCONV_STABILITY_OPT_IN`, you can specify whic
63
63
 
64
64
  During the transition from old to stable conventions, HTTPX instrumentation code comes in three patch versions: `dup`, `old`, and `stable`. These versions are identical except for the attributes they send. Any changes to HTTPX instrumentation should consider all three patches.
65
65
 
66
- For additional information on migration, please refer to our [documentation](https://opentelemetry.io/docs/specs/semconv/non-normative/http-migration/).
66
+ For additional information on migration, please refer to our [documentation](https://opentelemetry.io/docs/specs/semconv/non-normative/http-migration/).
@@ -72,19 +72,17 @@ module OpenTelemetry
72
72
  verb = request.verb
73
73
  uri = request.uri
74
74
 
75
- span_data = HttpHelper.span_attrs_for(verb)
75
+ span_data = HttpHelper.span_attrs_for_dup(verb)
76
76
 
77
77
  config = HTTPX::Instrumentation.instance.config
78
78
 
79
79
  attributes = {
80
80
  OpenTelemetry::SemanticConventions::Trace::HTTP_HOST => uri.host,
81
- OpenTelemetry::SemanticConventions::Trace::HTTP_METHOD => span_data.normalized_method,
82
81
  OpenTelemetry::SemanticConventions::Trace::HTTP_SCHEME => uri.scheme,
83
82
  OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET => uri.path,
84
83
  OpenTelemetry::SemanticConventions::Trace::HTTP_URL => "#{uri.scheme}://#{uri.host}",
85
84
  OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => uri.host,
86
85
  OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => uri.port,
87
- 'http.request.method' => span_data.normalized_method,
88
86
  'url.scheme' => uri.scheme,
89
87
  'url.path' => uri.path,
90
88
  'url.full' => "#{uri.scheme}://#{uri.host}",
@@ -92,10 +90,9 @@ module OpenTelemetry
92
90
  'server.port' => uri.port
93
91
  }
94
92
 
95
- attributes['http.request.method_original'] = span_data.original_method if span_data.original_method
96
93
  attributes['url.query'] = uri.query unless uri.query.nil?
97
94
  attributes[OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = config[:peer_service] if config[:peer_service]
98
- attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
95
+ attributes.merge!(span_data.attributes)
99
96
 
100
97
  span = tracer.start_span(span_data.span_name, attributes: attributes, kind: :client, start_timestamp: start_time)
101
98
 
@@ -11,7 +11,7 @@ module OpenTelemetry
11
11
  # @api private
12
12
  module HttpHelper
13
13
  # Lightweight struct to hold span creation attributes
14
- SpanCreationAttributes = Struct.new(:span_name, :normalized_method, :original_method, keyword_init: true)
14
+ SpanCreationAttributes = Struct.new(:span_name, :attributes, keyword_init: true)
15
15
 
16
16
  # Pre-computed mapping to avoid string allocations during normalization
17
17
  METHOD_CACHE = {
@@ -44,41 +44,89 @@ module OpenTelemetry
44
44
  :trace => 'TRACE'
45
45
  }.freeze
46
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
47
+ private_constant :METHOD_CACHE
48
+
49
+ OLD_SPAN_NAMES_BY_METHOD = METHOD_CACHE.values.uniq.each_with_object({}) do |method, hash|
50
+ hash[method] = "HTTP #{method}"
51
+ end.freeze
59
52
 
60
- private_constant :METHOD_CACHE, :OLD_SPAN_NAMES
53
+ private_constant :OLD_SPAN_NAMES_BY_METHOD
61
54
 
62
- # Prepares all span data for the specified semantic convention in a single call
55
+ # Prepares span data using old semantic conventions
63
56
  # @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)
57
+ # @return [SpanCreationAttributes] struct containing span_name and attributes hash
58
+ def self.span_attrs_for_old(method)
59
+ client_context_attrs = OpenTelemetry::Common::HTTP::ClientContext.attributes
67
60
  normalized = METHOD_CACHE[method]
61
+ attributes = client_context_attrs.dup
62
+
63
+ # Determine base span name and method value
64
+ if normalized
65
+ span_name = OLD_SPAN_NAMES_BY_METHOD[normalized]
66
+ method_value = normalized
67
+ else
68
+ span_name = 'HTTP'
69
+ method_value = '_OTHER'
70
+ end
71
+
72
+ attributes['http.method'] ||= method_value
73
+
74
+ SpanCreationAttributes.new(span_name: span_name, attributes: attributes)
75
+ end
76
+
77
+ # Prepares span data using stable semantic conventions
78
+ # @param method [String, Symbol] The HTTP method
79
+ # @return [SpanCreationAttributes] struct containing span_name and attributes hash
80
+ def self.span_attrs_for_stable(method)
81
+ client_context_attrs = OpenTelemetry::Common::HTTP::ClientContext.attributes
82
+ url_template = client_context_attrs['url.template']
83
+ normalized = METHOD_CACHE[method]
84
+ attributes = client_context_attrs.dup
85
+
86
+ # Determine base span name and method value
68
87
  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
- )
88
+ base_name = normalized
89
+ method_value = normalized
90
+ original = nil
75
91
  else
76
- SpanCreationAttributes.new(
77
- span_name: 'HTTP',
78
- normalized_method: '_OTHER',
79
- original_method: method.to_s
80
- )
92
+ base_name = 'HTTP'
93
+ method_value = '_OTHER'
94
+ original = method.to_s
81
95
  end
96
+
97
+ span_name = url_template ? "#{base_name} #{url_template}" : base_name
98
+ attributes['http.request.method'] ||= method_value
99
+ attributes['http.request.method_original'] ||= original if original
100
+
101
+ SpanCreationAttributes.new(span_name: span_name, attributes: attributes)
102
+ end
103
+
104
+ # Prepares span data using both old and stable semantic conventions
105
+ # @param method [String, Symbol] The HTTP method
106
+ # @return [SpanCreationAttributes] struct containing span_name and attributes hash
107
+ def self.span_attrs_for_dup(method)
108
+ client_context_attrs = OpenTelemetry::Common::HTTP::ClientContext.attributes
109
+ url_template = client_context_attrs['url.template']
110
+ normalized = METHOD_CACHE[method]
111
+ attributes = client_context_attrs.dup
112
+
113
+ # Determine base span name and method value
114
+ if normalized
115
+ base_name = normalized
116
+ method_value = normalized
117
+ original = nil
118
+ else
119
+ base_name = 'HTTP'
120
+ method_value = '_OTHER'
121
+ original = method.to_s
122
+ end
123
+
124
+ span_name = url_template ? "#{base_name} #{url_template}" : base_name
125
+ attributes['http.method'] ||= method_value
126
+ attributes['http.request.method'] ||= method_value
127
+ attributes['http.request.method_original'] ||= original if original
128
+
129
+ SpanCreationAttributes.new(span_name: span_name, attributes: attributes)
82
130
  end
83
131
  end
84
132
  end
@@ -71,13 +71,12 @@ module OpenTelemetry
71
71
  verb = request.verb
72
72
  uri = request.uri
73
73
 
74
- span_data = HttpHelper.span_attrs_for(verb, semconv: :old)
74
+ span_data = HttpHelper.span_attrs_for_old(verb)
75
75
 
76
76
  config = HTTPX::Instrumentation.instance.config
77
77
 
78
78
  attributes = {
79
79
  OpenTelemetry::SemanticConventions::Trace::HTTP_HOST => uri.host,
80
- OpenTelemetry::SemanticConventions::Trace::HTTP_METHOD => span_data.normalized_method,
81
80
  OpenTelemetry::SemanticConventions::Trace::HTTP_SCHEME => uri.scheme,
82
81
  OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET => uri.path,
83
82
  OpenTelemetry::SemanticConventions::Trace::HTTP_URL => "#{uri.scheme}://#{uri.host}",
@@ -86,7 +85,7 @@ module OpenTelemetry
86
85
  }
87
86
 
88
87
  attributes[OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = config[:peer_service] if config[:peer_service]
89
- attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
88
+ attributes.merge!(span_data.attributes)
90
89
 
91
90
  span = tracer.start_span(span_data.span_name, attributes: attributes, kind: :client, start_timestamp: start_time)
92
91
 
@@ -71,22 +71,20 @@ module OpenTelemetry
71
71
  verb = request.verb
72
72
  uri = request.uri
73
73
 
74
- span_data = HttpHelper.span_attrs_for(verb)
74
+ span_data = HttpHelper.span_attrs_for_stable(verb)
75
75
 
76
76
  config = HTTPX::Instrumentation.instance.config
77
77
 
78
78
  attributes = {
79
- 'http.request.method' => span_data.normalized_method,
80
79
  'url.scheme' => uri.scheme,
81
80
  'url.path' => uri.path,
82
81
  'url.full' => "#{uri.scheme}://#{uri.host}",
83
82
  'server.address' => uri.host,
84
83
  'server.port' => uri.port
85
84
  }
86
- attributes['http.request.method_original'] = span_data.original_method if span_data.original_method
87
85
  attributes['url.query'] = uri.query unless uri.query.nil?
88
86
  attributes[OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = config[:peer_service] if config[:peer_service]
89
- attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
87
+ attributes.merge!(span_data.attributes)
90
88
 
91
89
  span = tracer.start_span(span_data.span_name, attributes: attributes, kind: :client, start_timestamp: start_time)
92
90
 
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module HTTPX
10
- VERSION = '0.5.1'
10
+ VERSION = '0.6.0'
11
11
  end
12
12
  end
13
13
  end
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.5.1
4
+ version: 0.6.0
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-11-25 00:00:00.000000000 Z
11
+ date: 2026-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-instrumentation-base
@@ -48,10 +48,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
48
48
  licenses:
49
49
  - Apache-2.0
50
50
  metadata:
51
- changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-httpx/0.5.1/file/CHANGELOG.md
51
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-httpx/0.6.0/file/CHANGELOG.md
52
52
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/http
53
53
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
54
- documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-httpx/0.5.1
54
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-httpx/0.6.0
55
55
  post_install_message:
56
56
  rdoc_options: []
57
57
  require_paths: