Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,24 @@ module Excon
module Middlewares
# Excon middleware for instrumentation
class TracerMiddleware < ::Excon::Middleware::Base
HTTP_METHODS_SYMBOL_TO_STRING = {
connect: 'CONNECT',
delete: 'DELETE',
get: 'GET',
head: 'HEAD',
options: 'OPTIONS',
patch: 'PATCH',
post: 'POST',
put: 'PUT',
trace: 'TRACE'
}.freeze
HTTP_METHODS_TO_UPPERCASE = %w[connect delete get head options patch post put trace].each_with_object({}) do |method, hash|
uppercase_method = method.upcase
hash[method] = uppercase_method
hash[method.to_sym] = uppercase_method
hash[uppercase_method] = uppercase_method
end.freeze

HTTP_METHODS_TO_SPAN_NAMES = HTTP_METHODS_TO_UPPERCASE.values.each_with_object({}) do |uppercase_method, hash|
hash[uppercase_method] ||= "HTTP #{uppercase_method}"
end.freeze

def request_call(datum)
begin
unless datum.key?(:otel_span)
http_method = HTTP_METHODS_SYMBOL_TO_STRING[datum[:method]]
http_method = HTTP_METHODS_TO_UPPERCASE[datum[:method]]
attributes = span_creation_attributes(datum, http_method)
tracer.start_span(
"HTTP #{http_method}",
HTTP_METHODS_TO_SPAN_NAMES[http_method],
attributes: attributes,
kind: :client
).tap do |span|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
)
end

specify 'after request with capital-letters HTTP method' do
::Excon.new('http://example.com/success')
.request(method: 'GET')

_(span.attributes['http.method']).must_equal 'GET'
end

it 'after request with failure code' do
::Excon.get('http://example.com/failure')

Expand Down