Skip to content

Instantly share code, notes, and snippets.

@dangalipo
Created November 24, 2016 02:39
Show Gist options
  • Save dangalipo/a1fd86df39f2711c0ef092b38b1e7fab to your computer and use it in GitHub Desktop.
Save dangalipo/a1fd86df39f2711c0ef092b38b1e7fab to your computer and use it in GitHub Desktop.
This is probably made of fail can someone tell me why....
class ApplicationController < ActionController::Base
before_filter :store_request_and_session_ids
private
def store_request_and_session_ids
Thread.current[:request_id] ||= request.uuid
Thread.current[:session_id] ||= session.id
end
end
def connection(timeout: API_TIMEOUT)
Faraday.new(url: url) do |conn|
conn.use Faraday::Adapter::NetHttp
# NB. logging post body is blocked by https://github.com/lostisland/faraday/issues/254
conn.response :body_logger if EnvSettings['EXPORT_LOG']
conn.options.timeout = timeout
conn.headers['X-Locomote-Api-Key'] = cbt_config.api_key
conn.headers['X-Locomote-Log-Request-Id'] = Thread.current[:request_id]
conn.headers['X-Locomote-Log-Session-Id'] = Thread.current[:session_id]
conn.headers['Content-Type'] = 'application/json'
conn.use :extended_logging, logger: Logger.new(Rails.root.join('log', 'cbt.log'))
# use JSON.parse(response.body, { symbolize_names: true }) instead
# conn.response :json, :content_type => /\bjson$/
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment