crashlog 1.0.3 → 1.0.4

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/.gitignore CHANGED
@@ -15,4 +15,7 @@ test/tmp
15
15
  test/version_tmp
16
16
  tmp
17
17
 
18
- spec/dummy/log/development.log
18
+ spec/dummy/log/development.log
19
+ .rbenv-*
20
+
21
+ /.rbx/
data/Gemfile CHANGED
@@ -3,11 +3,13 @@ source :rubygems
3
3
  # Specify your gem's dependencies in crashlog.gemspec
4
4
  gemspec
5
5
 
6
- gem 'rspec-rails'
6
+ # gem 'rspec-rails'
7
+ gem 'rspec'
7
8
  gem 'guard-rspec'
8
9
  gem 'uuid'
9
10
  gem 'json_spec'
10
11
  gem 'rake', '~> 0.9.2'
11
- gem 'rails', '~> 3.2.7'
12
+ # gem 'rails', '~> 3.2.7'
12
13
  gem 'delorean'
13
14
  gem 'rack-test', :git => 'git://github.com/brynary/rack-test.git'
15
+ gem 'simplecov', :platforms => :mri_19
@@ -8,11 +8,11 @@ GIT
8
8
  PATH
9
9
  remote: .
10
10
  specs:
11
- crashlog (1.0.1)
12
- activesupport
11
+ crashlog (1.0.3)
13
12
  crashlog-auth-hmac (~> 1.1.6)
14
13
  faraday (~> 0.8.4)
15
14
  hashr
15
+ json
16
16
  multi_json (~> 1.3.6)
17
17
  rabl (>= 0.6.14)
18
18
  uuid
@@ -20,54 +20,27 @@ PATH
20
20
  GEM
21
21
  remote: http://rubygems.org/
22
22
  specs:
23
- actionmailer (3.2.7)
24
- actionpack (= 3.2.7)
25
- mail (~> 2.4.4)
26
- actionpack (3.2.7)
27
- activemodel (= 3.2.7)
28
- activesupport (= 3.2.7)
29
- builder (~> 3.0.0)
30
- erubis (~> 2.7.0)
31
- journey (~> 1.0.4)
32
- rack (~> 1.4.0)
33
- rack-cache (~> 1.2)
34
- rack-test (~> 0.6.1)
35
- sprockets (~> 2.1.3)
36
- activemodel (3.2.7)
37
- activesupport (= 3.2.7)
38
- builder (~> 3.0.0)
39
- activerecord (3.2.7)
40
- activemodel (= 3.2.7)
41
- activesupport (= 3.2.7)
42
- arel (~> 3.0.2)
43
- tzinfo (~> 0.3.29)
44
- activeresource (3.2.7)
45
- activemodel (= 3.2.7)
46
- activesupport (= 3.2.7)
47
- activesupport (3.2.7)
23
+ activesupport (3.2.8)
48
24
  i18n (~> 0.6)
49
25
  multi_json (~> 1.0)
50
- arel (3.0.2)
51
- builder (3.0.0)
52
26
  chronic (0.6.7)
53
27
  crashlog-auth-hmac (1.1.6)
54
28
  delorean (2.0.0)
55
29
  chronic
56
30
  diff-lcs (1.1.3)
57
- erubis (2.7.0)
58
31
  faraday (0.8.4)
59
32
  multipart-post (~> 1.1)
60
33
  ffi (1.1.1)
34
+ ffi (1.1.1-java)
61
35
  guard (1.2.3)
62
36
  listen (>= 0.4.2)
63
37
  thor (>= 0.14.6)
64
38
  guard-rspec (1.2.0)
65
39
  guard (>= 1.1)
66
40
  hashr (0.0.22)
67
- hike (1.2.1)
68
- i18n (0.6.0)
69
- journey (1.0.4)
70
- json (1.7.4)
41
+ i18n (0.6.1)
42
+ json (1.7.5)
43
+ json (1.7.5-java)
71
44
  json_spec (1.0.3)
72
45
  multi_json (~> 1.0)
73
46
  rspec (~> 2.0)
@@ -77,45 +50,18 @@ GEM
77
50
  rb-inotify (~> 0.8.8)
78
51
  macaddr (1.6.1)
79
52
  systemu (~> 2.5.0)
