opentelemetry-instrumentation-faraday 0.30.1 → 0.31.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: b877acc5ff0551faa19a4d1a09eb5c95b63e497259369edbe20dc211ef8b3964
4
- data.tar.gz: 7860cb972bcf7747c4d3e97d8b45635beb6c67242bca36afa71ee3b663b4ede2
3
+ metadata.gz: 46f7fa87e08e43feb21e52ad6cd99a410b0970f296f92b49c70a9b9d80780467
4
+ data.tar.gz: a0e21b9ba9a4e5e85cade98b944857e3d3849715712743acfe920da964d0d76b
5
5
  SHA512:
6
- metadata.gz: 6660d12e648798d2eb55e8c11eb557d1d7c07a8fe593cb69cd025ae02b0be6a41d6d4a35c19f5a7126bfa5ab4a1b79e239cdea5c35d70f065ecff9865af5feb3
7
- data.tar.gz: d486ff5275318c336dede3e3bd5088a0d7445add80ac4c508735e2a218b8dbdcae5fbca1acf4171411012da56c662056c7e2e2ebd5750f323cecfc7ad82b2fa6
6
+ metadata.gz: 0bc58f394b3a670801edb54a6e7e14680ce3eab49342a4d3019902fc2a909278db3f4d4c02179f44bc93b1b23308d05ed21f6dda0ccfd61b71864040ee0487fd
7
+ data.tar.gz: 3bceb71ba3361ccfd4260cb2631cf983977d3619444ace55d6f77725f10b70e3f918c01740612409fb0aa069a1b6011b7acf8336a6d9301b30b4aafc6bd9ac18
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Release History: opentelemetry-instrumentation-faraday
2
2
 
3
+ ### v0.31.0 / 2026-01-13
4
+
5
+ * ADDED: HTTP Client Semconv v1.17 Span Naming
6
+
3
7
  ### v0.30.1 / 2025-11-25
4
8
 
5
9
  * FIXED: Update support for unknown HTTP methods to match semantic conventions
