airbrake-faraday_sender 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2011 Viximo, Inc.
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
1
+ # Airbrake::FaradaySender
2
+
3
+ Replace Airbrake's sender implementation with one that uses Faraday. Use Faraday's EventMachine
4
+ adapters to have non-blocking error reports.
5
+
6
+ * Add to your Gemfile.
7
+ * Set Faraday.default_adapter
@@ -0,0 +1,7 @@
1
+ require 'bundler'
2
+ Bundler.setup :development
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new do |s|
7
+ end
@@ -0,0 +1,15 @@
1
+ require 'airbrake'
2
+ require 'airbrake/faraday_sender'
3
+
4
+ Airbrake.instance_eval do
5
+ def configure_with_faraday_sender(*args, &block)
6
+ configure_without_faraday_sender(*args, &block).tap do
7
+ self.sender = Airbrake::FaradaySender.new(configuration)
8
+ end
9
+ end
10
+
11
+ class << self
12
+ alias_method :configure_without_faraday_sender, :configure
13
+ alias_method :configure, :configure_with_faraday_sender
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ module Airbrake
2
+ class FaradaySender
3
+ module Version
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ PATCH = 1
7
+ STRING = [MAJOR, MINOR, PATCH].join('.')
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,81 @@
1
+ require 'faraday'
2
+
3
+ module Airbrake
4
+ class FaradaySender
5
+ extend Forwardable
6
+
7
+ def_delegators :@configuration, :secure, :protocol, :host, :port,
8
+ :http_open_timeout, :http_read_timeout
9
+
10
+ class << self
11
+ attr_accessor :faraday_middleware
12
+ end
13
+
14
+ def initialize(configuration)
15
+ @configuration = configuration
16
+ end
17
+
18
+ # Override the send to airbrake method
19
+ def send_to_airbrake(data)
20
+ log :debug, "Sending request to #{url.to_s}:\n#{data}"
21
+
22
+ response = begin
23
+ log :info, "Starting post::: #{url.path}"
24
+ connection.post(url.path, data) do |req|
25
+ req.headers = Airbrake::HEADERS
26
+ end
27
+ rescue Faraday::Error::ClientError => e
28
+ log :error, "Error contacting Airbrake server: #{e.message}"
29
+ return
30
+ end
31
+
32
+ log :info, "Success: #{response.class}", response
33
+
34
+ if response.respond_to?(:body)
35
+ error_id = response.body.match(%r{<error-id[^>]*>(.*?)</error-id>})
36
+ error_id[1] if error_id
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ # Define the farday connection
43
+ def connection
44
+ ssl = {}
45
+ if secure
46
+ ssl[:use_ssl] = true
47
+ ssl[:ca_file] = OpenSSL::X509::DEFAULT_CERT_FILE if File.exist?(OpenSSL::X509::DEFAULT_CERT_FILE)
48
+ ssl[:verify_mode] = OpenSSL::SSL::VERIFY_PEER
49
+ else
50
+ ssl[:use_ssl] = false
51
+ end
52
+
53
+ Faraday.new("#{url.scheme}://#{url.host}", {
54
+ :ssl => ssl,
55
+ :request => {:open_timeout => http_open_timeout, :timeout => http_read_timeout}
56
+ }) do |builder|
57
+ builder.response :raise_error
58
+
59
+ if self.class.faraday_middleware
60
+ self.class.faraday_middleware.call(builder)
61
+ else
62
+ builder.adapter Faraday.default_adapter
63
+ end
64
+ end
65
+ end
66
+
67
+ def url
68
+ URI.parse("#{protocol}://#{host}:#{port}").merge(Airbrake::Sender::NOTICES_URI)
69
+ end
70
+
71
+ def log(level, message, response = nil)
72
+ logger.send level, LOG_PREFIX + message if logger
73
+ Airbrake.report_environment_info
74
+ Airbrake.report_response_body(response.body) if response && response.respond_to?(:body)
75
+ end
76
+
77
+ def logger
78
+ Airbrake.logger
79
+ end
80
+ end
81
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: airbrake-faraday_sender
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Matt Griffin
14
+ - Wes Jossey
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-10-14 00:00:00 -04:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: faraday
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: airbrake
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 7
45
+ segments:
46
+ - 3
47
+ - 0
48
+ version: "3.0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description: " Airbrake sender implementation usign Faraday. Faraday's pluggable backends allow Airbrake to be \n used with net_http or EventMachine/Synchrony.\n"
52
+ email: matt@griffinonline.org
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ files:
60
+ - README.md
61
+ - Rakefile
62
+ - LICENSE
63
+ - lib/airbrake/faraday_sender.rb
64
+ - lib/airbrake-faraday_sender/version.rb
65
+ - lib/airbrake-faraday_sender.rb
66
+ has_rdoc: true
67
+ homepage: http://github.com/Viximo/airbrake-faraday_sender
68
+ licenses:
69
+ - MIT
70
+ post_install_message:
71
+ rdoc_options: []
72
+
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ requirements: []
94
+
95
+ rubyforge_project:
96
+ rubygems_version: 1.5.3
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Airbrake sender implementation usign Faraday.
100
+ test_files: []
101
+