Skip to content

Commit 43cc87f

Browse files
committed
feat: HTTP Semconv naming
1 parent f59066e commit 43cc87f

File tree

23 files changed

+71
-174
lines changed

23 files changed

+71
-174
lines changed

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

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,16 @@ module HttpHelper
4444
:trace => 'TRACE'
4545
}.freeze
4646

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
47+
private_constant :METHOD_CACHE
6148

62-
# Prepares all span data for the specified semantic convention in a single call
49+
# Prepares all span data in a single call
6350
# @param method [String, Symbol] The HTTP method
64-
# @param semconv [Symbol] The semantic convention to use (:stable or :old)
6551
# @return [SpanCreationAttributes] struct containing span_name, normalized_method, and original_method
66-
def self.span_attrs_for(method, semconv: :stable)
52+
def self.span_attrs_for(method)
6753
normalized = METHOD_CACHE[method]
6854
if normalized
69-
span_name = semconv == :old ? OLD_SPAN_NAMES[normalized] : normalized
7055
SpanCreationAttributes.new(
71-
span_name: span_name,
56+
span_name: normalized,
7257
normalized_method: normalized,
7358
original_method: nil
7459
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def reset
6767
end
6868

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

7272
@otel_span = tracer.start_span(
7373
span_data.span_name,

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

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,16 @@ module HttpHelper
4444
:trace => 'TRACE'
4545
}.freeze
4646

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
47+
private_constant :METHOD_CACHE
6148

62-
# Prepares all span data for the specified semantic convention in a single call
49+
# Prepares all span data in a single call
6350
# @param method [String, Symbol] The HTTP method
64-
# @param semconv [Symbol] The semantic convention to use (:stable or :old)
6551
# @return [SpanCreationAttributes] struct containing span_name, normalized_method, and original_method
66-
def self.span_attrs_for(method, semconv: :stable)
52+
def self.span_attrs_for(method)
6753
normalized = METHOD_CACHE[method]
6854
if normalized
69-
span_name = semconv == :old ? OLD_SPAN_NAMES[normalized] : normalized
7055
SpanCreationAttributes.new(
71-
span_name: span_name,
56+
span_name: normalized,
7257
normalized_method: normalized,
7358
original_method: nil
7459
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ 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], semconv: :old)
20+
span_data = HttpHelper.span_attrs_for(datum[:method])
2121

2222
attributes = {
2323
OpenTelemetry::SemanticConventions::Trace::HTTP_HOST => datum[:host],

instrumentation/excon/lib/opentelemetry/instrumentation/excon/patches/old/socket.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def connect
2727
attributes = { OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => conn_address, OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => conn_port }.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
2828

2929
if is_a?(::Excon::SSLSocket) && @data[:proxy]
30-
span_name = 'HTTP CONNECT'
30+
span_name = 'CONNECT'
3131
span_kind = :client
3232
else
3333
span_name = 'connect'

instrumentation/excon/test/opentelemetry/instrumentation/excon/old/instrumentation_test.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
Excon.get('http://example.com/success')
5050

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.host']).must_equal 'example.com'
5454
_(span.attributes['http.method']).must_equal 'GET'
5555
_(span.attributes['http.scheme']).must_equal 'http'
@@ -93,7 +93,7 @@
9393
Excon.get('http://example.com/failure')
9494

9595
_(exporter.finished_spans.size).must_equal 1
96-
_(span.name).must_equal 'HTTP GET'
96+
_(span.name).must_equal 'GET'
9797
_(span.attributes['http.host']).must_equal 'example.com'
9898
_(span.attributes['http.method']).must_equal 'GET'
9999
_(span.attributes['http.scheme']).must_equal 'http'
@@ -113,7 +113,7 @@
113113
end.must_raise Excon::Error::Timeout
114114

115115
_(exporter.finished_spans.size).must_equal 1
116-
_(span.name).must_equal 'HTTP GET'
116+
_(span.name).must_equal 'GET'
117117
_(span.attributes['http.host']).must_equal 'example.com'
118118
_(span.attributes['http.method']).must_equal 'GET'
119119
_(span.attributes['http.scheme']).must_equal 'http'
@@ -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
_(span.attributes['http.host']).must_equal 'example.com'
148148
_(span.attributes['http.method']).must_equal 'OVERRIDE'
149149
_(span.attributes['http.scheme']).must_equal 'http'
@@ -224,7 +224,7 @@
224224
Excon.get('http://example.com/body')
225225

226226
_(exporter.finished_spans.size).must_equal 1
227-
_(span.name).must_equal 'HTTP GET'
227+
_(span.name).must_equal 'GET'
228228
_(span.attributes['http.host']).must_equal 'example.com'
229229
_(span.attributes['http.method']).must_equal 'GET'
230230
end
@@ -309,7 +309,7 @@
309309
_(-> { Excon.get('https://localhost/', proxy: 'https://proxy_user:proxy_pass@localhost') }).must_raise(Excon::Error::Socket)
310310

311311
_(exporter.finished_spans.size).must_equal(3)
312-
_(span.name).must_equal 'HTTP CONNECT'
312+
_(span.name).must_equal 'CONNECT'
313313
_(span.kind).must_equal(:client)
314314
_(span.attributes['net.peer.name']).must_equal('localhost')
315315
_(span.attributes['net.peer.port']).must_equal(443)
@@ -340,7 +340,7 @@
340340

341341
def assert_http_spans(scheme: 'http', host: 'localhost', port: nil, target: '/', exception: nil)
342342
exporter.finished_spans[1..].each do |http_span|
343-
_(http_span.name).must_equal 'HTTP GET'
343+
_(http_span.name).must_equal 'GET'
344344
_(http_span.attributes['http.host']).must_equal host
345345
_(http_span.attributes['http.method']).must_equal 'GET'
346346
_(http_span.attributes['http.scheme']).must_equal scheme

instrumentation/faraday/lib/opentelemetry/instrumentation/faraday/http_helper.rb

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,18 @@ module HttpHelper
4444
:trace => 'TRACE'
4545
}.freeze
4646

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
47+
private_constant :METHOD_CACHE
5948

