Skip to content

Commit

Permalink
fix: excessive hash creation on context attr merging (#1117)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlaurin authored Feb 2, 2022
1 parent 0e4ed4e commit bc1291a
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def span_creation_attributes(method)
}
config = Ethon::Instrumentation.instance.config
instrumentation_attrs['peer.service'] = config[:peer_service] if config[:peer_service]
instrumentation_attrs.merge(
instrumentation_attrs.merge!(
OpenTelemetry::Common::HTTP::ClientContext.attributes
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def span_creation_attributes(datum, http_method)
}
config = Excon::Instrumentation.instance.config
instrumentation_attrs['peer.service'] = config[:peer_service] if config[:peer_service]
instrumentation_attrs.merge(
instrumentation_attrs.merge!(
OpenTelemetry::Common::HTTP::ClientContext.attributes
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def span_creation_attributes(http_method:, url:)
}
config = Faraday::Instrumentation.instance.config
instrumentation_attrs['peer.service'] = config[:peer_service] if config[:peer_service]
instrumentation_attrs.merge(
instrumentation_attrs.merge!(
OpenTelemetry::Common::HTTP::ClientContext.attributes
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def perform(req, options) # rubocop:disable Metrics/AbcSize
'http.url' => "#{uri.scheme}://#{uri.host}",
'net.peer.name' => uri.host,
'net.peer.port' => uri.port
}.merge(OpenTelemetry::Common::HTTP::ClientContext.attributes)
}.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)

tracer.in_span("HTTP #{request_method}", attributes: attributes, kind: :client) do |span|
OpenTelemetry.propagation.inject(req.headers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ module Patches
# Module to prepend to HTTP::Connection for instrumentation
module Connection
def initialize(req, options)
attributes = OpenTelemetry::Common::HTTP::ClientContext.attributes.merge(
attributes = {
'net.peer.name' => req.uri.host,
'net.peer.port' => req.uri.port
)
}.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)

tracer.in_span('HTTP CONNECT', attributes: attributes) do
super
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ def do_get_block(req, proxy, conn, &block) # rubocop:disable Metrics/AbcSize
uri = req.header.request_uri
url = "#{uri.scheme}://#{uri.host}"
request_method = req.header.request_method

attributes = {
'http.method' => request_method,
'http.scheme' => uri.scheme,
'http.target' => uri.path,
'http.url' => url,
'net.peer.name' => uri.host,
'net.peer.port' => uri.port
}.merge(OpenTelemetry::Common::HTTP::ClientContext.attributes)
}.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)

tracer.in_span("HTTP #{request_method}", attributes: attributes, kind: :client) do |span|
OpenTelemetry.propagation.inject(req.header)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def connect
site = @proxy || @dest
url = site.addr

attributes = OpenTelemetry::Common::HTTP::ClientContext.attributes.merge('http.url' => url)
attributes = { 'http.url' => url }.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
tracer.in_span('HTTP CONNECT', attributes: attributes) do
super
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def request(req, body = nil, &block)
OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET => req.path,
OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => @address,
OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => @port
}.merge(OpenTelemetry::Common::HTTP::ClientContext.attributes)
}.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)

tracer.in_span(
HTTP_METHODS_TO_SPAN_NAMES[req.method],
Expand All @@ -50,11 +50,12 @@ def connect
conn_port = port
end

attributes = OpenTelemetry::Common::HTTP::ClientContext.attributes
tracer.in_span('HTTP CONNECT', attributes: attributes.merge(
attributes = {
OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => conn_address,
OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => conn_port
)) do
}.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)

tracer.in_span('HTTP CONNECT', attributes: attributes) do
super
end
end
Expand Down

0 comments on commit bc1291a

Please sign in to comment.