opentelemetry-instrumentation-faraday 0.30.0 → 0.30.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/opentelemetry/instrumentation/faraday/http_helper.rb +86 -0
- data/lib/opentelemetry/instrumentation/faraday/middlewares/dup/tracer_middleware.rb +9 -16
- data/lib/opentelemetry/instrumentation/faraday/middlewares/old/tracer_middleware.rb +4 -15
- data/lib/opentelemetry/instrumentation/faraday/middlewares/stable/tracer_middleware.rb +9 -16
- data/lib/opentelemetry/instrumentation/faraday/version.rb +1 -1
- data/lib/opentelemetry/instrumentation/faraday.rb +1 -0
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b877acc5ff0551faa19a4d1a09eb5c95b63e497259369edbe20dc211ef8b3964
|
|
4
|
+
data.tar.gz: 7860cb972bcf7747c4d3e97d8b45635beb6c67242bca36afa71ee3b663b4ede2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6660d12e648798d2eb55e8c11eb557d1d7c07a8fe593cb69cd025ae02b0be6a41d6d4a35c19f5a7126bfa5ab4a1b79e239cdea5c35d70f065ecff9865af5feb3
|
|
7
|
+
data.tar.gz: d486ff5275318c336dede3e3bd5088a0d7445add80ac4c508735e2a218b8dbdcae5fbca1acf4171411012da56c662056c7e2e2ebd5750f323cecfc7ad82b2fa6
|
data/CHANGELOG.md
CHANGED
|
@@ -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 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, :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
|
|
@@ -12,32 +12,24 @@ 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
|
-
|
|
19
|
+
span_data = HttpHelper.span_attrs_for(env.method)
|
|
20
|
+
|
|
32
21
|
config = Faraday::Instrumentation.instance.config
|
|
33
22
|
|
|
34
23
|
attributes = span_creation_attributes(
|
|
35
|
-
http_method:
|
|
24
|
+
http_method: span_data.normalized_method,
|
|
25
|
+
original_method: span_data.original_method,
|
|
26
|
+
url: env.url,
|
|
27
|
+
config: config
|
|
36
28
|
)
|
|
37
29
|
|
|
38
30
|
OpenTelemetry::Common::HTTP::ClientContext.with_attributes(attributes) do |attrs, _|
|
|
39
31
|
tracer.in_span(
|
|
40
|
-
|
|
32
|
+
span_data.span_name, attributes: attrs, kind: config.fetch(:span_kind)
|
|
41
33
|
) do |span|
|
|
42
34
|
OpenTelemetry.propagation.inject(env.request_headers)
|
|
43
35
|
|
|
@@ -58,7 +50,7 @@ module OpenTelemetry
|
|
|
58
50
|
|
|
59
51
|
private
|
|
60
52
|
|
|
61
|
-
def span_creation_attributes(http_method:, url:, config:)
|
|
53
|
+
def span_creation_attributes(http_method:, original_method:, url:, config:)
|
|
62
54
|
cleansed_url = OpenTelemetry::Common::Utilities.cleanse_url(url.to_s)
|
|
63
55
|
attrs = {
|
|
64
56
|
'http.method' => http_method,
|
|
@@ -67,6 +59,7 @@ module OpenTelemetry
|
|
|
67
59
|
'url.full' => cleansed_url,
|
|
68
60
|
'faraday.adapter.name' => app.class.name
|
|
69
61
|
}
|
|
62
|
+
attrs['http.request.method_original'] = original_method if original_method
|
|
70
63
|
if url.host
|
|
71
64
|
attrs['net.peer.name'] = url.host
|
|
72
65
|
attrs['server.address'] = url.host
|
|
@@ -12,32 +12,21 @@ 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
|
-
|
|
19
|
+
span_data = HttpHelper.span_attrs_for(env.method, semconv: :old)
|
|
20
|
+
|
|
32
21
|
config = Faraday::Instrumentation.instance.config
|
|
33
22
|
|
|
34
23
|
attributes = span_creation_attributes(
|
|
35
|
-
http_method:
|
|
24
|
+
http_method: span_data.normalized_method, url: env.url, config: config
|
|
36
25
|
)
|
|
37
26
|
|
|
38
27
|
OpenTelemetry::Common::HTTP::ClientContext.with_attributes(attributes) do |attrs, _|
|
|
39
28
|
tracer.in_span(
|
|
40
|
-
|
|
29
|
+
span_data.span_name, attributes: attrs, kind: config.fetch(:span_kind)
|
|
41
30
|
) do |span|
|
|
42
31
|
OpenTelemetry.propagation.inject(env.request_headers)
|
|
43
32
|
|
|
@@ -12,32 +12,24 @@ 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
|
-
|
|
19
|
+
span_data = HttpHelper.span_attrs_for(env.method)
|
|
20
|
+
|
|
32
21
|
config = Faraday::Instrumentation.instance.config
|
|
33
22
|
|
|
34
23
|
attributes = span_creation_attributes(
|
|
35
|
-
http_method:
|
|
24
|
+
http_method: span_data.normalized_method,
|
|
25
|
+
original_method: span_data.original_method,
|
|
26
|
+
url: env.url,
|
|
27
|
+
config: config
|
|
36
28
|
)
|
|
37
29
|
|
|
38
30
|
OpenTelemetry::Common::HTTP::ClientContext.with_attributes(attributes) do |attrs, _|
|
|
39
31
|
tracer.in_span(
|
|
40
|
-
|
|
32
|
+
span_data.span_name, attributes: attrs, kind: config.fetch(:span_kind)
|
|
41
33
|
) do |span|
|
|
42
34
|
OpenTelemetry.propagation.inject(env.request_headers)
|
|
43
35
|
|
|
@@ -58,12 +50,13 @@ module OpenTelemetry
|
|
|
58
50
|
|
|
59
51
|
private
|
|
60
52
|
|
|
61
|
-
def span_creation_attributes(http_method:, url:, config:)
|
|
53
|
+
def span_creation_attributes(http_method:, original_method:, url:, config:)
|
|
62
54
|
attrs = {
|
|
63
55
|
'http.request.method' => http_method,
|
|
64
56
|
'url.full' => OpenTelemetry::Common::Utilities.cleanse_url(url.to_s),
|
|
65
57
|
'faraday.adapter.name' => app.class.name
|
|
66
58
|
}
|
|
59
|
+
attrs['http.request.method_original'] = original_method if original_method
|
|
67
60
|
attrs['server.address'] = url.host if url.host
|
|
68
61
|
attrs['peer.service'] = config[:peer_service] if config[:peer_service]
|
|
69
62
|
|
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.
|
|
4
|
+
version: 0.30.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-
|
|
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
|
|
@@ -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.
|
|
54
|
+
changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-faraday/0.30.1/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.
|
|
57
|
+
documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-faraday/0.30.1
|
|
57
58
|
post_install_message:
|
|
58
59
|
rdoc_options: []
|
|
59
60
|
require_paths:
|