crashlog 1.0.0.rc1 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
+ script: bundle exec rake spec
2
3
  rvm:
3
4
  - 1.9.3
4
5
  - 1.9.2
@@ -9,3 +10,7 @@ rvm:
9
10
  - rbx-19mode
10
11
  - jruby-head
11
12
  - ree
13
+ branches:
14
+ only:
15
+ - master
16
+ - develop
data/Gemfile.lock CHANGED
@@ -10,7 +10,7 @@ PATH
10
10
  specs:
11
11
  crashlog (1.0.0.rc1)
12
12
  activesupport
13
- crashlog-auth-hmac (~> 1.1.5)
13
+ crashlog-auth-hmac (~> 1.1.6)
14
14
  faraday
15
15
  hashr
16
16
  rabl (>= 0.6.14)
@@ -50,7 +50,7 @@ GEM
50
50
  arel (3.0.2)
51
51
  builder (3.0.0)
52
52
  chronic (0.6.7)
53
- crashlog-auth-hmac (1.1.5)
53
+ crashlog-auth-hmac (1.1.6)
54
54
  delorean (2.0.0)
55
55
  chronic
56
56
  diff-lcs (1.1.3)
@@ -86,7 +86,7 @@ GEM
86
86
  multipart-post (1.1.5)
87
87
  pg (0.14.0)
88
88
  polyglot (0.3.3)
89
- rabl (0.7.1)
89
+ rabl (0.7.2)
90
90
  activesupport (>= 2.3.14)
91
91
  multi_json (~> 1.0)
92
92
  rack (1.4.1)
data/crashlog.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
 
19
19
  gem.add_dependency("activesupport")
20
20
  gem.add_dependency("faraday")
21
- gem.add_dependency("crashlog-auth-hmac", '~> 1.1.5')
21
+ gem.add_dependency("crashlog-auth-hmac", '~> 1.1.6')
22
22
  gem.add_dependency("yajl-ruby")
23
23
  gem.add_dependency("rabl", '>= 0.6.14')
24
24
  gem.add_dependency("uuid")
@@ -2,5 +2,6 @@
2
2
  require 'crash_log/rails'
3
3
  <% end -%>
4
4
  CrashLog.configure do |config|
5
- config.api_key = <%= api_key_expression %>
5
+ config.api_key = <%= api_key_expression %>
6
+ config.secret = <%= secret_expression %>
6
7
  end
data/lib/crash_log.rb CHANGED
@@ -66,7 +66,7 @@ module CrashLog
66
66
 
67
67
  # Sends the notice unless it is one of the default ignored exceptions.
68
68
  def notify_or_ignore(exception, context = {})
69
- send_notification(exception, context = {}) unless ignored?(exception)
69
+ notify(exception, context = {}) unless ignored?(exception)
70
70
  end
71
71
 
72
72
  # Print a message at the top of the applciation's logs to say we're ready.
@@ -82,12 +82,16 @@ module CrashLog
82
82
 
83
83
  # Configure the gem to send notifications, at the very least an api_key is
84
84
  # required.
85
- def configure(&block)
85
+ def configure(announce = false, &block)
86
86
  if block_given?
87
87
  yield(configuration)
88
88
 
89
89
  if configuration.valid?
90
- report_for_duty!
90
+ if announce.eql?(true)
91
+ report_for_duty!
92
+ else
93
+ info("Configuration updated")
94
+ end
91
95
  elsif !configuration.invalid_keys.include?(:api_key)
92
96
  error("Not configured correctly. Missing the following keys: #{configuration.invalid_keys.join(', ')}")
93
97
  end
