lib/opentelemetry/instrumentation/excon/middlewares/tracer_middleware.rb in opentelemetry-instrumentation-excon-0.19.4 vs lib/opentelemetry/instrumentation/excon/middlewares/tracer_middleware.rb in opentelemetry-instrumentation-excon-0.19.5
- old
+ new
@@ -8,28 +8,27 @@
module Instrumentation
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|
datum[:otel_span] = span
OpenTelemetry::Trace.with_span(span) do