80
- mail (2.4.4)
81
- i18n (>= 0.4.0)
82
- mime-types (~> 1.16)
83
- treetop (~> 1.4.8)
84
- mime-types (1.19)
85
53
  multi_json (1.3.6)
86
54
  multipart-post (1.1.5)
87
- polyglot (0.3.3)
88
- rabl (0.7.2)
55
+ rabl (0.7.3)
89
56
  activesupport (>= 2.3.14)
90
57
  multi_json (~> 1.0)
91
58
  rack (1.4.1)
92
- rack-cache (1.2)
93
- rack (>= 0.4)
94
- rack-ssl (1.3.2)
95
- rack
96
- rails (3.2.7)
97
- actionmailer (= 3.2.7)
98
- actionpack (= 3.2.7)
99
- activerecord (= 3.2.7)
100
- activeresource (= 3.2.7)
101
- activesupport (= 3.2.7)
102
- bundler (~> 1.0)
103
- railties (= 3.2.7)
104
- railties (3.2.7)
105
- actionpack (= 3.2.7)
106
- activesupport (= 3.2.7)
107
- rack-ssl (~> 1.3.2)
108
- rake (>= 0.8.7)
109
- rdoc (~> 3.4)
110
- thor (>= 0.14.6, < 2.0)
111
59
  rake (0.9.2.2)
112
60
  rb-fchange (0.0.5)
113
61
  ffi
114
62
  rb-fsevent (0.9.1)
115
63
  rb-inotify (0.8.8)
116
64
  ffi (>= 0.5.0)
117
- rdoc (3.12)
118
- json (~> 1.4)
119
65
  rspec (2.11.0)
120
66
  rspec-core (~> 2.11.0)
121
67
  rspec-expectations (~> 2.11.0)
@@ -124,26 +70,17 @@ GEM
124
70
  rspec-expectations (2.11.2)
125
71
  diff-lcs (~> 1.1.3)
126
72
  rspec-mocks (2.11.1)
127
- rspec-rails (2.11.0)
128
- actionpack (>= 3.0)
129
- activesupport (>= 3.0)
130
- railties (>= 3.0)
131
- rspec (~> 2.11.0)
132
- sprockets (2.1.3)
133
- hike (~> 1.2)
134
- rack (~> 1.0)
135
- tilt (~> 1.1, != 1.3.0)
73
+ simplecov (0.6.4)
74
+ multi_json (~> 1.0)
75
+ simplecov-html (~> 0.5.3)
76
+ simplecov-html (0.5.3)
136
77
  systemu (2.5.2)
137
78
  thor (0.15.4)
138
- tilt (1.3.3)
139
- treetop (1.4.10)
140
- polyglot
141
- polyglot (>= 0.3.1)
142
- tzinfo (0.3.33)
143
79
  uuid (2.3.5)
144
80
  macaddr (~> 1.0)
145
81
 
146
82
  PLATFORMS
83
+ java
147
84
  ruby
148
85
 
149
86
  DEPENDENCIES
@@ -152,7 +89,7 @@ DEPENDENCIES
152
89
  guard-rspec
153
90
  json_spec
154
91
  rack-test!
155
- rails (~> 3.2.7)
156
92
  rake (~> 0.9.2)
157
- rspec-rails
93
+ rspec
94
+ simplecov
158
95
  uuid
data/README.md CHANGED
@@ -9,7 +9,9 @@ insight into issues occurring within your production applications, in realtime.
9
9
 
10
10
  Add this line to your application's Gemfile:
11
11
 
12
- gem 'crashlog'
12
+ ```ruby
13
+ gem 'crashlog'
14
+ ```
13
15
 
14
16
  And then execute:
15
17
 
data/Rakefile CHANGED
@@ -1,9 +1,7 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
3
 
4
- $: << 'lib'
5
-
6
- require "crash_log"
4
+ require File.expand_path("../lib/crash_log", __FILE__)
7
5
 
8
6
  require 'rake'
9
7
  require "rspec/core/rake_task"
@@ -11,4 +9,4 @@ require "rspec/core/rake_task"
11
9
  desc "Run all examples"
12
10
  RSpec::Core::RakeTask.new
13
11
 
14
- task :default => :spec
12
+ task :default => :spec
@@ -15,11 +15,11 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = CrashLog::VERSION
17
17
 
