lib/opentelemetry/instrumentation/restclient/patches/request.rb in opentelemetry-instrumentation-restclient-0.20.0 vs lib/opentelemetry/instrumentation/restclient/patches/request.rb in opentelemetry-instrumentation-restclient-0.21.0
- old
+ new
@@ -16,18 +16,18 @@
end
end
private
- def trace_request # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
+ def create_request_span
http_method = method.upcase
instrumentation_attrs = {
'http.method' => http_method.to_s,
'http.url' => OpenTelemetry::Common::Utilities.cleanse_url(url)
}
- config = RestClient::Instrumentation.instance.config
- instrumentation_attrs['peer.service'] = config[:peer_service] if config[:peer_service]
+ instrumentation_config = RestClient::Instrumentation.instance.config
+ instrumentation_attrs['peer.service'] = instrumentation_config[:peer_service] if instrumentation_config[:peer_service]
span = tracer.start_span(
"HTTP #{http_method}",
attributes: instrumentation_attrs.merge(
OpenTelemetry::Common::HTTP::ClientContext.attributes
),
@@ -35,9 +35,15 @@
)
OpenTelemetry::Trace.with_span(span) do
OpenTelemetry.propagation.inject(processed_headers)
end
+
+ span
+ end
+
+ def trace_request
+ span = create_request_span
yield(span).tap do |response|
# Verify return value is a response.
# If so, add additional attributes.
if response.is_a?(::RestClient::Response)