Skip to content

Commit 3a237a5

Browse files
fix: update span name when semconv stability is enabled (#1570)
Co-authored-by: Kayla Reopelle <[email protected]>
1 parent 75bab36 commit 3a237a5

File tree

8 files changed

+24
-24
lines changed

8 files changed

+24
-24
lines changed

instrumentation/http/lib/opentelemetry/instrumentation/http/patches/dup/client.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ def annotate_span_with_response!(span, response)
6565
def create_request_span_name(request_method, request_path)
6666
if (implementation = config[:span_name_formatter])
6767
updated_span_name = implementation.call(request_method, request_path)
68-
updated_span_name.is_a?(String) ? updated_span_name : "HTTP #{request_method}"
68+
updated_span_name.is_a?(String) ? updated_span_name : request_method.to_s
6969
else
70-
"HTTP #{request_method}"
70+
request_method.to_s
7171
end
7272
rescue StandardError
73-
"HTTP #{request_method}"
73+
request_method.to_s
7474
end
7575

7676
def tracer

instrumentation/http/lib/opentelemetry/instrumentation/http/patches/dup/connection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def initialize(req, options)
2222
'server.port' => req.uri.port
2323
}.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
2424

25-
tracer.in_span('HTTP CONNECT', attributes: attributes) do
25+
tracer.in_span('CONNECT', attributes: attributes) do
2626
super
2727
end
2828
end

instrumentation/http/lib/opentelemetry/instrumentation/http/patches/stable/client.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ def annotate_span_with_response!(span, response)
5656
def create_request_span_name(request_method, request_path)
5757
if (implementation = config[:span_name_formatter])
5858
updated_span_name = implementation.call(request_method, request_path)
59-
updated_span_name.is_a?(String) ? updated_span_name : "HTTP #{request_method}"
59+
updated_span_name.is_a?(String) ? updated_span_name : request_method.to_s
6060
else
61-
"HTTP #{request_method}"
61+
request_method.to_s
6262
end
6363
rescue StandardError
64-
"HTTP #{request_method}"
64+
request_method.to_s
6565
end
6666

6767
def tracer

instrumentation/http/lib/opentelemetry/instrumentation/http/patches/stable/connection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def initialize(req, options)
1818
'server.port' => req.uri.port
1919
}.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
2020

21-
tracer.in_span('HTTP CONNECT', attributes: attributes) do
21+
tracer.in_span('CONNECT', attributes: attributes) do
2222
super
2323
end
2424
end

instrumentation/http/test/instrumentation/http/patches/dup/client_test.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
it 'traces a simple request' do
4949
HTTP.get('http://example.com/success')
5050
_(exporter.finished_spans.size).must_equal(1)
51-
_(span.name).must_equal 'HTTP GET'
51+
_(span.name).must_equal 'GET'
5252
# Old semantic conventions
5353
_(span.attributes['http.method']).must_equal 'GET'
5454
_(span.attributes['http.scheme']).must_equal 'http'
@@ -77,7 +77,7 @@
7777
HTTP.post('http://example.com/failure')
7878

7979
_(exporter.finished_spans.size).must_equal 1
80-
_(span.name).must_equal 'HTTP POST'
80+
_(span.name).must_equal 'POST'
8181
# Old semantic conventions
8282
_(span.attributes['http.method']).must_equal 'POST'
8383
_(span.attributes['http.scheme']).must_equal 'http'
@@ -107,7 +107,7 @@
107107
end.must_raise HTTP::TimeoutError
108108

109109
_(exporter.finished_spans.size).must_equal 1
110-
_(span.name).must_equal 'HTTP GET'
110+
_(span.name).must_equal 'GET'
111111
# Old semantic conventions
112112
_(span.attributes['http.method']).must_equal 'GET'
113113
_(span.attributes['http.scheme']).must_equal 'https'
@@ -143,7 +143,7 @@
143143
end
144144

145145
_(exporter.finished_spans.size).must_equal 1
146-
_(span.name).must_equal 'HTTP GET'
146+
_(span.name).must_equal 'GET'
147147
# Old semantic conventions
148148
_(span.attributes['http.method']).must_equal 'GET'
149149
_(span.attributes['http.scheme']).must_equal 'http'
@@ -172,7 +172,7 @@
172172
let(:span_name_formatter) do
173173
# demonstrate simple addition of path and string to span name:
174174
lambda { |request_method, request_path|
175-
"HTTP #{request_method} #{request_path} miniswan"
175+
"#{request_method} #{request_path} miniswan"
176176
}
177177
end
178178

@@ -182,7 +182,7 @@
182182
end
183183

