Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change net attribute names to match the semantic conventions spec for http #999

Merged
merged 5 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ tracer.in_span(
'http.method' => req.method,
'http.scheme' => USE_SSL_TO_SCHEME[use_ssl?],
'http.target' => req.path,
'peer.hostname' => @address,
'peer.port' => @port
'net.peer.name' => @address,
'net.peer.port' => @port
),
kind: :client
) do |span|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ module Transformer
STATUS_ERROR = 'ERROR'
STATUS_OK = 'OK'
ATTRIBUTE_PEER_SERVICE = 'peer.service'
ATTRIBUTE_NET_PEER_IP = 'peer.ip'
ATTRIBUTE_NET_PEER_PORT = 'peer.port'
ATTRIBUTE_NET_HOST_IP = 'host.ip'
ATTRIBUTE_NET_HOST_PORT = 'host.port'
ATTRIBUTE_NET_PEER_IP = 'net.peer.ip'
ATTRIBUTE_NET_PEER_PORT = 'net.peer.port'
ATTRIBUTE_NET_HOST_IP = 'net.host.ip'
ATTRIBUTE_NET_HOST_PORT = 'net.host.port'

DEFAULT_SERVICE_NAME = OpenTelemetry::SDK::Resources::Resource.default.attribute_enumerator.find { |k, _| k == SERVICE_NAME_ATTRIBUTE_KEY }&.last || 'unknown_service'
private_constant(:KIND_MAP, :DEFAULT_SERVICE_NAME, :SERVICE_NAME_ATTRIBUTE_KEY, :ERROR_TAG_KEY, :STATUS_CODE_NAME, :STATUS_ERROR, :STATUS_OK, :ATTRIBUTE_PEER_SERVICE, :ATTRIBUTE_NET_PEER_IP, :ATTRIBUTE_NET_PEER_PORT, :ATTRIBUTE_NET_HOST_IP, :ATTRIBUTE_NET_HOST_PORT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def perform(req, options) # rubocop:disable Metrics/AbcSize
'http.scheme' => uri.scheme,
'http.target' => uri.path,
'http.url' => "#{uri.scheme}://#{uri.host}",
'peer.hostname' => uri.host,
'peer.port' => uri.port
'net.peer.name' => uri.host,
'net.peer.port' => uri.port
}.merge(OpenTelemetry::Common::HTTP::ClientContext.attributes)

tracer.in_span("HTTP #{request_method}", attributes: attributes, kind: :client) do |span|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ module Patches
module Connection
def initialize(req, options)
attributes = OpenTelemetry::Common::HTTP::ClientContext.attributes.merge(
'peer.hostname' => req.uri.host,
'peer.port' => req.uri.port
'net.peer.name' => req.uri.host,
'net.peer.port' => req.uri.port
)

