opentelemetry-instrumentation-httpx 0.5.0 → 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: 6487fc4d89f7b954e2a4a7f3a12e1cea61742eac2d9043c34d3a93743024d363
4
- data.tar.gz: 61dfba5ba4bbf2ff8950640ce4327ebdb27e2d0aa48c1aea4af599941e3c2006
3
+ metadata.gz: b345154080244595e374a9c5c73dc2bb6a3d3772c9e689aff17197d5d2745f00
4
+ data.tar.gz: b2b03b233c59c2291e429a95838f2e7bbbf23a28374784f9bd969e3ec201a589
5
5
  SHA512:
6
- metadata.gz: 9f6c6dd2c2e2fdb41f96d214b3f14b54c28a4d2bce7c96541bfc0292602773b9714499cfc9b8b095d777c5baea8c6e010071197806b2b2c713fb20c391dceb92
7
- data.tar.gz: 6958b119d19337ec8b8c38dd7a96a21c6ac72299f59983e0835e96e8ff4b047b07ed0264e3555af499a90a27dd7cd6291e837d6a8778d2ee55c1afb9cc7e37ba
6
+ metadata.gz: fe41c4e43b96bef2caaf39830ab4a7d14ffb0ec5955f96fd71d3bb6039c06d74d9bd7fb5b8a7c547bb692a47d0e1b011fa42ea46ab76e24f705f12fe2f212c58
7
+ data.tar.gz: ac11915108072d027abe9383e0eb4cccba42b9dd891772f4f93dd4dcfc87c261918c37447357c999bc49a80b0583dfacabd8ae404075a04b40c498032a2fd711
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
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
+
7
+ ### v0.5.1 / 2025-11-25
8
+
9
+ * FIXED: Update support for unknown HTTP methods to match semantic conventions
10
+
3
11
  ### v0.5.0 / 2025-10-22
4
12
 
5
13
  * BREAKING CHANGE: Min Ruby Version 3.2
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,17 +72,17 @@ module OpenTelemetry
72
72
  verb = request.verb
73
73
  uri = request.uri
74
74
 
75
+ span_data = HttpHelper.span_attrs_for_dup(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,
80
81
  OpenTelemetry::SemanticConventions::Trace::HTTP_SCHEME => uri.scheme,
81
82
  OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET => uri.path,
82
83
  OpenTelemetry::SemanticConventions::Trace::HTTP_URL => "#{uri.scheme}://#{uri.host}",
83
84
  OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => uri.host,
84
85
  OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => uri.port,
85
- 'http.request.method' => verb,
86
86
  'url.scheme' => uri.scheme,
87
87
  'url.path' => uri.path,
88
88
  'url.full' => "#{uri.scheme}://#{uri.host}",
@@ -92,9 +92,9 @@ module OpenTelemetry
92
92
 
93
93
  attributes['url.query'] = uri.query unless uri.query.nil?
94
94
  attributes[OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = config[:peer_service] if config[:peer_service]
95
- attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
95
+ attributes.merge!(span_data.attributes)
96
96
 
97
- span = tracer.start_span(verb, attributes: attributes, kind: :client, start_timestamp: start_time)
97
+ span = tracer.start_span(span_data.span_name, attributes: attributes, kind: :client, start_timestamp: start_time)
98
98
 
99
99
  OpenTelemetry::Trace.with_span(span) do
100
100
  OpenTelemetry.propagation.inject(request.headers)
@@ -0,0 +1,134 @@
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, :attributes, 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
+ 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
52
+
53
+ private_constant :OLD_SPAN_NAMES_BY_METHOD
54
+
55
+ # Prepares span data using old semantic conventions
56
+ # @param method [String, Symbol] The HTTP method
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
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
87
+ if normalized
88
+ base_name = normalized
89
+ method_value = normalized
90
+ original = nil
91
+ else
92
+ base_name = 'HTTP'
93
+ method_value = '_OTHER'
94
+ original = method.to_s
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)
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
@@ -71,11 +71,12 @@ module OpenTelemetry
71
71
  verb = request.verb
72
72
  uri = request.uri
73
73
 
74
+ span_data = HttpHelper.span_attrs_for_old(verb)
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,
79
80
  OpenTelemetry::SemanticConventions::Trace::HTTP_SCHEME => uri.scheme,
80
81
  OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET => uri.path,
81
82
  OpenTelemetry::SemanticConventions::Trace::HTTP_URL => "#{uri.scheme}://#{uri.host}",
@@ -84,9 +85,9 @@ module OpenTelemetry
84
85
  }
85
86
 
86
87
  attributes[OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = config[:peer_service] if config[:peer_service]
87
- attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
88
+ attributes.merge!(span_data.attributes)
88
89
 
89
- span = tracer.start_span("HTTP #{verb}", attributes: attributes, kind: :client, start_timestamp: start_time)
90
+ span = tracer.start_span(span_data.span_name, attributes: attributes, kind: :client, start_timestamp: start_time)
90
91
 
91
92
  OpenTelemetry::Trace.with_span(span) do
92
93
  OpenTelemetry.propagation.inject(request.headers)
@@ -71,10 +71,11 @@ module OpenTelemetry
71
71
  verb = request.verb
72
72
  uri = request.uri
73
73
 
74
+ span_data = HttpHelper.span_attrs_for_stable(verb)
75
+
74
76
  config = HTTPX::Instrumentation.instance.config
75
77
 
76
78
  attributes = {
77
- 'http.request.method' => verb,
78
79
  'url.scheme' => uri.scheme,
79
80
  'url.path' => uri.path,
80
81
  'url.full' => "#{uri.scheme}://#{uri.host}",
@@ -83,9 +84,9 @@ module OpenTelemetry
83
84
  }
84
85
  attributes['url.query'] = uri.query unless uri.query.nil?
85
86
  attributes[OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = config[:peer_service] if config[:peer_service]
86
- attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
87
+ attributes.merge!(span_data.attributes)
87
88
 
88
- span = tracer.start_span(verb, attributes: attributes, kind: :client, start_timestamp: start_time)
89
+ span = tracer.start_span(span_data.span_name, attributes: attributes, kind: :client, start_timestamp: start_time)
89
90
 
90
91
  OpenTelemetry::Trace.with_span(span) do
91
92
  OpenTelemetry.propagation.inject(request.headers)
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module HTTPX
10
- VERSION = '0.5.0'
10
+ VERSION = '0.6.0'
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.5.0
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-10-22 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
@@ -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.5.0/file/CHANGELOG.md
51
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-httpx/0.6.0/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.5.0
54
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-httpx/0.6.0
54
55
  post_install_message:
55
56
  rdoc_options: []
56
57
  require_paths: