lib/opentelemetry/instrumentation/net/http/patches/instrumentation.rb in opentelemetry-instrumentation-net_http-0.22.7 vs lib/opentelemetry/instrumentation/net/http/patches/instrumentation.rb in opentelemetry-instrumentation-net_http-0.22.8

- old
+ new

@@ -12,10 +12,13 @@ # Module to prepend to Net::HTTP for instrumentation module Instrumentation HTTP_METHODS_TO_SPAN_NAMES = Hash.new { |h, k| h[k] = "HTTP #{k}" } USE_SSL_TO_SCHEME = { false => 'http', true => 'https' }.freeze + # Constant for the HTTP status range + HTTP_STATUS_SUCCESS_RANGE = (100..399) + def request(req, body = nil, &block) # Do not trace recursive call for starting the connection return super unless started? return super if untraced? @@ -76,10 +79,10 @@ return unless response&.code status_code = response.code.to_i span.set_attribute(OpenTelemetry::SemanticConventions::Trace::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 tracer Net::HTTP::Instrumentation.instance.tracer end