lib/elastic_apm/spies/faraday.rb in elastic-apm-2.1.0 vs lib/elastic_apm/spies/faraday.rb in elastic-apm-2.1.1

- old
+ new

@@ -3,11 +3,11 @@ module ElasticAPM # @api private module Spies # @api private class FaradaySpy - # rubocop:disable Metrics/MethodLength + # rubocop:disable Metrics/MethodLength, Metrics/AbcSize def install ::Faraday::Connection.class_eval do alias run_request_without_apm run_request def run_request(method, url, body, headers, &block) @@ -20,21 +20,23 @@ name = "#{method.upcase} #{host}" type = "ext.faraday.#{method}" ElasticAPM.with_span name, type do |span| ElasticAPM::Spies::NetHTTPSpy.disable_in do + id = span&.id || transaction.id + run_request_without_apm(method, url, body, headers) do |req| req['Elastic-Apm-Traceparent'] = - transaction.traceparent.to_header(span_id: span.id) + transaction.traceparent.to_header(span_id: id) yield req if block_given? end end end end end end - # rubocop:enable Metrics/MethodLength + # rubocop:enable Metrics/MethodLength, Metrics/AbcSize end register 'Faraday', 'faraday', FaradaySpy.new end end