lib/opentelemetry/instrumentation/net/http/patches/instrumentation.rb in opentelemetry-instrumentation-net_http-0.19.3 vs lib/opentelemetry/instrumentation/net/http/patches/instrumentation.rb in opentelemetry-instrumentation-net_http-0.19.4
- old
+ new
@@ -16,20 +16,21 @@
def request(req, body = nil, &block)
# Do not trace recursive call for starting the connection
return super(req, body, &block) unless started?
- attributes = OpenTelemetry::Common::HTTP::ClientContext.attributes
+ 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,
+ OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => @port
+ }.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
+
tracer.in_span(
HTTP_METHODS_TO_SPAN_NAMES[req.method],
- attributes: attributes.merge(
- 'http.method' => req.method,
- 'http.scheme' => USE_SSL_TO_SCHEME[use_ssl?],
- 'http.target' => req.path,
- 'net.peer.name' => @address,
- 'net.peer.port' => @port
- ),
+ attributes: attributes,
kind: :client
) do |span|
OpenTelemetry.propagation.inject(req)
super(req, body, &block).tap do |response|
@@ -47,24 +48,25 @@
else
conn_address = address
conn_port = port
end
- attributes = OpenTelemetry::Common::HTTP::ClientContext.attributes
- tracer.in_span('HTTP CONNECT', attributes: attributes.merge(
- 'net.peer.name' => conn_address,
- 'net.peer.port' => conn_port
- )) do
+ 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
super
end
end
def annotate_span_with_response!(span, response)
return unless response&.code
status_code = response.code.to_i
- span.set_attribute('http.status_code', status_code)
+ span.set_attribute(OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE, status_code)
span.status = OpenTelemetry::Trace::Status.error unless (100..399).include?(status_code.to_i)
end
def tracer
Net::HTTP::Instrumentation.instance.tracer