18
- gem.add_dependency("activesupport")
19
18
  gem.add_dependency("faraday", '~> 0.8.4')
20
19
  gem.add_dependency("multi_json", '~> 1.3.6')
21
20
  gem.add_dependency("crashlog-auth-hmac", '~> 1.1.6')
22
21
  gem.add_dependency("rabl", '>= 0.6.14')
23
22
  gem.add_dependency("uuid")
24
23
  gem.add_dependency("hashr")
24
+ gem.add_dependency("json")
25
25
  end
@@ -0,0 +1,51 @@
1
+ class Hash
2
+ # Return a new hash with all keys converted to strings.
3
+ #
4
+ # { :name => 'Rob', :years => '28' }.stringify_keys
5
+ # #=> { "name" => "Rob", "years" => "28" }
6
+ def stringify_keys
7
+ dup.stringify_keys!
8
+ end
9
+
10
+ # Destructively convert all keys to strings. Same as
11
+ # +stringify_keys+, but modifies +self+.
12
+ def stringify_keys!
13
+ keys.each do |key|
14
+ self[key.to_s] = delete(key)
15
+ end
16
+ self
17
+ end
18
+
19
+ # Return a new hash with all keys converted to symbols, as long as
20
+ # they respond to +to_sym+.
21
+ #
22
+ # { 'name' => 'Rob', 'years' => '28' }.symbolize_keys
23
+ # #=> { :name => "Rob", :years => "28" }
24
+ def symbolize_keys
25
+ dup.symbolize_keys!
26
+ end
27
+
28
+ # Destructively convert all keys to symbols, as long as they respond
29
+ # to +to_sym+. Same as +symbolize_keys+, but modifies +self+.
30
+ def symbolize_keys!
31
+ keys.each do |key|
32
+ self[(key.to_sym rescue key) || key] = delete(key)
33
+ end
34
+ self
35
+ end
36
+
37
+ # Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch.
38
+ # Note that keys are NOT treated indifferently, meaning if you use strings for keys but assert symbols
39
+ # as keys, this will fail.
40
+ #
41
+ # ==== Examples
42
+ # { :name => "Rob", :years => "28" }.assert_valid_keys(:name, :age) # => raises "ArgumentError: Unknown key: years"
43
+ # { :name => "Rob", :age => "28" }.assert_valid_keys("name", "age") # => raises "ArgumentError: Unknown key: name"
44
+ # { :name => "Rob", :age => "28" }.assert_valid_keys(:name, :age) # => passes, raises nothing
45
+ def assert_valid_keys(*valid_keys)
46
+ valid_keys.flatten!
47
+ each_key do |k|
48
+ raise(ArgumentError, "Unknown key: #{k}") unless valid_keys.include?(k)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,7 @@
1
+ unless Kernel.respond_to?(:require_relative)
2
+ module Kernel
3
+ def require_relative(path)
4
+ require File.join(File.dirname(caller[0]), path.to_str)
5
+ end
6
+ end
7
+ end
@@ -1,31 +1,23 @@
1
- $: << File.expand_path('..', __FILE__)
2
-
3
- require 'crash_log/version'
4
-
5
- begin
6
- require 'active_support'
7
- require 'active_support/core_ext'
8
- rescue LoadError
9
- require 'activesupport'
10
- require 'activesupport/core_ext'
11
- end
12
-
13
1
  require 'faraday'
14
2
  require 'multi_json'
3
+ require 'time'
4
+
5
+ require File.expand_path('../core_ext/kernel/require_relative', __FILE__)
15
6
 
16
- require 'crash_log/railtie' if defined?(Rails::Railtie)
17
- require 'crash_log/logging'
7
+ require_relative 'core_ext/hash/keys'
8
+ require_relative 'crash_log/version'
9
+ require_relative 'crash_log/logging'
10
+ require_relative 'crash_log/helpers'
11
+ require_relative 'crash_log/backtrace'
12
+ require_relative 'crash_log/configuration'
13
+ require_relative 'crash_log/payload'
14
+ require_relative 'crash_log/reporter'
15
+ require_relative 'crash_log/system_information'
16
+ require_relative 'crash_log/rack'
18
17
 
19
18
  module CrashLog
20
19
  extend Logging::ClassMethods
21
20
 
