Skip to content

Commit 1dd6810

Browse files
committed
fix: update span names when no method is avaliable
1 parent 19961a2 commit 1dd6810

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ module Easy
1616
# #to_s is required because user input could be symbol or string
1717
h[k] = k.to_s.upcase
1818
end
19-
HTTP_METHODS_TO_SPAN_NAMES = Hash.new { |h, k| h[k] = k.to_s }
19+
HTTP_METHODS_TO_SPAN_NAMES = Hash.new do |h, k|
20+
h[k] = k.to_s
21+
h[k] = 'HTTP' if k == '_OTHER'
22+
end
2023

2124
# Constant for the HTTP status range
2225
HTTP_STATUS_SUCCESS_RANGE = (100..399)
@@ -66,7 +69,7 @@ def reset
6669
end
6770

6871
def otel_before_request
69-
method = 'N/A' # Could be GET or not HTTP at all
72+
method = '_OTHER' # Could be GET or not HTTP at all
7073
method = @otel_method if instance_variable_defined?(:@otel_method) && !@otel_method.nil?
7174

7275
@otel_span = tracer.start_span(
@@ -89,8 +92,9 @@ def otel_span_started?
8992
private
9093

9194
def span_creation_attributes(method)
95+
http_method = (method == '_OTHER' ? 'N/A' : method)
9296
instrumentation_attrs = {
93-
'http.method' => method,
97+
'http.method' => http_method,
9498
'http.request.method' => method
9599
}
96100

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ module Easy
1616
# #to_s is required because user input could be symbol or string
1717
h[k] = k.to_s.upcase
1818
end
19-
HTTP_METHODS_TO_SPAN_NAMES = Hash.new { |h, k| h[k] = k.to_s }
19+
HTTP_METHODS_TO_SPAN_NAMES = Hash.new do |h, k|
20+
h[k] = k.to_s
21+
h[k] = 'HTTP' if k == '_OTHER'
22+
end
2023

2124
# Constant for the HTTP status range
2225
HTTP_STATUS_SUCCESS_RANGE = (100..399)
@@ -65,7 +68,7 @@ def reset
6568
end
6669

6770
def otel_before_request
68-
method = 'N/A' # Could be GET or not HTTP at all
71+
method = '_OTHER' # Could be GET or not HTTP at all
6972
method = @otel_method if instance_variable_defined?(:@otel_method) && !@otel_method.nil?
7073

7174
@otel_span = tracer.start_span(

instrumentation/ethon/test/opentelemetry/instrumentation/ethon/dup/instrumentation_test.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@
7070
easy.stub(:complete, nil) do
7171
easy.perform
7272

73-
_(span.name).must_equal 'N/A'
73+
_(span.name).must_equal 'HTTP'
7474
_(span.attributes['http.method']).must_equal 'N/A'
7575
_(span.attributes['http.status_code']).must_be_nil
7676
_(span.attributes['http.url']).must_equal 'http://example.com/test'
7777
_(span.attributes['net.peer.name']).must_equal 'example.com'
78-
_(span.attributes['http.request.method']).must_equal 'N/A'
78+
_(span.attributes['http.request.method']).must_equal '_OTHER'
7979
_(span.attributes['http.response.status_code']).must_be_nil
8080
_(span.attributes['url.full']).must_equal 'http://example.com/test'
8181
_(span.attributes['server.address']).must_equal 'example.com'
@@ -97,9 +97,9 @@ def stub_response(options)
9797

9898
it 'when response is successful' do
9999
stub_response(response_code: 200) do
100-
_(span.name).must_equal 'N/A'
100+
_(span.name).must_equal 'HTTP'
101101
_(span.attributes['http.method']).must_equal 'N/A'
102-
_(span.attributes['http.request.method']).must_equal 'N/A'
102+
_(span.attributes['http.request.method']).must_equal '_OTHER'
103103
_(span.attributes['http.status_code']).must_equal 200
104104
_(span.attributes['http.response.status_code']).must_equal 200
105105
_(span.attributes['http.url']).must_equal 'http://example.com/test'
@@ -113,9 +113,9 @@ def stub_response(options)
113113

114114
it 'when response is not successful' do
115115
stub_response(response_code: 500) do
116-
_(span.name).must_equal 'N/A'
116+
_(span.name).must_equal 'HTTP'
117117
_(span.attributes['http.method']).must_equal 'N/A'
118-
_(span.attributes['http.request.method']).must_equal 'N/A'
118+
_(span.attributes['http.request.method']).must_equal '_OTHER'
119119
_(span.attributes['http.status_code']).must_equal 500
120120
_(span.attributes['http.response.status_code']).must_equal 500
121121
_(span.attributes['http.url']).must_equal 'http://example.com/test'
@@ -129,9 +129,9 @@ def stub_response(options)
129129

130130
it 'when request times out' do
131131
stub_response(response_code: 0, return_code: :operation_timedout) do
132-
_(span.name).must_equal 'N/A'
132+
_(span.name).must_equal 'HTTP'
133133
_(span.attributes['http.method']).must_equal 'N/A'
134-
_(span.attributes['http.request.method']).must_equal 'N/A'
134+
_(span.attributes['http.request.method']).must_equal '_OTHER'
135135
_(span.attributes['http.status_code']).must_be_nil
136136
_(span.attributes['http.response.status_code']).must_be_nil
137137
_(span.attributes['http.url']).must_equal 'http://example.com/test'

instrumentation/ethon/test/opentelemetry/instrumentation/ethon/stable/instrumentation_test.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
easy.stub(:complete, nil) do
7171
easy.perform
7272

73-
_(span.name).must_equal 'N/A'
74-
_(span.attributes['http.request.method']).must_equal 'N/A'
73+
_(span.name).must_equal 'HTTP'
74+
_(span.attributes['http.request.method']).must_equal '_OTHER'
7575
_(span.attributes['http.response.status_code']).must_be_nil
7676
_(span.attributes['url.full']).must_equal 'http://example.com/test'
7777
_(span.attributes['server.address']).must_equal 'example.com'
@@ -93,8 +93,8 @@ def stub_response(options)
9393

9494
it 'when response is successful' do
9595
stub_response(response_code: 200) do
96-
_(span.name).must_equal 'N/A'
97-
_(span.attributes['http.request.method']).must_equal 'N/A'
96+
_(span.name).must_equal 'HTTP'
97+
_(span.attributes['http.request.method']).must_equal '_OTHER'
9898
_(span.attributes['http.response.status_code']).must_equal 200
9999
_(span.attributes['url.full']).must_equal 'http://example.com/test'
100100
_(easy.instance_eval { @otel_span }).must_be_nil
@@ -106,8 +106,8 @@ def stub_response(options)
106106

107107
it 'when response is not successful' do
108108
stub_response(response_code: 500) do
109-
_(span.name).must_equal 'N/A'
110-
_(span.attributes['http.request.method']).must_equal 'N/A'
109+
_(span.name).must_equal 'HTTP'
110+
_(span.attributes['http.request.method']).must_equal '_OTHER'
111111
_(span.attributes['http.response.status_code']).must_equal 500
112112
_(span.attributes['url.full']).must_equal 'http://example.com/test'
113113
_(easy.instance_eval { @otel_span }).must_be_nil
@@ -119,8 +119,8 @@ def stub_response(options)
119119

120120
it 'when request times out' do
121121
stub_response(response_code: 0, return_code: :operation_timedout) do
122-
_(span.name).must_equal 'N/A'
123-
_(span.attributes['http.request.method']).must_equal 'N/A'
122+
_(span.name).must_equal 'HTTP'
123+
_(span.attributes['http.request.method']).must_equal '_OTHER'
124124
_(span.attributes['http.response.status_code']).must_be_nil
125125
_(span.attributes['url.full']).must_equal 'http://example.com/test'
126126
_(span.status.code).must_equal(

0 commit comments

Comments
 (0)