lib/opentelemetry/instrumentation/http/patches/client.rb in opentelemetry-instrumentation-http-0.23.4 vs lib/opentelemetry/instrumentation/http/patches/client.rb in opentelemetry-instrumentation-http-0.23.5
- old
+ new
@@ -8,10 +8,13 @@
module Instrumentation
module HTTP
module Patches
# Module to prepend to HTTP::Client for instrumentation
module Client
+ # Constant for the HTTP status range
+ HTTP_STATUS_SUCCESS_RANGE = (100..399)
+
def perform(req, options)
uri = req.uri
request_method = req.verb.to_s.upcase
span_name = create_request_span_name(request_method, uri.path)
@@ -41,10 +44,10 @@
def annotate_span_with_response!(span, response)
return unless response&.status
status_code = response.status.to_i
span.set_attribute('http.status_code', status_code)
- span.status = OpenTelemetry::Trace::Status.error unless (100..399).cover?(status_code.to_i)
+ span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(status_code)
end
def create_request_span_name(request_method, request_path)
if (implementation = config[:span_name_formatter])
updated_span_name = implementation.call(request_method, request_path)