opentelemetry-instrumentation-faraday 0.30.0 → 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: 4bafda9fd097097c56f5eb2c496fcb13459545eac94ef35af88e75cfb60f4855
4
- data.tar.gz: 551305837597a22d74899fb2b761c351ecd429ed71e655f1ba9100cc002ec6e4
3
+ metadata.gz: 46f7fa87e08e43feb21e52ad6cd99a410b0970f296f92b49c70a9b9d80780467
4
+ data.tar.gz: a0e21b9ba9a4e5e85cade98b944857e3d3849715712743acfe920da964d0d76b
5
5
  SHA512:
6
- metadata.gz: a299a184c319f45a6a119d5243bf48e76c7b13795f570079d559e428de05bf9f47d9a34e3c37b9d3c6551f4169d1a800dbcbd25ebc9bfede2b0822edc62388f3
7
- data.tar.gz: 7d80941dd09d0702597c45e72f2a86df677a8f845e458db0459706899dcca23069d594c738e6651e19d319ed8e992e46894f54236f0fa509664d1a7a204d6e01
6
+ metadata.gz: 0bc58f394b3a670801edb54a6e7e14680ce3eab49342a4d3019902fc2a909278db3f4d4c02179f44bc93b1b23308d05ed21f6dda0ccfd61b71864040ee0487fd
7
+ data.tar.gz: 3bceb71ba3361ccfd4260cb2631cf983977d3619444ace55d6f77725f10b70e3f918c01740612409fb0aa069a1b6011b7acf8336a6d9301b30b4aafc6bd9ac18
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
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
+
7
+ ### v0.30.1 / 2025-11-25
8
+
9
+ * FIXED: Update support for unknown HTTP methods to match semantic conventions
10
+
3
11
  ### v0.30.0 / 2025-10-22
4
12
 
5
13
  * BREAKING CHANGE: Min Ruby Version 3.2
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
 
@@ -0,0 +1,136 @@
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 Faraday
10
+ # Utility module for HTTP-related helper methods
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
+ 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
87
+
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
98
+
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
107
+ # @param method [String, Symbol] The HTTP method
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']
112
+ normalized = METHOD_CACHE[method]
113
+ attributes = client_context_attrs.dup
114
+
115
+ # Determine base span name and method value
116
+ if normalized
117
+ base_name = normalized
118
+ method_value = normalized
119
+ original = nil
120
+ else
121
+ base_name = 'HTTP'
122
+ method_value = '_OTHER'
123
+ original = method.to_s
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)
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -12,32 +12,20 @@ module OpenTelemetry
12
12
  # TracerMiddleware propagates context and instruments Faraday requests
13
13
  # by way of its middleware system
14
14
  class TracerMiddleware < ::Faraday::Middleware
15
- HTTP_METHODS_SYMBOL_TO_STRING = {
16
- connect: 'CONNECT',
17
- delete: 'DELETE',
18
- get: 'GET',
19
- head: 'HEAD',
20
- options: 'OPTIONS',
21
- patch: 'PATCH',
22
- post: 'POST',
23
- put: 'PUT',
24
- trace: 'TRACE'
25
- }.freeze
26
-
27
15
  # Constant for the HTTP status range
28
16
  HTTP_STATUS_SUCCESS_RANGE = (100..399)
29
17
 
30
18
  def call(env)
31
- http_method = HTTP_METHODS_SYMBOL_TO_STRING[env.method]
19
+ span_data = HttpHelper.span_attrs_for_dup(env.method)
20
+
32
21
  config = Faraday::Instrumentation.instance.config
33
22
 
34
- attributes = span_creation_attributes(
35
- http_method: http_method, url: env.url, config: config
36
- )
23
+ attributes = span_creation_attributes(url: env.url, config: config)
24
+ attributes.merge!(span_data.attributes)
37
25
 
38
26
  OpenTelemetry::Common::HTTP::ClientContext.with_attributes(attributes) do |attrs, _|
