davidjrice-exceptional 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Manifest CHANGED
@@ -1,4 +1,3 @@
1
- exceptional.gemspec
2
1
  exceptional.yml
3
2
  History.txt
4
3
  init.rb
@@ -6,7 +5,9 @@ install.rb
6
5
  lib/exceptional/agent/worker.rb
7
6
  lib/exceptional/deployed_environment.rb
8
7
  lib/exceptional/exception_data.rb
8
+ lib/exceptional/integration/merb.rb
9
9
  lib/exceptional/integration/rails.rb
10
+ lib/exceptional/merb.rb
10
11
  lib/exceptional/rails.rb
11
12
  lib/exceptional/version.rb
12
13
  lib/exceptional.rb
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  begin
2
2
  require 'echoe'
3
3
 
4
- Echoe.new('exceptional', '0.0.1') do |p|
4
+ Echoe.new('exceptional', '0.0.2') do |p|
5
5
  p.rubyforge_name = 'exceptional'
6
6
  p.summary = "Exceptional is the core Ruby library for communicating with http://getexceptional.com (hosted error tracking service)"
7
7
  p.description = "Exceptional is the core Ruby library for communicating with http://getexceptional.com (hosted error tracking service)"
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "exceptional"
3
- s.version = "0.0.1"
3
+ s.version = "0.0.2"
4
4
  s.date = "2008-10-13"
5
5
  s.summary = "Exceptional is the core Ruby library for communicating with http://getexceptional.com (hosted error tracking service)"
6
6
  s.email = "david@getexceptional.com"
@@ -19,7 +19,9 @@ Gem::Specification.new do |s|
19
19
  "lib/exceptional/agent/worker.rb",
20
20
  "lib/exceptional/deployed_environment.rb",
21
21
  "lib/exceptional/exception_data.rb",
22
+ "lib/exceptional/integration/merb.rb",
22
23
  "lib/exceptional/integration/rails.rb",
24
+ "lib/exceptional/merb.rb",
23
25
  "lib/exceptional/rails.rb",
24
26
  "lib/exceptional/version.rb",
25
27
  "lib/exceptional.rb"]
@@ -27,8 +29,8 @@ Gem::Specification.new do |s|
27
29
  "spec/exception_data_spec.rb",
28
30
  "spec/exceptional_spec.rb",
29
31
  "spec/spec_helper.rb",
30
- "spec/worker_spec.rbrb"]
32
+ "spec/worker_spec.rb"]
31
33
  s.rdoc_options = ["--main", "README"]
32
34
  s.extra_rdoc_files = ["History.txt", "Manifest", "README"]
33
35
  s.add_dependency("json", ["> 0.0.0"])
34
- end
36
+ end
data/install.rb CHANGED
@@ -15,4 +15,5 @@ else
15
15
  puts "For exceptional to work you need to configure your API Key"
16
16
  puts " See #{example_config_file}"
17
17
  puts "If you don't have an API Key, get one at http://getexceptional.com/"
18
- end
18
+ File.copy example_config_file, config_file
19
+ end
@@ -1,4 +1,6 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
+ require 'exceptional/integration/merb'
3
+ require 'exceptional/merb'
2
4
  require 'exceptional/rails'
3
5
  require 'exceptional/deployed_environment'
4
6
  require 'exceptional/agent/worker'
@@ -95,7 +97,8 @@ module Exceptional
95
97
  e.controller_name = controller.controller_name
96
98
  e.action_name = controller.action_name
97
99
  e.application_root = self.application_root
98
- e.occurred_at = Time.now.to_s
100
+ e.occurred_at = Time.now.strftime("%Y%m%d %H:%M:%S %Z")
101
+ e.environment = request.env.to_hash
99
102
  e.url = "#{request.protocol}#{request.host}#{request.request_uri}"
100
103
  # Need to remove rack data from environment hash
101
104
  safe_environment = request.env.to_hash
@@ -127,6 +130,45 @@ module Exceptional
127
130
  end
128
131
  end
129
132
 
133
+ def handle_merb(exception, request, params)
134
+ log! "Handling #{exception.message}", 'info'
135
+ e = parse(exception)
136
+ # Additional data for Merb Exceptions
137
+ e.framework = "merb"
138
+ e.controller_name = params['controller']
139
+ e.action_name = params['action']
140
+ e.application_root = self.application_root
141
+ e.occurred_at = Time.now.to_s
142
+ e.url = "#{request.protocol}#{request.host}#{request.uri}"
143
+ # Need to remove rack data from environment hash
144
+ safe_environment = request.env.to_hash
145
+ safe_environment.delete_if { |k,v| k =~ /rack/ }
146
+ e.environment = safe_environment
147
+
148
+ safe_session = {}
149
+ request.session.instance_variables.each do |v|
150
+ next if v =~ /cgi/
151
+ next if v =~ /db/
152
+ # remove prepended @'s
153
+ var = v.sub("@","")
154
+ safe_session[var] = request.session.instance_variable_get(v)
155
+ end
156
+
157
+ e.session = safe_session
158
+ e.parameters = params ? params.to_hash : {}
159
+
160
+ if mode == :queue
161
+ worker.add_exception(e)
162
+ else # :direct mode
163
+ begin
164
+ post e
165
+ rescue
166
+ log! "Error posting data to Exceptional."
167
+ log! e.message
168
+ log! e.backtace.join("\n"), 'debug'
169
+ end
170
+ end
171
+ end
130
172
  # TODO these configuration methods & defaults should have their own class
