Class: Airbrake::Sender
- Inherits:
-
Object
- Object
- Airbrake::Sender
- Defined in:
- lib/airbrake/sender.rb
Overview
Sends out the notice to Airbrake
Direct Known Subclasses
Constant Summary collapse
- NOTICES_URI =
'/notifier_api/v2/notices'.freeze
- HEADERS =
{ :xml => { 'Content-type' => 'text/xml', 'Accept' => 'text/xml, application/xml' },:json => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }}
- JSON_API_URI =
'/api/v3/projects'.freeze
- HTTP_ERRORS =
[Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Errno::ECONNREFUSED, OpenSSL::SSL::SSLError].freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#http_open_timeout ⇒ Object
readonly
Returns the value of attribute http_open_timeout.
-
#http_read_timeout ⇒ Object
readonly
Returns the value of attribute http_read_timeout.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#project_id ⇒ Object
readonly
Returns the value of attribute project_id.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
-
#proxy_host ⇒ Object
readonly
Returns the value of attribute proxy_host.
-
#proxy_pass ⇒ Object
readonly
Returns the value of attribute proxy_pass.
-
#proxy_port ⇒ Object
readonly
Returns the value of attribute proxy_port.
-
#proxy_user ⇒ Object
readonly
Returns the value of attribute proxy_user.
-
#secure ⇒ Object
(also: #secure?)
readonly
Returns the value of attribute secure.
-
#use_system_ssl_cert_chain ⇒ Object
(also: #use_system_ssl_cert_chain?)
readonly
Returns the value of attribute use_system_ssl_cert_chain.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Sender
constructor
A new instance of Sender.
-
#send_to_airbrake(notice) ⇒ Object
Sends the notice data off to Airbrake for processing.
Constructor Details
#initialize(options = {}) ⇒ Sender
Returns a new instance of Sender.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/airbrake/sender.rb', line 26 def initialize( = {}) [ :proxy_host, :proxy_port, :proxy_user, :proxy_pass, :protocol, :host, :port, :secure, :use_system_ssl_cert_chain, :http_open_timeout, :http_read_timeout, :project_id, :api_key ].each do |option| instance_variable_set("@#{option}", [option]) end end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
87 88 89 |
# File 'lib/airbrake/sender.rb', line 87 def api_key @api_key end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
87 88 89 |
# File 'lib/airbrake/sender.rb', line 87 def host @host end |
#http_open_timeout ⇒ Object (readonly)
Returns the value of attribute http_open_timeout.
87 88 89 |
# File 'lib/airbrake/sender.rb', line 87 def http_open_timeout @http_open_timeout end |
#http_read_timeout ⇒ Object (readonly)
Returns the value of attribute http_read_timeout.
87 88 89 |
# File 'lib/airbrake/sender.rb', line 87 def http_read_timeout @http_read_timeout end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
87 88 89 |
# File 'lib/airbrake/sender.rb', line 87 def port @port end |
#project_id ⇒ Object (readonly)
Returns the value of attribute project_id.
87 88 89 |
# File 'lib/airbrake/sender.rb', line 87 def project_id @project_id end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
87 88 89 |
# File 'lib/airbrake/sender.rb', line 87 def protocol @protocol end |
#proxy_host ⇒ Object (readonly)
Returns the value of attribute proxy_host.
87 88 89 |
# File 'lib/airbrake/sender.rb', line 87 def proxy_host @proxy_host end |
#proxy_pass ⇒ Object (readonly)
Returns the value of attribute proxy_pass.
87 88 89 |
# File 'lib/airbrake/sender.rb', line 87 def proxy_pass @proxy_pass end |
#proxy_port ⇒ Object (readonly)
Returns the value of attribute proxy_port.
87 88 89 |
# File 'lib/airbrake/sender.rb', line 87 def proxy_port @proxy_port end |
#proxy_user ⇒ Object (readonly)
Returns the value of attribute proxy_user.
87 88 89 |
# File 'lib/airbrake/sender.rb', line 87 def proxy_user @proxy_user end |
#secure ⇒ Object (readonly) Also known as: secure?
Returns the value of attribute secure.
87 88 89 |
# File 'lib/airbrake/sender.rb', line 87 def secure @secure end |
#use_system_ssl_cert_chain ⇒ Object (readonly) Also known as: use_system_ssl_cert_chain?
Returns the value of attribute use_system_ssl_cert_chain.
87 88 89 |
# File 'lib/airbrake/sender.rb', line 87 def use_system_ssl_cert_chain @use_system_ssl_cert_chain end |
Instance Method Details
#send_to_airbrake(notice) ⇒ Object
Sends the notice data off to Airbrake for processing.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/airbrake/sender.rb', line 49 def send_to_airbrake(notice) data = prepare_notice(notice) http = setup_http_connection response = begin http.post(url.respond_to?(:path) ? url.path : url, data, headers) rescue *HTTP_ERRORS => e log :level => :error, :message => "Unable to contact the Airbrake server. HTTP Error=#{e}" nil end case response when Net::HTTPSuccess then log :level => :info, :message => "Success: #{response.class}", :response => response else log :level => :error, :message => "Failure: #{response.class}", :response => response, :notice => notice end if response && response.respond_to?(:body) error_id = response.body.match(%r{<id[^>]*>(.*?)</id>}) error_id[1] if error_id end rescue => e log :level => :error, :message => "[Airbrake::Sender#send_to_airbrake] Cannot send notification. Error: #{e.class}" + " - #{e.}\nBacktrace:\n#{e.backtrace.join("\n\t")}" nil end |