data/README.md CHANGED
@@ -33,9 +33,11 @@ end
33
33
  ```
34
34
 
35
35
  ### Configuration options
36
- This instrumentation offers the following configuration options:
37
- * `enable_internal_instrumentation` (default: `false`): When set to `true`, any spans with
38
- span kind of `internal` are included in traces.
36
+
37
+ This instrumentation offers the following configuration options:
38
+
39
+ - `enable_internal_instrumentation` (default: `false`): When set to `true`, any spans with
40
+ span kind of `internal` are included in traces.
39
41
 
40
42
  ## Examples
41
43
 
@@ -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,91 @@ 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
52
+
53
+ private_constant :OLD_SPAN_NAMES_BY_METHOD
54
+
55
+ module_function
56
+
57
+ # Prepares span data using old semantic conventions
58
+ # @param method [String, Symbol] The HTTP method
59
+ # @return [SpanCreationAttributes] struct containing span_name and attributes hash
60
+ def span_attrs_for_old(method)
61
+ client_context_attrs = OpenTelemetry::Common::HTTP::ClientContext.attributes
62
+ normalized = METHOD_CACHE[method]
63
+ attributes = client_context_attrs.dup
64
+
65
+ # Determine base span name and method value
66
+ if normalized
67
+ span_name = OLD_SPAN_NAMES_BY_METHOD[normalized]
68
+ method_value = normalized
69
+ else
70
+ span_name = 'HTTP'
71
+ method_value = '_OTHER'
72
+ end
73
+
74
+ attributes['http.method'] ||= method_value
75
+
76
+ SpanCreationAttributes.new(span_name: span_name, attributes: attributes)
77
+ end
78
+
79
+ # Prepares span data using stable semantic conventions
80
+ # @param method [String, Symbol] The HTTP method
81
+ # @return [SpanCreationAttributes] struct containing span_name and attributes hash
82
+ def span_attrs_for_stable(method)
83
+ client_context_attrs = OpenTelemetry::Common::HTTP::ClientContext.attributes
84
+ url_template = client_context_attrs['url.template']
85
+ normalized = METHOD_CACHE[method]
86
+ attributes = client_context_attrs.dup
59
87
 
60
- private_constant :METHOD_CACHE, :OLD_SPAN_NAMES
88
+ # Determine base span name and method value
89
+ if normalized
90
+ base_name = normalized
91
+ method_value = normalized
92
+ original = nil
93
+ else
94
+ base_name = 'HTTP'
95
+ method_value = '_OTHER'
96
+ original = method.to_s
97
+ end
61
98
 
62
- # Prepares all span data for the specified semantic convention in a single call
99
+ span_name = url_template ? "#{base_name} #{url_template}" : base_name
100
+ attributes['http.request.method'] ||= method_value
101
+ attributes['http.request.method_original'] ||= original if original
102
+
103
+ SpanCreationAttributes.new(span_name: span_name, attributes: attributes)
104
+ end
105
+
106
+ # Prepares span data using both old and stable semantic conventions
63
107
  # @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)
108
+ # @return [SpanCreationAttributes] struct containing span_name and attributes hash
109
+ def span_attrs_for_dup(method)
110
+ client_context_attrs = OpenTelemetry::Common::HTTP::ClientContext.attributes
111
+ url_template = client_context_attrs['url.template']
67
112
  normalized = METHOD_CACHE[method]
113
+ attributes = client_context_attrs.dup
114
+
115
+ # Determine base span name and method value
68
116
  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
- )
117
+ base_name = normalized
118
+ method_value = normalized
119
+ original = nil
75
120
  else
76
- SpanCreationAttributes.new(
77
- span_name: 'HTTP',
78
- normalized_method: '_OTHER',
79
- original_method: method.to_s
80
- )
121
+ base_name = 'HTTP'
122
+ method_value = '_OTHER'
123
+ original = method.to_s
81
124
  end
125
+
126
+ span_name = url_template ? "#{base_name} #{url_template}" : base_name
127
+ attributes['http.method'] ||= method_value
128
+ attributes['http.request.method'] ||= method_value
129
+ attributes['http.request.method_original'] ||= original if original
130
+
131
+ SpanCreationAttributes.new(span_name: span_name, attributes: attributes)
82
132
  end
83
133
  end
84
134
  end
@@ -16,16 +16,12 @@ module OpenTelemetry
16
16
  HTTP_STATUS_SUCCESS_RANGE = (100..399)
17
17
 
18
18
  def call(env)
19
- span_data = HttpHelper.span_attrs_for(env.method)
19
+ span_data = HttpHelper.span_attrs_for_dup(env.method)
20
20
 
21
21
  config = Faraday::Instrumentation.instance.config
22
22
 
23
- attributes = span_creation_attributes(
24
- http_method: span_data.normalized_method,
25
- original_method: span_data.original_method,
26
- url: env.url,
27
- config: config
28
- )
23
+ attributes = span_creation_attributes(url: env.url, config: config)
24
+ attributes.merge!(span_data.attributes)
29
25
 
30
26
  OpenTelemetry::Common::HTTP::ClientContext.with_attributes(attributes) do |attrs, _|
31
27
  tracer.in_span(
@@ -50,25 +46,20 @@ module OpenTelemetry
50
46
 
51
47
  private
52
48
 
53
- def span_creation_attributes(http_method:, original_method:, url:, config:)
49
+ def span_creation_attributes(url:, config:)
54
50
  cleansed_url = OpenTelemetry::Common::Utilities.cleanse_url(url.to_s)
55
51
  attrs = {
56
- 'http.method' => http_method,
57
- 'http.request.method' => http_method,
58
52
  'http.url' => cleansed_url,
59
53
  'url.full' => cleansed_url,
60
54
  'faraday.adapter.name' => app.class.name
61
55
  }
62
- attrs['http.request.method_original'] = original_method if original_method
63
56
  if url.host
64
57
  attrs['net.peer.name'] = url.host
65
58
  attrs['server.address'] = url.host
66
59
  end
67
60
  attrs['peer.service'] = config[:peer_service] if config[:peer_service]
68
61
 
69
- attrs.merge!(
70
- OpenTelemetry::Common::HTTP::ClientContext.attributes
71
- )
62
+ attrs
72
63
  end
73
64
 
74
65
  # Versions prior to 1.0 do not define an accessor for app
@@ -16,13 +16,12 @@ module OpenTelemetry
16
16
  HTTP_STATUS_SUCCESS_RANGE = (100..399)
17
17
 
18
18
  def call(env)
19
- span_data = HttpHelper.span_attrs_for(env.method, semconv: :old)
19
+ span_data = HttpHelper.span_attrs_for_old(env.method)
20
20
 
21
21
  config = Faraday::Instrumentation.instance.config
22
22
 
23
- attributes = span_creation_attributes(
24
- http_method: span_data.normalized_method, url: env.url, config: config
25
- )
23
+ attributes = span_creation_attributes(url: env.url, config: config)
24
+ attributes.merge!(span_data.attributes)
26
25
 
27
26
  OpenTelemetry::Common::HTTP::ClientContext.with_attributes(attributes) do |attrs, _|
28
27
  tracer.in_span(
@@ -47,18 +46,15 @@ module OpenTelemetry
47
46
 
48
47
  private
49
48
 
50
- def span_creation_attributes(http_method:, url:, config:)
49
+ def span_creation_attributes(url:, config:)
51
50
  attrs = {
52
- 'http.method' => http_method,
53
51
  'http.url' => OpenTelemetry::Common::Utilities.cleanse_url(url.to_s),
54
52
  'faraday.adapter.name' => app.class.name
55
53
  }
56
54
  attrs['net.peer.name'] = url.host if url.host
57
55
  attrs['peer.service'] = config[:peer_service] if config[:peer_service]
58
56
 
59
- attrs.merge!(
60
- OpenTelemetry::Common::HTTP::ClientContext.attributes
61
- )
57
+ attrs
62
58
  end
63
59
 
64
60
  # Versions prior to 1.0 do not define an accessor for app
@@ -16,16 +16,12 @@ module OpenTelemetry
16
16
  HTTP_STATUS_SUCCESS_RANGE = (100..399)
17
17
 
18
18
  def call(env)
19
- span_data = HttpHelper.span_attrs_for(env.method)
19
+ span_data = HttpHelper.span_attrs_for_stable(env.method)
20
20
 
21
21
  config = Faraday::Instrumentation.instance.config
22
22
 
23
- attributes = span_creation_attributes(
24
- http_method: span_data.normalized_method,
25
- original_method: span_data.original_method,
26
- url: env.url,
27
- config: config
28
- )
23
+ attributes = span_creation_attributes(url: env.url, config: config)
24
+ attributes.merge!(span_data.attributes)
29
25
 
30
26
  OpenTelemetry::Common::HTTP::ClientContext.with_attributes(attributes) do |attrs, _|
31
27
  tracer.in_span(
@@ -50,19 +46,15 @@ module OpenTelemetry
50
46
 
51
47
  private
52
48
 
53
- def span_creation_attributes(http_method:, original_method:, url:, config:)
49
+ def span_creation_attributes(url:, config:)
54
50
  attrs = {
55
- 'http.request.method' => http_method,
56
51
  'url.full' => OpenTelemetry::Common::Utilities.cleanse_url(url.to_s),
57
52
  'faraday.adapter.name' => app.class.name
58
53
  }
59
- attrs['http.request.method_original'] = original_method if original_method
60
54
  attrs['server.address'] = url.host if url.host
61
55
  attrs['peer.service'] = config[:peer_service] if config[:peer_service]
62
56
 
63
- attrs.merge!(
64
- OpenTelemetry::Common::HTTP::ClientContext.attributes
65
- )
57
+ attrs
66
58
  end
67
59
 
68
60
  # Versions prior to 1.0 do not define an accessor for app
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module Faraday
10
- VERSION = '0.30.1'
10
+ VERSION = '0.31.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-faraday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.30.1
4
+ version: 0.31.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
@@ -51,10 +51,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
51
51
  licenses:
52
52
  - Apache-2.0
53
53
  metadata:
54
- changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-faraday/0.30.1/file/CHANGELOG.md
54
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-faraday/0.31.0/file/CHANGELOG.md
55
55
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/faraday
56
56
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
57
- documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-faraday/0.30.1
57
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-faraday/0.31.0
58
58
  post_install_message:
59
59
  rdoc_options: []
60
60
  require_paths: