lib/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware.rb in opentelemetry-instrumentation-faraday-0.23.4 vs lib/opentelemetry/instrumentation/faraday/middlewares/tracer_middleware.rb in opentelemetry-instrumentation-faraday-0.24.0

- old
+ new

@@ -23,37 +23,41 @@ trace: 'TRACE' }.freeze def call(env) http_method = HTTP_METHODS_SYMBOL_TO_STRING[env.method] + config = Faraday::Instrumentation.instance.config + attributes = span_creation_attributes( - http_method: http_method, url: env.url + http_method: http_method, url: env.url, config: config ) tracer.in_span( - "HTTP #{http_method}", attributes: attributes, kind: :client + "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) } end end private - attr_reader :app - - def span_creation_attributes(http_method:, url:) + def span_creation_attributes(http_method:, url:, config:) instrumentation_attrs = { 'http.method' => http_method, - 'http.url' => OpenTelemetry::Common::Utilities.cleanse_url(url.to_s) + '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 - config = Faraday::Instrumentation.instance.config instrumentation_attrs['peer.service'] = config[:peer_service] if config[:peer_service] + instrumentation_attrs.merge!( OpenTelemetry::Common::HTTP::ClientContext.attributes ) end + + # Versions prior to 1.0 do not define an accessor for app + attr_reader :app if Gem::Version.new(Faraday::VERSION) < Gem::Version.new('1.0.0') def tracer Faraday::Instrumentation.instance.tracer end