184184
_(exporter.finished_spans.size).must_equal 1
185-
_(span.name).must_equal 'HTTP GET /success miniswan'
185+
_(span.name).must_equal 'GET /success miniswan'
186186
# Old semantic conventions
187187
_(span.attributes['http.method']).must_equal 'GET'
188188
_(span.attributes['http.scheme']).must_equal 'http'
@@ -221,7 +221,7 @@
221221
end
222222

223223
_(exporter.finished_spans.size).must_equal 1
224-
_(span.name).must_equal 'HTTP GET'
224+
_(span.name).must_equal 'GET'
225225
# Old semantic conventions
226226
_(span.attributes['http.method']).must_equal 'GET'
227227
_(span.attributes['http.scheme']).must_equal 'http'

instrumentation/http/test/instrumentation/http/patches/dup/connection_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
end
4242

4343
_(exporter.finished_spans.size).must_equal(2)
44-
_(span.name).must_equal 'HTTP CONNECT'
44+
_(span.name).must_equal 'CONNECT'
4545
# Old semantic conventions
4646
_(span.attributes['net.peer.name']).must_equal('localhost')
4747
_(span.attributes['net.peer.port']).wont_be_nil

instrumentation/http/test/instrumentation/http/patches/stable/client_test.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
it 'traces a simple request' do
5050
HTTP.get('http://example.com/success')
5151
_(exporter.finished_spans.size).must_equal(1)
52-
_(span.name).must_equal 'HTTP GET'
52+
_(span.name).must_equal 'GET'
5353
_(span.attributes['http.request.method']).must_equal 'GET'
5454
_(span.attributes['url.scheme']).must_equal 'http'
5555
_(span.attributes['http.response.status_code']).must_equal 200
@@ -69,7 +69,7 @@
6969
HTTP.post('http://example.com/failure')
7070

7171
_(exporter.finished_spans.size).must_equal 1
72-
_(span.name).must_equal 'HTTP POST'
72+
_(span.name).must_equal 'POST'
7373
_(span.attributes['http.request.method']).must_equal 'POST'
7474
_(span.attributes['url.scheme']).must_equal 'http'
7575
_(span.attributes['http.response.status_code']).must_equal 500
@@ -91,7 +91,7 @@
9191
end.must_raise HTTP::TimeoutError
9292

9393
_(exporter.finished_spans.size).must_equal 1
94-
_(span.name).must_equal 'HTTP GET'
94+
_(span.name).must_equal 'GET'
9595
_(span.attributes['http.request.method']).must_equal 'GET'
9696
_(span.attributes['url.scheme']).must_equal 'https'
9797
_(span.attributes['http.response.status_code']).must_be_nil
@@ -119,7 +119,7 @@
119119
end
120120

121121
_(exporter.finished_spans.size).must_equal 1
122-
_(span.name).must_equal 'HTTP GET'
122+
_(span.name).must_equal 'GET'
123123
_(span.attributes['http.request.method']).must_equal 'GET'
124124
_(span.attributes['url.scheme']).must_equal 'http'
125125
_(span.attributes['http.response.status_code']).must_equal 200
@@ -139,7 +139,7 @@
139139
let(:span_name_formatter) do
140140
# demonstrate simple addition of path and string to span name:
141141
lambda { |request_method, request_path|
142-
"HTTP #{request_method} #{request_path} miniswan"
142+
"#{request_method} #{request_path} miniswan"
143143
}
144144
end
145145

@@ -149,7 +149,7 @@
149149
end
150150

151151
_(exporter.finished_spans.size).must_equal 1
152-
_(span.name).must_equal 'HTTP GET /success miniswan'
152+
_(span.name).must_equal 'GET /success miniswan'
153153
_(span.attributes['http.request.method']).must_equal 'GET'
154154
_(span.attributes['url.scheme']).must_equal 'http'
155155
_(span.attributes['http.response.status_code']).must_equal 200
@@ -179,7 +179,7 @@
179179
end
180180

181181
_(exporter.finished_spans.size).must_equal 1
182-
_(span.name).must_equal 'HTTP GET'
182+
_(span.name).must_equal 'GET'
183183
_(span.attributes['http.request.method']).must_equal 'GET'
184184
_(span.attributes['url.scheme']).must_equal 'http'
185185
_(span.attributes['http.response.status_code']).must_equal 200

instrumentation/http/test/instrumentation/http/patches/stable/connection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
end
4242

4343
_(exporter.finished_spans.size).must_equal(2)
44-
_(span.name).must_equal 'HTTP CONNECT'
44+
_(span.name).must_equal 'CONNECT'
4545
_(span.attributes['server.address']).must_equal('localhost')
4646
_(span.attributes['server.port']).wont_be_nil
4747
ensure

0 commit comments

Comments
 (0)