Skip to content

Commit 6b762fb

Browse files
committed
squash: move files
1 parent 282aa08 commit 6b762fb

File tree

36 files changed

+531
-572
lines changed

36 files changed

+531
-572
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ module Ethon
1515
end
1616
end
1717

18+
require_relative 'ethon/http_helper'
1819
require_relative 'ethon/instrumentation'
1920
require_relative 'ethon/version'
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 Ethon
10+
# Helper module for HTTP method normalization
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 stable semantic conventions in a single call
63+
# @param method [String, Symbol] The HTTP method
64+
# @return [SpanCreationAttributes] struct containing span_name, normalized_method, and original_method
65+
def self.attrs_for_stable(method)
66+
normalized = METHOD_CACHE[method]
67+
if normalized
68+
SpanCreationAttributes.new(
69+
span_name: normalized,
70+
normalized_method: normalized,
71+
original_method: nil
72+
)
73+
else
74+
SpanCreationAttributes.new(
75+
span_name: 'HTTP',
76+
normalized_method: '_OTHER',
77+
original_method: method.to_s
78+
)
79+
end
80+
end
81+
82+
# Prepares all span data for old semantic conventions in a single call
83+
# @param method [String, Symbol] The HTTP method
84+
# @return [SpanCreationAttributes] struct containing span_name, normalized_method, and original_method
85+
def self.attrs_for_old(method)
86+
normalized = METHOD_CACHE[method]
87+
if normalized
88+
SpanCreationAttributes.new(
89+
span_name: OLD_SPAN_NAMES[normalized],
90+
normalized_method: normalized,
91+
original_method: nil
92+
)
93+
else
94+
SpanCreationAttributes.new(
95+
span_name: 'HTTP',
96+
normalized_method: '_OTHER',
97+
original_method: method.to_s
98+
)
99+
end
100+
end
101+
end
102+
end
103+
end
104+
end

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7-
require_relative '../http_helper'
8-
97
module OpenTelemetry
108
module Instrumentation
119
module Ethon

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

Lines changed: 0 additions & 106 deletions
This file was deleted.

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7-
require_relative '../http_helper'
8-
97
module OpenTelemetry
108
module Instrumentation
119
module Ethon

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7-
require_relative '../http_helper'
8-
97
module OpenTelemetry
108
module Instrumentation
119
module Ethon

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ module Excon
1515
end
1616
end
1717

18+
require_relative 'excon/http_helper'
1819
require_relative 'excon/instrumentation'
1920
require_relative 'excon/version'
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 Excon
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 stable semantic conventions in a single call
63+
# @param method [String, Symbol] The HTTP method
64+
# @return [SpanCreationAttributes] struct containing span_name, normalized_method, and original_method
65+
def self.attrs_for_stable(method)
66+
normalized = METHOD_CACHE[method]
67+
if normalized
68+
SpanCreationAttributes.new(
69+
span_name: normalized,
70+
normalized_method: normalized,
71+
original_method: nil
72+
)
73+
else
74+
SpanCreationAttributes.new(
75+
span_name: 'HTTP',
76+
normalized_method: '_OTHER',
77+
original_method: method.to_s
78+
)
79+
end
80+
end
81+
82+
# Prepares all span data for old semantic conventions in a single call
83+
# @param method [String, Symbol] The HTTP method
84+
# @return [SpanCreationAttributes] struct containing span_name, normalized_method, and original_method
85+
def self.attrs_for_old(method)
86+
normalized = METHOD_CACHE[method]
87+
if normalized
88+
SpanCreationAttributes.new(
89+
span_name: OLD_SPAN_NAMES[normalized],
90+
normalized_method: normalized,
91+
original_method: nil
92+
)
93+
else
94+
SpanCreationAttributes.new(
95+
span_name: 'HTTP',
96+
normalized_method: '_OTHER',
97+
original_method: method.to_s
98+
)
99+
end
100+
end
101+
end
102+
end
103+
end
104+
end

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7-
require_relative '../http_helper'
8-
97
module OpenTelemetry
108
module Instrumentation
119
module Excon

0 commit comments

Comments
 (0)