lib/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware.rb in opentelemetry-instrumentation-faraday-0.24.7 vs lib/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware.rb in opentelemetry-instrumentation-faraday-0.24.8

- old
+ new

@@ -31,34 +31,37 @@ config = Faraday::Instrumentation.instance.config attributes = span_creation_attributes( http_method: http_method, url: env.url, config: config ) - tracer.in_span( - "HTTP #{http_method}", attributes: attributes, kind: config.fetch(:span_kind) - ) do |span| - OpenTelemetry.propagation.inject(env.request_headers) - app.call(env).on_complete { |resp| trace_response(span, resp.status) } - rescue ::Faraday::Error => e - trace_response(span, e.response[:status]) if e.response + OpenTelemetry::Common::HTTP::ClientContext.with_attributes(attributes) do |attrs, _| + tracer.in_span( + "HTTP #{http_method}", attributes: attrs, kind: config.fetch(:span_kind) + ) do |span| + OpenTelemetry.propagation.inject(env.request_headers) - raise + app.call(env).on_complete { |resp| trace_response(span, resp.status) } + rescue ::Faraday::Error => e + trace_response(span, e.response[:status]) if e.response + + raise + end end end private def span_creation_attributes(http_method:, url:, config:) - instrumentation_attrs = { + attrs = { 'http.method' => http_method, 'http.url' => OpenTelemetry::Common::Utilities.cleanse_url(url.to_s), 'faraday.adapter.name' => app.class.name } - instrumentation_attrs['net.peer.name'] = url.host if url.host - instrumentation_attrs['peer.service'] = config[:peer_service] if config[:peer_service] + attrs['net.peer.name'] = url.host if url.host + attrs['peer.service'] = config[:peer_service] if config[:peer_service] - instrumentation_attrs.merge!( + attrs.merge!( OpenTelemetry::Common::HTTP::ClientContext.attributes ) end # Versions prior to 1.0 do not define an accessor for app