Created
November 24, 2016 02:39
-
-
Save dangalipo/a1fd86df39f2711c0ef092b38b1e7fab to your computer and use it in GitHub Desktop.
This is probably made of fail can someone tell me why....
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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