Skip to content

Commit a5fb642

Browse files
committed
moved
1 parent f65339f commit a5fb642

File tree

30 files changed

+336
-253
lines changed

30 files changed

+336
-253
lines changed

Rakefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ task default: [:each]
3636

3737
def foreach_gem(cmd)
3838
Dir.glob("**/opentelemetry-*.gemspec") do |gemspec|
39-
name = File.basename(gemspec, ".gemspec")
39+
next if gemspec.start_with?('.')
40+
4041
dir = File.dirname(gemspec)
4142
puts "**** Entering #{dir}"
4243
Dir.chdir(dir) do

instrumentation/all/Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ group :test do
3333
Dir.entries('../')
3434
.select { |entry| File.directory?(File.join('../', entry)) }
3535
.reject { |entry| excluded_instrumentations.include?(entry) }
36+
.reject { |entry| entry.start_with?('.') }
3637
.sort
3738
.each { |dir| gem "opentelemetry-instrumentation-#{dir}", path: "../#{dir}" }
3839
end

instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/http_helper.rb

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Ethon
1111
# @api private
1212
module HttpHelper
1313
# 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)
1515

1616
# Pre-computed mapping to avoid string allocations during normalization
1717
METHOD_CACHE = {
@@ -48,25 +48,45 @@ module HttpHelper
4848

4949
# Prepares all span data in a single call
5050
# @param method [String, Symbol] The HTTP method
51-
# @return [SpanCreationAttributes] struct containing span_name, normalized_method, and original_method
52-
def self.span_attrs_for(method)
53-
url_template = OpenTelemetry::Common::HTTP::ClientContext.attributes['url.template']
51+
# @param semconv [Symbol] Semantic convention to use (:old, :stable, or :dup)
52+
# @return [SpanCreationAttributes] struct containing span_name and attributes hash
53+
def self.span_attrs_for(method, semconv: :old)
54+
client_context_attrs = OpenTelemetry::Common::HTTP::ClientContext.attributes
55+
url_template = client_context_attrs['url.template']
5456
normalized = METHOD_CACHE[method]
57+
attributes = client_context_attrs.dup
58+
59+
# Determine base span name and method value
5560
if normalized
56-
span_name = url_template ? "#{normalized} #{url_template}" : normalized
57-
SpanCreationAttributes.new(
58-
span_name: span_name,
59-
normalized_method: normalized,
60-
original_method: nil
61-
)
61+
base_name = normalized
62+
method_value = normalized
6263
else
63-
span_name = url_template ? "HTTP #{url_template}" : 'HTTP'
64-
SpanCreationAttributes.new(
65-
span_name: span_name,
66-
normalized_method: '_OTHER',
67-
original_method: method.to_s
68-
)
64+
base_name = 'HTTP'
65+
method_value = '_OTHER'
66+
original = method.to_s
6967
end
68+
69+
# Set span name based on semantic convention
70+
span_name = if semconv == :old
71+
base_name
72+
else
73+
(url_template ? "#{base_name} #{url_template}" : base_name)
74+
end
75+
76+
# Set attributes based on semantic convention
77+
case semconv
78+
when :old
79+
attributes['http.method'] ||= method_value
80+
when :stable
81+
attributes['http.request.method'] ||= method_value
82+
attributes['http.request.method_original'] ||= original if original
83+
when :dup
84+
attributes['http.method'] ||= method_value
85+
attributes['http.request.method'] ||= method_value
86+
attributes['http.request.method_original'] ||= original if original
87+
end
88+
89+
SpanCreationAttributes.new(span_name: span_name, attributes: attributes)
7090
end
7191
end
7292
end

instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/dup/easy.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ def reset
6868
end
6969

7070
def otel_before_request
71-
span_data = HttpHelper.span_attrs_for(@otel_method)
71+
span_data = HttpHelper.span_attrs_for(@otel_method, semconv: :dup)
7272

7373
@otel_span = tracer.start_span(
7474
span_data.span_name,
75-
attributes: span_creation_attributes(span_data, client_context_attrs),
75+
attributes: span_creation_attributes(span_data),
7676
kind: :client
7777
)
7878

@@ -89,12 +89,8 @@ def otel_span_started?
8989

9090
private
9191

92-
def span_creation_attributes(span_data, client_context_attrs)
93-
instrumentation_attrs = {
94-
'http.method' => span_data.normalized_method,
95-
'http.request.method' => span_data.normalized_method
96-
}
97-
instrumentation_attrs['http.request.method_original'] = span_data.original_method if span_data.original_method
92+
def span_creation_attributes(span_data)
93+
instrumentation_attrs = {}
9894

9995
uri = _otel_cleanse_uri(url)
10096
if uri
@@ -106,7 +102,7 @@ def span_creation_attributes(span_data, client_context_attrs)
106102

107103
config = Ethon::Instrumentation.instance.config
108104
instrumentation_attrs['peer.service'] = config[:peer_service] if config[:peer_service]
109-
instrumentation_attrs.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
105+
instrumentation_attrs.merge!(span_data.attributes)
110106
end
111107

112108
# Returns a URL string with userinfo removed.

instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/old/easy.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ def reset
6767
end
6868

6969
def otel_before_request
70-
span_data = HttpHelper.span_attrs_for(@otel_method)
70+
span_data = HttpHelper.span_attrs_for(@otel_method, semconv: :old)
7171

7272
@otel_span = tracer.start_span(
7373
span_data.span_name,
74-
attributes: span_creation_attributes(span_data, client_context_attrs),
74+
attributes: span_creation_attributes(span_data),
7575
kind: :client
7676
)
7777

@@ -88,9 +88,8 @@ def otel_span_started?
8888

8989
private
9090

91-
def span_creation_attributes(span_data, client_context_attrs)
91+
def span_creation_attributes(span_data)
9292
instrumentation_attrs = {
93-
'http.method' => span_data.normalized_method
9493
}
9594

9695
uri = _otel_cleanse_uri(url)
@@ -101,7 +100,7 @@ def span_creation_attributes(span_data, client_context_attrs)
101100

102101
config = Ethon::Instrumentation.instance.config
103102
instrumentation_attrs['peer.service'] = config[:peer_service] if config[:peer_service]
104-
instrumentation_attrs.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
103+
instrumentation_attrs.merge!(span_data.attributes)
105104
end
106105

107106
# Returns a URL string with userinfo removed.

instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/stable/easy.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ def reset
6767
end
6868

6969
def otel_before_request
70-
span_data = HttpHelper.span_attrs_for(@otel_method)
70+
span_data = HttpHelper.span_attrs_for(@otel_method, semconv: :stable)
7171

7272
@otel_span = tracer.start_span(
7373
span_data.span_name,
74-
attributes: span_creation_attributes(span_data, client_context_attrs),
74+
attributes: span_creation_attributes(span_data),
7575
kind: :client
7676
)
7777

@@ -88,11 +88,8 @@ def otel_span_started?
8888

8989
private
9090

91-
def span_creation_attributes(span_data, client_context_attrs)
92-
instrumentation_attrs = {
93-
'http.request.method' => span_data.normalized_method
94-
}
95-
instrumentation_attrs['http.request.method_original'] = span_data.original_method if span_data.original_method
91+
def span_creation_attributes(span_data)
92+
instrumentation_attrs = { }
9693

9794
uri = _otel_cleanse_uri(url)
9895
if uri
@@ -102,7 +99,7 @@ def span_creation_attributes(span_data, client_context_attrs)
10299

103100
config = Ethon::Instrumentation.instance.config
104101
instrumentation_attrs['peer.service'] = config[:peer_service] if config[:peer_service]
105-
instrumentation_attrs.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
102+
instrumentation_attrs.merge!(span_data.attributes)
106103
end
107104

108105
# Returns a URL string with userinfo removed.

instrumentation/excon/lib/opentelemetry/instrumentation/excon/http_helper.rb

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ module Excon
1010
# Utility module for HTTP-related helper methods
1111
# @api private
1212
module HttpHelper
13-
# Lightweight struct to hold span creation attributes
14-
SpanCreationAttributes = Struct.new(:span_name, :normalized_method, :original_method, keyword_init: true)
13+
# Lightweight struct to hold span creation data
14+
SpanCreationAttributes = Struct.new(:span_name, :attributes, keyword_init: true)
1515

1616
# Pre-computed mapping to avoid string allocations during normalization
1717
METHOD_CACHE = {
@@ -46,27 +46,47 @@ module HttpHelper
4646

4747
private_constant :METHOD_CACHE
4848

49-
# Prepares all span data in a single call
49+
# Prepares all span data in a single call, including ClientContext attributes
5050
# @param method [String, Symbol] The HTTP method
51-
# @return [SpanCreationAttributes] struct containing span_name, normalized_method, and original_method
52-
def self.span_attrs_for(method)
53-
url_template = OpenTelemetry::Common::HTTP::ClientContext.attributes['url.template']
51+
# @param semconv [Symbol] Semantic convention to use (:old, :stable, or :dup)
52+
# @return [SpanCreationAttributes] struct containing span_name and attributes hash
53+
def self.span_attrs_for(method, semconv: :old)
54+
client_context_attrs = OpenTelemetry::Common::HTTP::ClientContext.attributes
55+
url_template = client_context_attrs['url.template']
5456
normalized = METHOD_CACHE[method]
57+
attributes = client_context_attrs.dup
58+
59+
# Determine base span name and method value
5560
if normalized
56-
span_name = url_template ? "#{normalized} #{url_template}" : normalized
57-
SpanCreationAttributes.new(
58-
span_name: span_name,
59-
normalized_method: normalized,
60-
original_method: nil
61-
)
61+
base_name = normalized
62+
method_value = normalized
6263
else
63-
span_name = url_template ? "HTTP #{url_template}" : 'HTTP'
64-
SpanCreationAttributes.new(
65-
span_name: span_name,
66-
normalized_method: '_OTHER',
67-
original_method: method.to_s
68-
)
64+
base_name = 'HTTP'
65+
method_value = '_OTHER'
66+
original = method.to_s
6967
end
68+
69+
# Set span name based on semantic convention
70+
span_name = if semconv == :old
71+
base_name
72+
else
73+
(url_template ? "#{base_name} #{url_template}" : base_name)
74+
end
75+
76+
# Set attributes based on semantic convention
77+
case semconv
78+
when :old
79+
attributes['http.method'] ||= method_value
80+
when :stable
81+
attributes['http.request.method'] ||= method_value
82+
attributes['http.request.method_original'] ||= original if original
83+
when :dup
84+
attributes['http.method'] ||= method_value
85+
attributes['http.request.method'] ||= method_value
86+
attributes['http.request.method_original'] ||= original if original
87+
end
88+
89+
SpanCreationAttributes.new(span_name: span_name, attributes: attributes)
7090
end
7191
end
7292
end

instrumentation/excon/lib/opentelemetry/instrumentation/excon/middlewares/dup/tracer_middleware.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,26 @@ class TracerMiddleware < ::Excon::Middleware::Base
1717
def request_call(datum)
1818
return @stack.request_call(datum) if untraced?(datum)
1919

20-
span_data = HttpHelper.span_attrs_for(datum[:method])
20+
span_data = HttpHelper.span_attrs_for(datum[:method], semconv: :dup)
2121

2222
cleansed_url = OpenTelemetry::Common::Utilities.cleanse_url(::Excon::Utils.request_uri(datum))
2323
attributes = {
2424
OpenTelemetry::SemanticConventions::Trace::HTTP_HOST => datum[:host],
25-
OpenTelemetry::SemanticConventions::Trace::HTTP_METHOD => span_data.normalized_method,
2625
OpenTelemetry::SemanticConventions::Trace::HTTP_SCHEME => datum[:scheme],
2726
OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET => datum[:path],
2827
OpenTelemetry::SemanticConventions::Trace::HTTP_URL => cleansed_url,
2928
OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => datum[:hostname],
3029
OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => datum[:port],
31-
'http.request.method' => span_data.normalized_method,
3230
'url.scheme' => datum[:scheme],
3331
'url.path' => datum[:path],
3432
'url.full' => cleansed_url,
3533
'server.address' => datum[:hostname],
3634
'server.port' => datum[:port]
3735
}
38-
attributes['http.request.method_original'] = span_data.original_method if span_data.original_method
3936
attributes['url.query'] = datum[:query] if datum[:query]
4037
peer_service = Excon::Instrumentation.instance.config[:peer_service]
4138
attributes[OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = peer_service if peer_service
42-
attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
39+
attributes.merge!(span_data.attributes)
4340
span = tracer.start_span(span_data.span_name, attributes: attributes, kind: :client)
4441
ctx = OpenTelemetry::Trace.context_with_span(span)
4542
datum[:otel_span] = span

instrumentation/excon/lib/opentelemetry/instrumentation/excon/middlewares/old/tracer_middleware.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ class TracerMiddleware < ::Excon::Middleware::Base
1717
def request_call(datum)
1818
return @stack.request_call(datum) if untraced?(datum)
1919

20-
span_data = HttpHelper.span_attrs_for(datum[:method])
20+
span_data = HttpHelper.span_attrs_for(datum[:method], semconv: :old)
2121

2222
attributes = {
2323
OpenTelemetry::SemanticConventions::Trace::HTTP_HOST => datum[:host],
24-
OpenTelemetry::SemanticConventions::Trace::HTTP_METHOD => span_data.normalized_method,
2524
OpenTelemetry::SemanticConventions::Trace::HTTP_SCHEME => datum[:scheme],
2625
OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET => datum[:path],
2726
OpenTelemetry::SemanticConventions::Trace::HTTP_URL => OpenTelemetry::Common::Utilities.cleanse_url(::Excon::Utils.request_uri(datum)),
@@ -30,7 +29,7 @@ def request_call(datum)
3029
}
3130
peer_service = Excon::Instrumentation.instance.config[:peer_service]
3231
attributes[OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = peer_service if peer_service
33-
attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
32+
attributes.merge!(span_data.attributes)
3433
span = tracer.start_span(span_data.span_name, attributes: attributes, kind: :client)
3534
ctx = OpenTelemetry::Trace.context_with_span(span)
3635
datum[:otel_span] = span

instrumentation/excon/lib/opentelemetry/instrumentation/excon/middlewares/stable/tracer_middleware.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,18 @@ class TracerMiddleware < ::Excon::Middleware::Base
1717
def request_call(datum)
1818
return @stack.request_call(datum) if untraced?(datum)
1919

20-
span_data = HttpHelper.span_attrs_for(datum[:method])
20+
span_data = HttpHelper.span_attrs_for(datum[:method], semconv: :stable)
2121

22-
attributes = {
23-
'http.request.method' => span_data.normalized_method,
24-
'url.scheme' => datum[:scheme],
22+
attributes = { 'url.scheme' => datum[:scheme],
2523
'url.path' => datum[:path],
2624
'url.full' => OpenTelemetry::Common::Utilities.cleanse_url(::Excon::Utils.request_uri(datum)),
2725
'server.address' => datum[:hostname],
2826
'server.port' => datum[:port]
2927
}
30-
attributes['http.request.method_original'] = span_data.original_method if span_data.original_method
3128
attributes['url.query'] = datum[:query] if datum[:query]
3229
peer_service = Excon::Instrumentation.instance.config[:peer_service]
3330
attributes[OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE] = peer_service if peer_service
34-
attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
31+
attributes.merge!(span_data.attributes)
3532
span = tracer.start_span(span_data.span_name, attributes: attributes, kind: :client)
3633
ctx = OpenTelemetry::Trace.context_with_span(span)
3734
datum[:otel_span] = span

0 commit comments

Comments
 (0)