39
27
  tracer.in_span(
40
- http_method, attributes: attrs, kind: config.fetch(:span_kind)
28
+ span_data.span_name, attributes: attrs, kind: config.fetch(:span_kind)
41
29
  ) do |span|
42
30
  OpenTelemetry.propagation.inject(env.request_headers)
43
31
 
@@ -58,11 +46,9 @@ module OpenTelemetry
58
46
 
59
47
  private
60
48
 
61
- def span_creation_attributes(http_method:, url:, config:)
49
+ def span_creation_attributes(url:, config:)
62
50
  cleansed_url = OpenTelemetry::Common::Utilities.cleanse_url(url.to_s)
63
51
  attrs = {
64
- 'http.method' => http_method,
65
- 'http.request.method' => http_method,
66
52
  'http.url' => cleansed_url,
67
53
  'url.full' => cleansed_url,
68
54
  'faraday.adapter.name' => app.class.name
@@ -73,9 +59,7 @@ module OpenTelemetry
73
59
  end
74
60
  attrs['peer.service'] = config[:peer_service] if config[:peer_service]
75
61
 
76
- attrs.merge!(
77
- OpenTelemetry::Common::HTTP::ClientContext.attributes
78
- )
62
+ attrs
79
63
  end
80
64
 
81
65
  # Versions prior to 1.0 do not define an accessor for app
@@ -12,32 +12,20 @@ module OpenTelemetry
12
12
  # TracerMiddleware propagates context and instruments Faraday requests
13
13
  # by way of its middleware system
14
14
  class TracerMiddleware < ::Faraday::Middleware
15
- HTTP_METHODS_SYMBOL_TO_STRING = {
16
- connect: 'CONNECT',
17
- delete: 'DELETE',
18
- get: 'GET',
19
- head: 'HEAD',
20
- options: 'OPTIONS',
21
- patch: 'PATCH',
22
- post: 'POST',
23
- put: 'PUT',
24
- trace: 'TRACE'
25
- }.freeze
26
-
27
15
  # Constant for the HTTP status range
28
16
  HTTP_STATUS_SUCCESS_RANGE = (100..399)
29
17
 
30
18
  def call(env)
31
- http_method = HTTP_METHODS_SYMBOL_TO_STRING[env.method]
19
+ span_data = HttpHelper.span_attrs_for_old(env.method)
20
+
32
21
  config = Faraday::Instrumentation.instance.config
33
22
 
34
- attributes = span_creation_attributes(
35
- http_method: http_method, url: env.url, config: config
36
- )
23
+ attributes = span_creation_attributes(url: env.url, config: config)
24
+ attributes.merge!(span_data.attributes)
37
25
 
38
26
  OpenTelemetry::Common::HTTP::ClientContext.with_attributes(attributes) do |attrs, _|
39
27
  tracer.in_span(
40
- "HTTP #{http_method}", attributes: attrs, kind: config.fetch(:span_kind)
28
+ span_data.span_name, attributes: attrs, kind: config.fetch(:span_kind)
41
29
  ) do |span|
42
30
  OpenTelemetry.propagation.inject(env.request_headers)
43
31
 
@@ -58,18 +46,15 @@ module OpenTelemetry
58
46
 
59
47
  private
60
48
 
61
- def span_creation_attributes(http_method:, url:, config:)
49
+ def span_creation_attributes(url:, config:)
62
50
  attrs = {
63
- 'http.method' => http_method,
64
51
  'http.url' => OpenTelemetry::Common::Utilities.cleanse_url(url.to_s),
65
52
  'faraday.adapter.name' => app.class.name
66
53
  }
67
54
  attrs['net.peer.name'] = url.host if url.host
68
55
  attrs['peer.service'] = config[:peer_service] if config[:peer_service]
69
56
 
70
- attrs.merge!(
71
- OpenTelemetry::Common::HTTP::ClientContext.attributes
72
- )
57
+ attrs
73
58
  end
74
59
 
75
60
  # Versions prior to 1.0 do not define an accessor for app
@@ -12,32 +12,20 @@ module OpenTelemetry
12
12
  # TracerMiddleware propagates context and instruments Faraday requests
13
13
  # by way of its middleware system
14
14
  class TracerMiddleware < ::Faraday::Middleware
15
- HTTP_METHODS_SYMBOL_TO_STRING = {
16
- connect: 'CONNECT',
17
- delete: 'DELETE',
18
- get: 'GET',
19
- head: 'HEAD',
20
- options: 'OPTIONS',
21
- patch: 'PATCH',
22
- post: 'POST',
23
- put: 'PUT',
24
- trace: 'TRACE'
25
- }.freeze
26
-
27
15
  # Constant for the HTTP status range
28
16
  HTTP_STATUS_SUCCESS_RANGE = (100..399)
29
17
 
30
18
  def call(env)
31
- http_method = HTTP_METHODS_SYMBOL_TO_STRING[env.method]
19
+ span_data = HttpHelper.span_attrs_for_stable(env.method)
20
+
32
21
  config = Faraday::Instrumentation.instance.config
33
22
 
34
- attributes = span_creation_attributes(
35
- http_method: http_method, url: env.url, config: config
36
- )
23
+ attributes = span_creation_attributes(url: env.url, config: config)
24
+ attributes.merge!(span_data.attributes)
37
25
 
38
26
  OpenTelemetry::Common::HTTP::ClientContext.with_attributes(attributes) do |attrs, _|
39
27
  tracer.in_span(
40
- http_method, attributes: attrs, kind: config.fetch(:span_kind)
28
+ span_data.span_name, attributes: attrs, kind: config.fetch(:span_kind)
41
29
  ) do |span|
42
30
  OpenTelemetry.propagation.inject(env.request_headers)
43
31
 
@@ -58,18 +46,15 @@ module OpenTelemetry
58
46
 
59
47
  private
60
48
 
61
- def span_creation_attributes(http_method:, url:, config:)
49
+ def span_creation_attributes(url:, config:)
62
50
  attrs = {
63
- 'http.request.method' => http_method,
64
51
  'url.full' => OpenTelemetry::Common::Utilities.cleanse_url(url.to_s),
65
52
  'faraday.adapter.name' => app.class.name
66
53
  }
67
54
  attrs['server.address'] = url.host if url.host
68
55
  attrs['peer.service'] = config[:peer_service] if config[:peer_service]
69
56
 
70
- attrs.merge!(
71
- OpenTelemetry::Common::HTTP::ClientContext.attributes
72
- )
57
+ attrs
73
58
  end
74
59
 
75
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.0'
10
+ VERSION = '0.31.0'
11
11
  end
12
12
  end
13
13
  end
@@ -16,5 +16,6 @@ module OpenTelemetry
16
16
  end
17
17
  end
18
18
 
19
+ require_relative 'faraday/http_helper'
19
20
  require_relative 'faraday/instrumentation'
20
21
  require_relative 'faraday/version'
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.0
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-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
@@ -38,6 +38,7 @@ files:
38
38
  - lib/opentelemetry-instrumentation-faraday.rb
39
39
  - lib/opentelemetry/instrumentation.rb
40
40
  - lib/opentelemetry/instrumentation/faraday.rb
41
+ - lib/opentelemetry/instrumentation/faraday/http_helper.rb
41
42
  - lib/opentelemetry/instrumentation/faraday/instrumentation.rb
42
43
  - lib/opentelemetry/instrumentation/faraday/middlewares/dup/tracer_middleware.rb
43
44
  - lib/opentelemetry/instrumentation/faraday/middlewares/old/tracer_middleware.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-faraday/0.30.0/file/CHANGELOG.md
54
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-faraday/0.31.0/file/CHANGELOG.md
54
55
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/faraday
55
56
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
56
- documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-faraday/0.30.0
57
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-faraday/0.31.0
57
58
  post_install_message:
58
59
  rdoc_options: []
59
60
  require_paths: