diff --git a/instrumentation/ethon/Appraisals b/instrumentation/ethon/Appraisals index 137aed805..61520f97d 100644 --- a/instrumentation/ethon/Appraisals +++ b/instrumentation/ethon/Appraisals @@ -1,9 +1,9 @@ # frozen_string_literal: true -appraise 'ethon-0.12' do - gem 'ethon', '~> 0.12.0' +appraise 'ethon-0.16' do + gem 'ethon', '~> 0.16.0' end -appraise 'ethon-0.11' do - gem 'ethon', '~> 0.11.0' +appraise 'ethon-latest' do + gem 'ethon' end diff --git a/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/easy.rb b/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/easy.rb index 18b11dc51..74791818e 100644 --- a/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/easy.rb +++ b/instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/patches/easy.rb @@ -87,8 +87,11 @@ def span_creation_attributes(method) '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] @@ -97,6 +100,20 @@ def span_creation_attributes(method) ) 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 diff --git a/instrumentation/ethon/test/opentelemetry/instrumentation/ethon/instrumentation_test.rb b/instrumentation/ethon/test/opentelemetry/instrumentation/ethon/instrumentation_test.rb index 1c3a24035..e39779bf0 100644 --- a/instrumentation/ethon/test/opentelemetry/instrumentation/ethon/instrumentation_test.rb +++ b/instrumentation/ethon/test/opentelemetry/instrumentation/ethon/instrumentation_test.rb @@ -71,6 +71,7 @@ _(span.attributes['http.method']).must_equal 'N/A' _(span.attributes['http.status_code']).must_be_nil _(span.attributes['http.url']).must_equal 'http://example.com/test' + _(span.attributes['net.peer.name']).must_equal 'example.com' end end end @@ -275,8 +276,10 @@ def stub_response(options) multi.perform _(exporter.finished_spans.size).must_equal 2 - _(exporter.finished_spans[0].attributes['http.url']).must_equal nil + _(exporter.finished_spans[0].attributes['http.url']).must_be_nil + _(exporter.finished_spans[0].attributes['net.peer.name']).must_be_nil _(exporter.finished_spans[1].attributes['http.url']).must_equal 'test' + _(exporter.finished_spans[1].attributes['net.peer.name']).must_be_nil end end end