lib/opentelemetry/instrumentation/net/http/patches/instrumentation.rb in opentelemetry-instrumentation-net_http-0.20.0 vs lib/opentelemetry/instrumentation/net/http/patches/instrumentation.rb in opentelemetry-instrumentation-net_http-0.21.0

- old
+ new

@@ -16,10 +16,12 @@ def request(req, body = nil, &block) # Do not trace recursive call for starting the connection return super(req, body, &block) unless started? + return super(req, body, &block) if untraced? + attributes = { OpenTelemetry::SemanticConventions::Trace::HTTP_METHOD => req.method, OpenTelemetry::SemanticConventions::Trace::HTTP_SCHEME => USE_SSL_TO_SCHEME[use_ssl?], OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET => req.path, OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => @address, @@ -39,10 +41,11 @@ end end private + # rubocop:disable Metrics/MethodLength def connect if proxy? conn_address = proxy_address conn_port = proxy_port else @@ -53,14 +56,23 @@ attributes = { OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => conn_address, OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => conn_port }.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes) - tracer.in_span('HTTP CONNECT', attributes: attributes) do + if use_ssl? && proxy? + span_name = 'HTTP CONNECT' + span_kind = :client + else + span_name = 'connect' + span_kind = :internal + end + + tracer.in_span(span_name, attributes: attributes, kind: span_kind) do super end end + # rubocop:enable Metrics/MethodLength def annotate_span_with_response!(span, response) return unless response&.code status_code = response.code.to_i @@ -69,9 +81,17 @@ span.status = OpenTelemetry::Trace::Status.error unless (100..399).include?(status_code.to_i) end def tracer Net::HTTP::Instrumentation.instance.tracer + end + + def untraced? + return true if Net::HTTP::Instrumentation.instance.config[:untraced_hosts]&.any? do |host| + host.is_a?(Regexp) ? host.match?(@address) : host == @address + end + + false end end end end end