131
173
  def remote_host
132
174
  @remote_host || ::REMOTE_HOST
@@ -224,4 +266,28 @@ module Exceptional
224
266
 
225
267
  end
226
268
 
269
+ end
270
+
271
+ # Hack to enable the gem as a Merb plugin.
272
+ if defined?(Merb::Plugins)
273
+ Merb::BootLoader.after_app_loads do
274
+ def to_stderr(s)
275
+ STDERR.puts "** [Exceptional] " + s
276
+ end
277
+
278
+ config_file = File.join(Merb.root,"/config/exceptional.yml")
279
+ begin
280
+ Exceptional.application_root = Merb.root
281
+ Exceptional.environment = Merb.environment.to_s
282
+
283
+ Exceptional.load_config(config_file)
284
+ if Exceptional.enabled?
285
+ Exceptional::Merb.init
286
+ end
287
+
288
+ rescue Exception => e
289
+ to_stderr e
290
+ to_stderr "Plugin disabled."
291
+ end
292
+ end
227
293
  end
@@ -80,5 +80,7 @@ module Exceptional
80
80
  @identifier = 'passenger'
81
81
  end
82
82
  end
83
+
83
84
  end
84
- end
85
+ end
86
+
@@ -0,0 +1,36 @@
1
+ module Exceptional
2
+ module Integration
3
+ module Merb
4
+ def self.included(mod)
5
+ mod.class_eval do
6
+ def base
7
+ self.render_with_exceptional template_or_message, :layout=>false
8
+ end
9
+
10
+ def exception
11
+ self.render_with_exceptional template_or_message, :layout=>false
12
+ end
13
+
14
+ private
15
+
16
+ def template_or_message
17
+ if File.exists?(Exceptional.application_root / 'app' / 'views' / 'exceptions' / 'internal_server_error.html.erb')
18
+ :internal_server_error
19
+ else
20
+ '500 exception. Please customize this page by creating app/views/exceptions/internal_server_error.html.erb.'
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ def render_with_exceptional(*opts)
27
+ self.render_then_call(render(*opts)) { post_to_exceptional }
28
+ end
29
+
30
+ def post_to_exceptional
31
+ exception = self.request.exceptions.first
32
+ Exceptional.handle_merb(exception, request, params)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,51 @@
1
+ module Exceptional
2
+ # TODO this class could really be 'drier', merge with Exceptional::Rails
3
+ # perhaps create an initializers module.
4
+ class Merb
5
+
6
+ def self.init
7
+ # With Merb, we can't determine the deployed environment on boot as that
8
+ # appears to load after the app & plugins.
9
+ setup_log
10
+ Exceptional.log_config_info
11
+
12
+ if Exceptional.authenticate
13
+
14
+ if Exceptional.mode == :queue
15
+ Exceptional.worker = Agent::Worker.new(Exceptional.log)
16
+ Exceptional.worker_thread = Thread.new do
17
+ Exceptional.worker.run
18
+ end
19
+ end
20
+
21
+ # Install hook in Merb's Exceptions controller.
22
+ Exceptions.send(:include, Exceptional::Integration::Merb)
23
+
24
+ at_exit do
25
+ if Exceptional.mode == :queue
26
+ Exceptional.worker_thread.terminate if Exceptional.worker_thread
27
+ end
28
+ end
29
+ else
30
+ Exceptional.log! "Plugin not authenticated, check your API Key"
31
+ Exceptional.log! "Disabling Plugin."
32
+ end
33
+ end
34
+
35
+ def self.setup_log
36
+ log_file = "#{Exceptional.application_root}/log/exceptional.log"
37
+
38
+ @log = Logger.new log_file
39
+ @log.level = Logger::INFO
40
+
41
+ allowed_log_levels = ['debug', 'info', 'warn', 'error', 'fatal']
42
+ if Exceptional.log_level && allowed_log_levels.include?(Exceptional.log_level)
43
+ @log.level = eval("Logger::#{Exceptional.log_level.upcase}")
44
+ end
45
+
46
+ Exceptional.log = @log
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Exceptional::Agent::Worker do
4
+
5
+ before(:each) do
6
+ @worker = Exceptional::Agent::Worker.new
7
+ end
8
+
9
+ describe "after initialisation" do
10
+
11
+ it "should default worker timeout" do
12
+ @worker.timeout.should == 10
13
+ end
14
+
15
+ it "should have no exceptions" do
16
+ @worker.exceptions.should == []
17
+ end
18
+
19
+ end
20
+
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: davidjrice-exceptional
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Rice
@@ -44,7 +44,9 @@ files:
44
44
  - lib/exceptional/agent/worker.rb
45
45
  - lib/exceptional/deployed_environment.rb
46
46
  - lib/exceptional/exception_data.rb
47
+ - lib/exceptional/integration/merb.rb
47
48
  - lib/exceptional/integration/rails.rb
49
+ - lib/exceptional/merb.rb
48
50
  - lib/exceptional/rails.rb
49
51
  - lib/exceptional/version.rb
50
52
  - lib/exceptional.rb
@@ -80,4 +82,4 @@ test_files:
80
82
  - spec/exception_data_spec.rb
81
83
  - spec/exceptional_spec.rb
82
84
  - spec/spec_helper.rb
83
- - spec/worker_spec.rbrb
85
+ - spec/worker_spec.rb