class FaradayMiddleware::Tracable
Public Class Methods
new(app, type_or_options, &block)
click to toggle source
You need to specify type as symbol
or
header_name: and block or header_value:
Calls superclass method
# File lib/faraday_middleware/tracable/request/tracable.rb, line 7 def initialize(app, type_or_options, &block) if type_or_options.is_a?(Hash) @header_name = type_or_options[:header_name] @header_value = block || type_or_options[:header_value] elsif type_map.has_key?(type_or_options) @header_name = type_map[type_or_options][:header_name] @header_value = type_map[type_or_options][:header_value] end super(app) end
Public Instance Methods
call(env)
click to toggle source
# File lib/faraday_middleware/tracable/request/tracable.rb, line 19 def call(env) if @header_name && @header_value env[:request_headers][@header_name] = @header_value.is_a?(Proc) ? instance_eval(&@header_value) : @header_value end @app.call(env) end
type_map()
click to toggle source
# File lib/faraday_middleware/tracable/request/tracable.rb, line 26 def type_map { stackdriver: { header_name: "X-Cloud-Trace-Context", header_value: ->(_) { trace_id = 32.times.map { [*("0".."9"), *("a".."f")].sample }.join "#{trace_id}/0;o=1" } }, } end