@@ -7,7 +7,7 @@ module CrashLog
7
7
  INPUT_FORMAT = %r{^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in `([^']+)')?$}
8
8
 
9
9
  # The file portion of the line (such as app/models/user.rb)
10
- attr_reader :file
10
+ attr_reader :file, :original_file
11
11
 
12
12
  # The line number portion of the line
13
13
  attr_reader :number
@@ -25,9 +25,10 @@ module CrashLog
25
25
  end
26
26
 
27
27
  def initialize(file, number, method)
28
- self.file = file
29
- self.number = number.to_i
30
- self.method = method
28
+ self.file = file
29
+ self.original_file = file
30
+ self.number = number.to_i
31
+ self.method = method
31
32
  end
32
33
 
33
34
  # Reconstructs the line in a readable fashion
@@ -51,18 +52,20 @@ module CrashLog
51
52
  end
52
53
 
53
54
  def context_line
54
- Backtrace::LineCache::getline(file, number)
55
+ Backtrace::LineCache::getline(original_file, number)
55
56
  end
56
57
 
58
+ alias :line_context :context_line
59
+
57
60
  def pre_context
58
61
  (number-context_lines..number-1).map {|i|
59
- Backtrace::LineCache.getline(file, i)
62
+ Backtrace::LineCache.getline(original_file, i)
60
63
  }.select { |line| line }
61
64
  end
62
65
 
63
66
  def post_context
64
67
  (number+1..number+context_lines).map {|i|
65
- Backtrace::LineCache.getline(file, i)
68
+ Backtrace::LineCache.getline(original_file, i)
66
69
  }.select { |line| line }
67
70
  end
68
71
 
@@ -98,7 +101,7 @@ module CrashLog
98
101
 
99
102
  private
100
103
 
101
- attr_writer :file, :number, :method
104
+ attr_writer :file, :number, :method, :original_file
102
105
 
103
106
  end
104
107
  end
@@ -2,6 +2,7 @@ require 'hashr'
2
2
  module CrashLog
3
3
  class Configuration < Hashr
4
4
  DEFAULT_PARAMS_FILTERS = %w(password password_confirmation).freeze
5
+ DEFAULT_USER_ATTRIBUTES = %w(id name full_name username email created_at).freeze
5
6
 
6
7
  DEFAULT_BACKTRACE_FILTERS = [
7
8
  lambda { |line|
@@ -125,6 +126,8 @@ module CrashLog
125
126
 
126
127
  :params_filters => DEFAULT_PARAMS_FILTERS.dup,
127
128
 
129
+ :user_attributes => DEFAULT_USER_ATTRIBUTES.dup,
130
+
128
131
  # Internal
129
132
  # Do not change unless you know what this does.
130
133
  :service_name => 'CrashLog',
@@ -171,7 +174,7 @@ module CrashLog
171
174
  end
172
175
 
173
176
  def ignored?(exception)
174
- ignore.include?(error_class(exception))
177
+ ignore.include?(error_class(exception).to_s)
175
178
  end
176
179
 
177
180
  def secure?
@@ -30,14 +30,12 @@ module CrashLog
30
30
  begin
31
31
  response = @app.call(env)
32
32
  rescue Exception => exception
33
- error_id = CrashLog.notify(exception, :rack_env => env)
34
- env['crash_log.error_id'] = error_id
33
+ CrashLog.notify(exception, :rack_env => env)
35
34
  raise
36
35
  end
37
36
 
38
37
  if env['rack.exception']
39
- error_id = CrashLog.notify(env['rack.exception'], :rack_env => env)
40
- env['crash_log.error_id'] = error_id
38
+ CrashLog.notify(env['rack.exception'], :rack_env => env)
41
39
  end
42
40
 
43
41
  response
@@ -19,7 +19,7 @@ module CrashLog
19
19
  rails_logger = RAILS_DEFAULT_LOGGER
20
20
  end
21
21
 
22
- CrashLog.configure do |config|
22
+ CrashLog.configure(true) do |config|
23
23
  config.logger = rails_logger
24
24
  config.stage = RAILS_ENV if defined?(RAILS_ENV)
25
25
  config.project_root = RAILS_ROOT if defined?(RAILS_ROOT)
@@ -16,13 +16,15 @@ module CrashLog
16
16
 
17
17
  # crash_log_context is defined in controller_methods.rb
18
18
  def rescue_action_in_public_with_crash_log(exception)
19
- crash_log.auto_notify(exception, crash_log_context)
19
+ CrashLog.notify_or_ignore(exception, crash_log_context)
20
+ ensure
20
21
  rescue_action_in_public_without_crash_log(exception)
21
22
  end
22
23
 
23
24
  # crash_log_context is defined in controller_methods.rb
24
25
  def rescue_action_locally_with_crash_log(exception)
25
- crash_log.auto_notify(exception, crash_log_context)
26
+ CrashLog.notify_or_ignore(exception, crash_log_context)
27
+ ensure
26
28
  rescue_action_locally_without_crash_log(exception)
27
29
  end
28
30
  end
@@ -8,7 +8,8 @@ module CrashLog
8
8
  :controller => params[:controller],
9
9
  :action => params[:action],
10
10
  :url => crash_log_request_url,
11
- :cgi_data => crash_log_filter_if_filtering(request.env)
11
+ :cgi_data => crash_log_filter_if_filtering(request.env),
12
+ :current_user => crash_log_current_user
12
13
  }
13
14
  end
14
15
 
@@ -40,6 +41,17 @@ module CrashLog
40
41
  url
41
42
  end
42
43
 
44
+ def crash_log_current_user
45
+ user = begin current_user rescue current_member end
46
+ user.attributes.select do |k, v|
47
+ CrashLog.configuration.
48
+ user_attributes.map(&:to_sym).
49
+ include?(k.to_sym) unless v.blank?
50
+ end.symbolize_keys
51
+ rescue NoMethodError, NameError
52
+ {}
53
+ end
54
+
43
55
  end
44
56
  end
45
57
  end
@@ -12,8 +12,8 @@ module CrashLog
12
12
  def render_exception_with_crash_log(env, exception)
13
13
  controller = env['action_controller.instance']
14
14
 
15
- env['crash_log.error_id'] = CrashLog.notify(exception) #,
16
- # crash_log_context(controller, env))
15
+ CrashLog.notify_or_ignore(exception) #,
16
+ # crash_log_context(controller, env))
17
17
 
18
18
  if defined?(controller.rescue_action_in_public_without_crash_log)
19
19
  controller.rescue_action_in_public_without_crash_log(exception)
@@ -6,7 +6,7 @@ module CrashLog
6
6
  class Railtie < ::Rails::Railtie
7
7
 
8
8
  config.after_initialize do
9
- CrashLog.configure do |config|
9
+ CrashLog.configure(true) do |config|
10
10
  config.logger = ::Rails.logger
11
11
  config.stage = ::Rails.env
12
12
  config.project_root = ::Rails.root
@@ -72,7 +72,7 @@ module CrashLog
72
72
  def post(endpoint, body)
73
73
  connection.post do |req|
74
74
  req.url(endpoint)
75
- req.headers['Content-Type'] = 'application/json'
75
+ req.headers['Content-Type'] = 'application/json; charset=UTF-8'
76
76
  req.body = body
77
77
  end
78
78
  end
@@ -1,3 +1,3 @@
1
1
  module CrashLog
2
- VERSION = "1.0.0.rc1"
2
+ VERSION = "1.0.0.rc2"
3
3
  end
@@ -3,6 +3,7 @@ require 'rails/generators'
3
3
  class CrashlogGenerator < Rails::Generators::Base
4
4
 
5
5
  class_option :api_key, :aliases => "-k", :type => :string, :desc => "Your CrashLog API key"
6
+ class_option :secret, :aliases => "-s", :type => :string, :desc => "Your CrashLog API secret"
6
7
 
7
8
  def self.source_root
8
9
  @_crashlog_source_root ||= File.expand_path("../../../../../generators/crashlog/templates", __FILE__)
@@ -17,8 +18,10 @@ class CrashlogGenerator < Rails::Generators::Base
17
18
  private
18
19
 
19
20
  def ensure_api_key_was_configured
20
- if !options[:api_key] && !api_key_configured?
21
- puts "Must pass --api-key or create config/initializers/crashlog.rb"
21
+ if !options[:api_key] &&
22
+ !options[:secret] &&
23
+ !api_key_configured?
24
+ puts "Must pass --api-key and --secret or create config/initializers/crashlog.rb"
22
25
  exit
23
26
  end
24
27
  end
@@ -27,6 +30,10 @@ class CrashlogGenerator < Rails::Generators::Base
27
30
  "'#{options[:api_key]}'"
28
31
  end
29
32
 
33
+ def secret_expression
34
+ "'#{options[:secret]}'"
35
+ end
36
+
30
37
  def generate_initializer
31
38
  template 'initializer.rb', 'config/initializers/crashlog.rb'
32
39
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'logger'
4
4
  require 'fileutils'
5
+ require "uri"
5
6
 
6
7
  RAILS_ENV = "production"
7
8
  RAILS_ROOT = FileUtils.pwd
@@ -18,17 +19,27 @@ host ||= "stdin.crashlog.io"
18
19
 
19
20
  secure = (ARGV[2] == "secure")
20
21
 
21
- exception = begin
22
- raise "Testing crashlog notifier with secure = #{secure}. If you can see this, it works."
23
- rescue => foo
24
- foo
25
- end
22
+ class SimulatedExceptionRaiser
23
+ attr_reader :secure
24
+
25
+ def initialize(secure)
26
+ @secure = secure
27
+ break_things
28
+ rescue => e
29
+ CrashLog.notify(e)
30
+ end
31
+
32
+ def break_things
33
+ raise "Testing crashlog notifier with secure = #{secure}. If you can see this, it works."
34
+ end
35
+ end
26
36
 
27
37
  CrashLog.configure do |config|
28
38
  config.api_key = ARGV[0]
29
39
  config.secret = ARGV[1]
30
40
  config.scheme = secure ? 'https' : 'http'
31
- config.host = host
41
+ config.host = URI.parse(host).host
42
+ config.port = URI.parse(host).port
32
43
  config.service_name = 'Staging'
33
44
  end
34
45
 
@@ -37,4 +48,5 @@ CrashLog.configuration.each do |key, value|
37
48
  puts sprintf("%25s: %s", key.to_s, value.inspect.slice(0, 55))
38
49
  end
39
50
  puts "Sending #{secure ? "" : "in"}secure notification to project with key #{ARGV.first}"
40
- CrashLog.notify(exception)
51
+
52
+ SimulatedExceptionRaiser.new(secure)
@@ -55,6 +55,16 @@ describe CrashLog::Backtrace do
55
55
  ""
56
56
  ]
57
57
  end
58
+
59
+ it 'does not filter context file path' do
60
+ CrashLog.configuration.project_root = File.expand_path('../../', __FILE__)
61
+ filters = CrashLog.configuration.backtrace_filters
62
+ backtrace = CrashLog::Backtrace.parse(raised_error.backtrace, :filters => filters)
63
+ line = backtrace.lines.first
64
+
65
+ line.file.should match /\[PROJECT_ROOT\]/
66
+ line.context_line.should match /raise RuntimeError/
67
+ end
58
68
  end
59
69
 
60
70
  describe 'filters' do
@@ -149,5 +149,15 @@ describe CrashLog do
149
149
 
150
150
  CrashLog.ignored?(ActiveRecord::RecordNotFound).should be_true
151
151
  end
152
+
153
+ it 'ignores ActionController::RoutingError' do
154
+ unless defined?(ActionController)
155
+ module ActionController
156
+ class RoutingError < RuntimeError
157
+ end
158
+ end
159
+ end
160
+ CrashLog.ignored?(ActionController::RoutingError).should be_true
161
+ end
152
162
  end
153
163
  end
@@ -6,7 +6,7 @@ describe 'Rescue from within a Rails 3.x controller' do
6
6
  include Rack::Test::Methods
7
7
 
8
8
  it 'is testing tails 3.x' do
9
- Rails.version.should =~ /^3\./
9
+ Rails.version.should =~ /^3\.2\./
10
10
  end
11
11
 
12
12
  describe 'dummy app' do
@@ -18,14 +18,15 @@ describe 'Rescue from within a Rails 3.x controller' do
18
18
  end
19
19
 
20
20
  it 'should intercept error and notify crashlog' do
21
- CrashLog.should_receive(:notify).with(kind_of(RuntimeError)).once
21
+ CrashLog.should_receive(:notify_or_ignore).with(kind_of(RuntimeError)).once
22
22
 
23
- begin
23
+ # begin
24
24
  get '/broken'
25
25
  last_response.status.should == 500
26
26
  last_response.body.should match /We're sorry, but something went wrong/
27
- rescue
28
- end
27
+ # rescue => e
28
+ # nil
29
+ # end
29
30
 
30
31
  end
31
32
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crashlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc1
4
+ version: 1.0.0.rc2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-23 00:00:00.000000000 Z
12
+ date: 2012-10-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70309383792940 !ruby/object:Gem::Requirement
16
+ requirement: &70250400938220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70309383792940
24
+ version_requirements: *70250400938220
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: faraday
27
- requirement: &70309383792280 !ruby/object:Gem::Requirement
27
+ requirement: &70250400937800 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,21 +32,21 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70309383792280
35
+ version_requirements: *70250400937800
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: crashlog-auth-hmac
38
- requirement: &70309383791780 !ruby/object:Gem::Requirement
38
+ requirement: &70250400937300 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
42
42
  - !ruby/object:Gem::Version
43
- version: 1.1.5
43
+ version: 1.1.6
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70309383791780
46
+ version_requirements: *70250400937300
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: yajl-ruby
49
- requirement: &70309383791260 !ruby/object:Gem::Requirement
49
+ requirement: &70250400936880 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70309383791260
57
+ version_requirements: *70250400936880
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rabl
60
- requirement: &70309383806820 !ruby/object:Gem::Requirement
60
+ requirement: &70250400936340 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.6.14
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70309383806820
68
+ version_requirements: *70250400936340
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: uuid
71
- requirement: &70309383806220 !ruby/object:Gem::Requirement
71
+ requirement: &70250400935920 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70309383806220
79
+ version_requirements: *70250400935920
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: hashr
82
- requirement: &70309383805760 !ruby/object:Gem::Requirement
82
+ requirement: &70250400935460 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70309383805760
90
+ version_requirements: *70250400935460
91
91
  description: CrashLog Exception reporter
92
92
  email:
93
93
  - support@crashlog.io