lib/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware.rb in opentelemetry-instrumentation-faraday-0.24.0 vs lib/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware.rb in opentelemetry-instrumentation-faraday-0.24.1
- old
+ new
@@ -33,11 +33,15 @@
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) }
+ 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
private
@@ -60,12 +64,12 @@
def tracer
Faraday::Instrumentation.instance.tracer
end
- def trace_response(span, response)
- span.set_attribute('http.status_code', response.status)
- span.status = OpenTelemetry::Trace::Status.error unless (100..399).cover?(response.status.to_i)
+ def trace_response(span, status)
+ span.set_attribute('http.status_code', status)
+ span.status = OpenTelemetry::Trace::Status.error unless (100..399).cover?(status.to_i)
end
end
end
end
end