22
- autoload :Backtrace, 'crash_log/backtrace'
23
- autoload :Configuration, 'crash_log/configuration'
24
- autoload :Payload, 'crash_log/payload'
25
- autoload :Rack, 'crash_log/rack'
26
- autoload :Reporter, 'crash_log/reporter'
27
- autoload :SystemInformation, 'crash_log/system_information'
28
-
29
21
  LOG_PREFIX = '** [CrashLog]'
30
22
 
31
23
  class << self
@@ -49,7 +41,7 @@ module CrashLog
49
41
  # def something_dangerous
50
42
  # raise RuntimeError, "This is too dangerous for you"
51
43
  # rescue => e
52
- # CrashLog.notify(e, {current_user: current_user})
44
+ # CrashLog.notify(e, {context: {current_user: current_user}})
53
45
  # end
54
46
  #
55
47
  # Returns true if successful, otherwise false
@@ -57,7 +49,11 @@ module CrashLog
57
49
  send_notification(exception, data).tap do |notification|
58
50
  if notification
59
51
  info "Event sent to CrashLog.io"
60
- info "Event URL: http://crashlog.io/locate/#{notification[:location_id]}" if notification.has_key?(:location_id)
52
+ if notification.has_key?(:location_id)
53
+ info "Event URL: http://crashlog.io/locate/#{notification[:location_id]}"
54
+ else
55
+ error "No Event location ID returned. There may have been a problem processing this Event"
56
+ end
61
57
  else
62
58
  error "Failed to send event to CrashLog.io"
63
59
  log_exception(exception)
@@ -67,7 +63,7 @@ module CrashLog
67
63
 
68
64
  # Sends the notice unless it is one of the default ignored exceptions.
69
65
  def notify_or_ignore(exception, context = {})
70
- notify(exception, context = {}) unless ignored?(exception)
66
+ notify(exception, context) unless ignored?(exception)
71
67
  end
72
68
 
73
69
  # Print a message at the top of the applciation's logs to say we're ready.
@@ -94,7 +90,7 @@ module CrashLog
94
90
  if announce.eql?(true)
95
91
  report_for_duty!
96
92
  else
97
- info("Configuration updated")
93
+ debug("Configuration updated successfully")
98
94
  end
99
95
  elsif !configuration.invalid_keys.include?(:api_key)
100
96
  error("Not configured correctly. Missing the following keys: #{configuration.invalid_keys.join(', ')}")
@@ -108,6 +104,10 @@ module CrashLog
108
104
  @configuration ||= Configuration.new
109
105
  end
110
106
 
107
+ def reset_configuration!
108
+ @configuration = Configuration.new
109
+ end
110
+
111
111
  # The default logging device.
112
112
  def logger
113
113
  self.configuration.logger || Logger.new($stdout)
@@ -131,9 +131,7 @@ module CrashLog
131
131
  private
132
132
 
133
133
  def send_notification(exception, context = {})
134
- if live?
135
- build_payload(exception, context).deliver!
136
- end
134
+ build_payload(exception, context).deliver! if live?
137
135
  end
138
136
 
139
137
  def build_payload(exception, data = {})
@@ -146,3 +144,8 @@ module CrashLog
146
144
  end
147
145
  end
148
146
  end
147
+
148
+ # Require this last to resolve an issue with Rails apps that use Bundler.setup
149
+ # instead of Bundler.require which results in the CrashLog module not being made
150
+ # available in time. FIXES: https://github.com/crashlog/crashlog/issues/7
151
+ require_relative 'crash_log/railtie' if defined?(Rails::Railtie)
@@ -1,8 +1,8 @@
1
1
  module CrashLog
2
2
  class Backtrace
3
3
 
4
- autoload :Line, 'crash_log/backtrace/line'
5
- autoload :LineCache, 'crash_log/backtrace/line_cache'
4
+ require_relative 'backtrace/line'
5
+ require_relative 'backtrace/line_cache'
6
6
 
7
7
  # holder for an Array of Backtrace::Line instances
8
8
  attr_reader :lines
@@ -56,8 +56,8 @@ module CrashLog
56
56
  attr_writer :lines
57
57
 
58
58
  def self.split_multiline_backtrace(backtrace)
