lib/opentelemetry/instrumentation/ethon/patches/easy.rb in opentelemetry-instrumentation-ethon-0.21.4 vs lib/opentelemetry/instrumentation/ethon/patches/easy.rb in opentelemetry-instrumentation-ethon-0.21.6

- old
+ new

@@ -85,17 +85,34 @@ def span_creation_attributes(method) instrumentation_attrs = { 'http.method' => method } - http_url = OpenTelemetry::Common::Utilities.cleanse_url(url) - instrumentation_attrs['http.url'] = http_url if http_url + uri = _otel_cleanse_uri(url) + if uri + instrumentation_attrs['http.url'] = uri.to_s + instrumentation_attrs['net.peer.name'] = uri.host if uri.host + end config = Ethon::Instrumentation.instance.config instrumentation_attrs['peer.service'] = config[:peer_service] if config[:peer_service] instrumentation_attrs.merge!( OpenTelemetry::Common::HTTP::ClientContext.attributes ) + end + + # Returns a URL string with userinfo removed. + # + # @param [String] url The URL string to cleanse. + # + # @return [String] the cleansed URL. + def _otel_cleanse_uri(url) + cleansed_url = URI.parse(url) + cleansed_url.password = nil + cleansed_url.user = nil + cleansed_url + rescue URI::Error + nil end def tracer Ethon::Instrumentation.instance.tracer end