lib/opentelemetry/instrumentation/ethon/patches/easy.rb in opentelemetry-instrumentation-ethon-0.21.8 vs lib/opentelemetry/instrumentation/ethon/patches/easy.rb in opentelemetry-instrumentation-ethon-0.21.9
- old
+ new
@@ -14,10 +14,13 @@
# #to_s is required because user input could be symbol or string
h[k] = k.to_s.upcase
end
HTTP_METHODS_TO_SPAN_NAMES = Hash.new { |h, k| h[k] = "HTTP #{k}" }
+ # Constant for the HTTP status range
+ HTTP_STATUS_SUCCESS_RANGE = (100..399)
+
def http_request(url, action_name, options = {})
@otel_method = ACTION_NAMES_TO_HTTP_METHODS[action_name]
super
end
@@ -40,10 +43,10 @@
return_code = response_options[:return_code]
message = return_code ? ::Ethon::Curl.easy_strerror(return_code) : 'unknown reason'
@otel_span.status = OpenTelemetry::Trace::Status.error("Request has failed: #{message}")
else
@otel_span.set_attribute('http.status_code', response_code)
- @otel_span.status = OpenTelemetry::Trace::Status.error unless (100..399).cover?(response_code.to_i)
+ @otel_span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(response_code.to_i)
end
ensure
@otel_span&.finish
@otel_span = nil
end