59
- if backtrace.to_a.size == 1
60
- backtrace.to_a.first.split(/\n\s*/)
59
+ if Array(backtrace).size == 1
60
+ Array(backtrace).first.split(/\n\s*/)
61
61
  else
62
62
  backtrace
63
63
  end
@@ -1,5 +1,7 @@
1
1
  require 'hashr'
2
2
  require 'multi_json'
3
+ require 'logger'
4
+
3
5
  module CrashLog
4
6
  class Configuration < Hashr
5
7
  DEFAULT_PARAMS_FILTERS = %w(password password_confirmation).freeze
@@ -33,10 +35,25 @@ module CrashLog
33
35
  'AbstractController::ActionNotFound',
34
36
  'Mongoid::Errors::DocumentNotFound']
35
37
 
38
+ ENVIRONMENT_FILTERS_DEFAULT = [
39
+ /SECRET/, /AWS/, /PASSWORD/, /PRIVATE/, /EC2/, /HEROKU/
40
+ ]
36
41
 
37
42
  # The logger to use for internal messages
38
43
  define :logger => nil,
39
44
 
45
+ # One of:
46
+ # - Logger::DEBUG
47
+ # - Logger::INFO
48
+ # - Logger::WARN
49
+ # - Logger::ERROR
50
+ # - Logger::FATAL
51
+ # - Logger::ANY
52
+ :level => Logger::INFO,
53
+
54
+ # Colorize log output
55
+ :colorize => true,
56
+
40
57
  # The API key to authenticate this project with CrashLog
41
58
  #
42
59
  # Get this from your projects configuration page within http://CrashLog.io
@@ -102,6 +119,11 @@ module CrashLog
102
119
  # Timeout for connecting to CrashLog collector interface
103
120
  :http_open_timeout => 5,
104
121
 
122
+ # +true+ to use whatever CAs OpenSSL has installed on your system.
123
+ # +false+ to use the ca-bundle.crt file included in CrashLog itself
124
+ # Defaut: false (reccomended)
125
+ :use_system_ssl_cert_chain => false,
126
+
105
127
  # Ignored error class names
106
128
  :ignore => IGNORE_DEFAULT.dup,
107
129
 
@@ -115,7 +137,7 @@ module CrashLog
115
137
  :context_lines => 5,
116
138
 
117
139
  # Environment variables to discard from ENV.
118
- :environment_filters => [],
140
+ :environment_filters => ENVIRONMENT_FILTERS_DEFAULT.dup,
119
141
 
120
142
  # Framework name
121
143
  :framework => 'Standalone',
@@ -134,7 +156,12 @@ module CrashLog
134
156
  :service_name => 'CrashLog',
135
157
 
136
158
  # MultiJson adapter
137
- :json_parser => MultiJson.default_adapter
159
+ :json_parser => MultiJson.default_adapter,
160
+
161
+ # Development mode
162
+ # When enabled we don't swallow internal exceptions.
163
+ # Useful for debugging connection issues.
164
+ :development_mode => false
138
165
 
139
166
  def root
140
167
  fetch(:project_root)
@@ -187,6 +214,36 @@ module CrashLog
187
214
  CrashLog::VERSION
188
215
  end
189
216
 
217
+ def development_mode?
218
+ development_mode.eql?(true)
219
+ end
220
+
221
+ def ca_bundle_path
222
+ if use_system_ssl_cert_chain? && File.exist?(OpenSSL::X509::DEFAULT_CERT_FILE)
223
+ OpenSSL::X509::DEFAULT_CERT_FILE
224
+ else
225
+ local_cert_path # ca-bundle.crt built from source, see resources/README.md
226
+ end
227
+ end
228
+
229
+ def local_cert_path
230
+ File.expand_path(File.join("../../../resources/ca-bundle.crt"), __FILE__)
231
+ end
232
+
233
+ def logger=(new_logger)
234
+ self[:logger] = new_logger
235
+ new_logger.level = self.level if self.logger.respond_to?(:level=)
236
+ end
237
+
238
+ # Helps to enable debug logging when in development mode
239
+ def development_mode=(flag)
240
+ self[:development_mode] = flag
241
+ self.level = Logger::DEBUG
242
+ if new_logger
243
+ new_logger.level = self.level if self.logger.respond_to?(:level=)
244
+ end
245
+ end
246
+
190
247
  private
191
248
 
192
249
  def error_class(exception)