tracer.in_span('HTTP CONNECT', attributes: attributes) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
_(span.attributes['http.scheme']).must_equal 'http'
_(span.attributes['http.status_code']).must_equal 200
_(span.attributes['http.target']).must_equal '/success'
_(span.attributes['peer.hostname']).must_equal 'example.com'
_(span.attributes['peer.port']).must_equal 80
_(span.attributes['net.peer.name']).must_equal 'example.com'
_(span.attributes['net.peer.port']).must_equal 80
assert_requested(
:get,
'http://example.com/success',
Expand All @@ -60,8 +60,8 @@
_(span.attributes['http.scheme']).must_equal 'http'
_(span.attributes['http.status_code']).must_equal 500
_(span.attributes['http.target']).must_equal '/failure'
_(span.attributes['peer.hostname']).must_equal 'example.com'
_(span.attributes['peer.port']).must_equal 80
_(span.attributes['net.peer.name']).must_equal 'example.com'
_(span.attributes['net.peer.port']).must_equal 80
assert_requested(
:post,
'http://example.com/failure',
Expand All @@ -80,8 +80,8 @@
_(span.attributes['http.scheme']).must_equal 'https'
_(span.attributes['http.status_code']).must_be_nil
_(span.attributes['http.target']).must_equal '/timeout'
_(span.attributes['peer.hostname']).must_equal 'example.com'
_(span.attributes['peer.port']).must_equal 443
_(span.attributes['net.peer.name']).must_equal 'example.com'
_(span.attributes['net.peer.port']).must_equal 443
_(span.status.code).must_equal(
OpenTelemetry::Trace::Status::ERROR
)
Expand All @@ -106,8 +106,8 @@
_(span.attributes['http.scheme']).must_equal 'http'
_(span.attributes['http.status_code']).must_equal 200
_(span.attributes['http.target']).must_equal '/success'
_(span.attributes['peer.hostname']).must_equal 'example.com'
_(span.attributes['peer.port']).must_equal 80
_(span.attributes['net.peer.name']).must_equal 'example.com'
_(span.attributes['net.peer.port']).must_equal 80
_(span.attributes['peer.service']).must_equal 'foo'
assert_requested(
:get,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@

_(exporter.finished_spans.size).must_equal(2)
_(span.name).must_equal 'HTTP CONNECT'
_(span.attributes['peer.hostname']).must_equal('localhost')
_(span.attributes['peer.port']).wont_be_nil
_(span.attributes['net.peer.name']).must_equal('localhost')
_(span.attributes['net.peer.port']).wont_be_nil
ensure
WebMock.disable_net_connect!
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def do_get_block(req, proxy, conn, &block) # rubocop:disable Metrics/AbcSize
'http.scheme' => uri.scheme,
'http.target' => uri.path,
'http.url' => url,
'peer.hostname' => uri.host,
'peer.port' => uri.port
'net.peer.name' => uri.host,
'net.peer.port' => uri.port
}.merge(OpenTelemetry::Common::HTTP::ClientContext.attributes)

tracer.in_span("HTTP #{request_method}", attributes: attributes, kind: :client) do |span|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
_(span.attributes['http.scheme']).must_equal 'http'
_(span.attributes['http.status_code']).must_equal 200
_(span.attributes['http.target']).must_equal '/success'
_(span.attributes['peer.hostname']).must_equal 'example.com'
_(span.attributes['peer.port']).must_equal 80
_(span.attributes['net.peer.name']).must_equal 'example.com'
_(span.attributes['net.peer.port']).must_equal 80
assert_requested(
:get,
'http://example.com/success',
Expand All @@ -64,8 +64,8 @@
_(span.attributes['http.scheme']).must_equal 'http'
_(span.attributes['http.status_code']).must_equal 500
_(span.attributes['http.target']).must_equal '/failure'
_(span.attributes['peer.hostname']).must_equal 'example.com'
_(span.attributes['peer.port']).must_equal 80
_(span.attributes['net.peer.name']).must_equal 'example.com'
_(span.attributes['net.peer.port']).must_equal 80
assert_requested(
:post,
'http://example.com/failure',
Expand All @@ -86,8 +86,8 @@
_(span.attributes['http.scheme']).must_equal 'https'
_(span.attributes['http.status_code']).must_be_nil
_(span.attributes['http.target']).must_equal '/timeout'
_(span.attributes['peer.hostname']).must_equal 'example.com'
_(span.attributes['peer.port']).must_equal 443
_(span.attributes['net.peer.name']).must_equal 'example.com'
_(span.attributes['net.peer.port']).must_equal 443
_(span.status.code).must_equal(
OpenTelemetry::Trace::Status::ERROR
)
Expand All @@ -114,8 +114,8 @@
_(span.attributes['http.scheme']).must_equal 'http'
_(span.attributes['http.status_code']).must_equal 200
_(span.attributes['http.target']).must_equal '/success'
_(span.attributes['peer.hostname']).must_equal 'example.com'
_(span.attributes['peer.port']).must_equal 80
_(span.attributes['net.peer.name']).must_equal 'example.com'
_(span.attributes['net.peer.port']).must_equal 80
_(span.attributes['peer.service']).must_equal 'foo'
assert_requested(
:get,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def request(req, body = nil, &block)
'http.method' => req.method,
'http.scheme' => USE_SSL_TO_SCHEME[use_ssl?],
'http.target' => req.path,
'peer.hostname' => @address,
'peer.port' => @port
'net.peer.name' => @address,
'net.peer.port' => @port
),
kind: :client
) do |span|
Expand All @@ -51,8 +51,8 @@ def connect

attributes = OpenTelemetry::Common::HTTP::ClientContext.attributes
tracer.in_span('HTTP CONNECT', attributes: attributes.merge(
'peer.hostname' => conn_address,
'peer.port' => conn_port
'net.peer.name' => conn_address,
'net.peer.port' => conn_port
)) do
super
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
_(span.attributes['http.scheme']).must_equal 'http'
_(span.attributes['http.status_code']).must_equal 200
_(span.attributes['http.target']).must_equal '/success'
_(span.attributes['peer.hostname']).must_equal 'example.com'
_(span.attributes['peer.port']).must_equal 80
_(span.attributes['net.peer.name']).must_equal 'example.com'
_(span.attributes['net.peer.port']).must_equal 80
assert_requested(
:get,
'http://example.com/success',
Expand All @@ -66,8 +66,8 @@
_(span.attributes['http.scheme']).must_equal 'http'
_(span.attributes['http.status_code']).must_equal 500
_(span.attributes['http.target']).must_equal '/failure'
_(span.attributes['peer.hostname']).must_equal 'example.com'
_(span.attributes['peer.port']).must_equal 80
_(span.attributes['net.peer.name']).must_equal 'example.com'
_(span.attributes['net.peer.port']).must_equal 80
assert_requested(
:post,
'http://example.com/failure',
Expand All @@ -86,8 +86,8 @@
_(span.attributes['http.scheme']).must_equal 'https'
_(span.attributes['http.status_code']).must_be_nil
_(span.attributes['http.target']).must_equal '/timeout'
_(span.attributes['peer.hostname']).must_equal 'example.com'
_(span.attributes['peer.port']).must_equal 443
_(span.attributes['net.peer.name']).must_equal 'example.com'
_(span.attributes['net.peer.port']).must_equal 443
_(span.status.code).must_equal(
OpenTelemetry::Trace::Status::ERROR
)
Expand All @@ -112,8 +112,8 @@
_(span.attributes['http.scheme']).must_equal 'http'
_(span.attributes['http.status_code']).must_equal 200
_(span.attributes['http.target']).must_equal '/success'
_(span.attributes['peer.hostname']).must_equal 'example.com'
_(span.attributes['peer.port']).must_equal 80
_(span.attributes['net.peer.name']).must_equal 'example.com'
_(span.attributes['net.peer.port']).must_equal 80
_(span.attributes['peer.service']).must_equal 'foo'
assert_requested(
:get,
Expand All @@ -138,8 +138,8 @@

_(exporter.finished_spans.size).must_equal(2)
_(span.name).must_equal 'HTTP CONNECT'
_(span.attributes['peer.hostname']).must_equal('localhost')
_(span.attributes['peer.port']).wont_be_nil
_(span.attributes['net.peer.name']).must_equal('localhost')
_(span.attributes['net.peer.port']).wont_be_nil
ensure
WebMock.disable_net_connect!
end
Expand All @@ -153,8 +153,8 @@

_(exporter.finished_spans.size).must_equal(1)
_(span.name).must_equal 'HTTP CONNECT'
_(span.attributes['peer.hostname']).must_equal('localhost')
_(span.attributes['peer.port']).must_equal(99_999)
_(span.attributes['net.peer.name']).must_equal('localhost')
_(span.attributes['net.peer.port']).must_equal(99_999)

span_event = span.events.first
_(span_event.name).must_equal 'exception'
Expand Down