Sha256: b281e57dce5d0951b0b8b9375ef47d30ab5a3bd439272d2e2807dbc40ff6ba28

Contents?: true

Size: 769 Bytes

Versions: 3

Compression:

Stored size: 769 Bytes

Contents

# frozen_string_literal: true

require 'faraday'

module Mnemosyne
  module Middleware
    class Faraday < ::Faraday::Middleware
      def call(env)
        trace = ::Mnemosyne::Instrumenter.current_trace

        return @app.call(env) unless trace

        span = ::Mnemosyne::Span.new 'external.http.faraday', \
          meta: {url: env[:url].to_s, method: env[:method]}

        span.start!

        env[:request_headers].merge!({
          'X-Mnemosyne-Transaction' => trace.transaction,
          'X-Mnemosyne-Origin' => span.uuid
        }.compact)

        @app.call(env).on_complete do |env| # rubocop:disable Lint/ShadowingOuterLocalVariable
          span.meta[:status] = env[:status]

          trace << span.finish!
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mnemosyne-ruby-1.13.0 lib/mnemosyne/middleware/faraday.rb
mnemosyne-ruby-1.12.1 lib/mnemosyne/middleware/faraday.rb
mnemosyne-ruby-1.12.0 lib/mnemosyne/middleware/faraday.rb