60-
private_constant :METHOD_CACHE, :OLD_SPAN_NAMES
49+
module_function
6150

62-
# Prepares all span data for the specified semantic convention in a single call
51+
# Prepares all span data in a single call
6352
# @param method [String, Symbol] The HTTP method
64-
# @param semconv [Symbol] The semantic convention to use (:stable or :old)
6553
# @return [SpanCreationAttributes] struct containing span_name, normalized_method, and original_method
66-
def self.span_attrs_for(method, semconv: :stable)
54+
def span_attrs_for(method)
6755
normalized = METHOD_CACHE[method]
6856
if normalized
69-
span_name = semconv == :old ? OLD_SPAN_NAMES[normalized] : normalized
7057
SpanCreationAttributes.new(
71-
span_name: span_name,
58+
span_name: normalized,
7259
normalized_method: normalized,
7360
original_method: nil
7461
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TracerMiddleware < ::Faraday::Middleware
1616
HTTP_STATUS_SUCCESS_RANGE = (100..399)
1717

1818
def call(env)
19-
span_data = HttpHelper.span_attrs_for(env.method, semconv: :old)
19+
span_data = HttpHelper.span_attrs_for(env.method)
2020

2121
config = Faraday::Instrumentation.instance.config
2222

instrumentation/faraday/test/opentelemetry/instrumentation/faraday/middlewares/old/tracer_middleware_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
it 'has http 200 attributes' do
4848
response = client.get('/success')
4949

50-
_(span.name).must_equal 'HTTP GET'
50+
_(span.name).must_equal 'GET'
5151
_(span.attributes['http.method']).must_equal 'GET'
5252
_(span.attributes['http.status_code']).must_equal 200
5353
_(span.attributes['http.url']).must_equal 'http://example.com/success'
@@ -60,7 +60,7 @@
6060
it 'has http.status_code 404' do
6161
response = client.get('/not_found')
6262

63-
_(span.name).must_equal 'HTTP GET'
63+
_(span.name).must_equal 'GET'
6464
_(span.attributes['http.method']).must_equal 'GET'
6565
_(span.attributes['http.status_code']).must_equal 404
6666
_(span.attributes['http.url']).must_equal 'http://example.com/not_found'
@@ -73,7 +73,7 @@
7373
it 'has http.status_code 500' do
7474
response = client.get('/failure')
7575

76-
_(span.name).must_equal 'HTTP GET'
76+
_(span.name).must_equal 'GET'
7777
_(span.attributes['http.method']).must_equal 'GET'
7878
_(span.attributes['http.status_code']).must_equal 500
7979
_(span.attributes['http.url']).must_equal 'http://example.com/failure'
@@ -116,7 +116,7 @@
116116
client.get('/success')
117117
end
118118

119-
_(span.name).must_equal 'HTTP GET'
119+
_(span.name).must_equal 'GET'
120120
_(span.attributes['http.method']).must_equal 'OVERRIDE'
121121
_(span.attributes['http.status_code']).must_equal 200
122122
_(span.attributes['http.url']).must_equal 'http://example.com/success'
@@ -206,7 +206,7 @@
206206
it 'omits missing attributes' do
207207
response = client.get('/success')
208208

209-
_(span.name).must_equal 'HTTP GET'
209+
_(span.name).must_equal 'GET'
210210
_(span.attributes['http.method']).must_equal 'GET'
211211
_(span.attributes['http.status_code']).must_equal 200
212212
_(span.attributes['http.url']).must_equal 'http:/success'

instrumentation/http/lib/opentelemetry/instrumentation/http/http_helper.rb

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,16 @@ module HttpHelper
4444
:trace => 'TRACE'
4545
}.freeze
4646

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
47+
private_constant :METHOD_CACHE
6148

62-
# Prepares all span data for the specified semantic convention in a single call
49+
# Prepares all span data in a single call
6350
# @param method [String, Symbol] The HTTP method
64-
# @param semconv [Symbol] The semantic convention to use (:stable or :old)
6551
# @return [SpanCreationAttributes] struct containing span_name, normalized_method, and original_method
66-
def self.span_attrs_for(method, semconv: :stable)
52+
def self.span_attrs_for(method)
6753
normalized = METHOD_CACHE[method]
6854
if normalized
69-
span_name = semconv == :old ? OLD_SPAN_NAMES[normalized] : normalized
7055
SpanCreationAttributes.new(
71-
span_name: span_name,
56+
span_name: normalized,
7257
normalized_method: normalized,
7358
original_method: nil
7459
)

0 commit comments

Comments
 (0)