sentry-raven 2.1.3 → 3.1.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.
Files changed (66) hide show
  1. checksums.yaml +5 -5
  2. data/.craft.yml +19 -0
  3. data/.scripts/bump-version.rb +5 -0
  4. data/CHANGELOG.md +703 -0
  5. data/Gemfile +37 -0
  6. data/Makefile +3 -0
  7. data/README.md +116 -18
  8. data/Rakefile +30 -0
  9. data/exe/raven +32 -0
  10. data/lib/raven/backtrace.rb +16 -6
  11. data/lib/raven/base.rb +17 -4
  12. data/lib/raven/breadcrumbs/{activesupport.rb → active_support_logger.rb} +9 -3
  13. data/lib/raven/breadcrumbs/logger.rb +2 -92
  14. data/lib/raven/breadcrumbs/sentry_logger.rb +73 -0
  15. data/lib/raven/breadcrumbs.rb +3 -1
  16. data/lib/raven/cli.rb +31 -43
  17. data/lib/raven/client.rb +39 -17
  18. data/lib/raven/configuration.rb +277 -37
  19. data/lib/raven/context.rb +17 -11
  20. data/lib/raven/core_ext/object/deep_dup.rb +57 -0
  21. data/lib/raven/core_ext/object/duplicable.rb +153 -0
  22. data/lib/raven/event.rb +172 -233
  23. data/lib/raven/helpers/deprecation_helper.rb +17 -0
  24. data/lib/raven/instance.rb +51 -25
  25. data/lib/raven/integrations/delayed_job.rb +18 -18
  26. data/lib/raven/integrations/rack-timeout.rb +11 -5
  27. data/lib/raven/integrations/rack.rb +36 -19
  28. data/lib/raven/integrations/rails/active_job.rb +52 -20
  29. data/lib/raven/integrations/rails/backtrace_cleaner.rb +29 -0
  30. data/lib/raven/integrations/rails/controller_transaction.rb +13 -0
  31. data/lib/raven/integrations/rails/overrides/debug_exceptions_catcher.rb +2 -2
  32. data/lib/raven/integrations/rails.rb +24 -8
  33. data/lib/raven/integrations/rake.rb +6 -1
  34. data/lib/raven/integrations/sidekiq/cleanup_middleware.rb +13 -0
  35. data/lib/raven/integrations/sidekiq/error_handler.rb +38 -0
  36. data/lib/raven/integrations/sidekiq.rb +6 -57
  37. data/lib/raven/interface.rb +2 -2
  38. data/lib/raven/interfaces/exception.rb +0 -2
  39. data/lib/raven/interfaces/http.rb +0 -2
  40. data/lib/raven/interfaces/message.rb +1 -1
  41. data/lib/raven/interfaces/single_exception.rb +0 -2
  42. data/lib/raven/interfaces/stack_trace.rb +19 -27
  43. data/lib/raven/linecache.rb +34 -17
  44. data/lib/raven/logger.rb +11 -18
  45. data/lib/raven/processor/cookies.rb +27 -7
  46. data/lib/raven/processor/http_headers.rb +18 -5
  47. data/lib/raven/processor/post_data.rb +16 -3
  48. data/lib/raven/processor/removecircularreferences.rb +12 -8
  49. data/lib/raven/processor/removestacktrace.rb +17 -6
  50. data/lib/raven/processor/sanitizedata.rb +88 -29
  51. data/lib/raven/processor/utf8conversion.rb +39 -14
  52. data/lib/raven/processor.rb +1 -1
  53. data/lib/raven/transports/http.rb +29 -21
  54. data/lib/raven/transports/stdout.rb +20 -0
  55. data/lib/raven/transports.rb +4 -8
  56. data/lib/raven/utils/context_filter.rb +42 -0
  57. data/lib/raven/utils/deep_merge.rb +6 -12
  58. data/lib/raven/utils/exception_cause_chain.rb +20 -0
  59. data/lib/raven/utils/real_ip.rb +1 -1
  60. data/lib/raven/utils/request_id.rb +16 -0
  61. data/lib/raven/version.rb +2 -2
  62. data/lib/sentry-raven-without-integrations.rb +6 -1
  63. data/lib/sentry_raven_without_integrations.rb +1 -0
  64. data/sentry-raven.gemspec +28 -0
  65. metadata +37 -103
  66. data/lib/raven/error.rb +0 -4
data/lib/raven/cli.rb CHANGED
@@ -1,60 +1,48 @@
1
1
  module Raven
2
2
  class CLI
3
- def self.test(dsn = nil, silent = false) # rubocop:disable all
4
- if silent
5
- Raven.configuration.logger = ::Logger.new(nil)
6
- else
7
- logger = ::Logger.new(STDOUT)
8
- logger.level = ::Logger::ERROR
9
- logger.formatter = proc do |_severity, _datetime, _progname, msg|
10
- "-> #{msg}\n"
11
- end
12
-
13
- Raven.configuration.logger = logger
14
- end
15
-
16
- Raven.configuration.timeout = 5
17
- Raven.configuration.dsn = dsn if dsn
3
+ def self.test(dsn = nil, silent = false, config = nil)
4
+ config ||= Raven.configuration
5
+
6
+ config.logger = if silent
7
+ ::Logger.new(nil)
8
+ else
9
+ logger = ::Logger.new(STDOUT)
10
+ logger.formatter = proc do |_severity, _datetime, _progname, msg|
11
+ "-> #{msg}\n"
12
+ end
13
+ logger
14
+ end
15
+
16
+ config.timeout = 5
17
+ config.dsn = dsn if dsn
18
18
 
19
19
  # wipe out env settings to ensure we send the event
20
- unless Raven.configuration.capture_allowed?
21
- env_name = Raven.configuration.environments.pop || 'production'
22
- Raven.logger.debug "Setting environment to #{env_name}"
23
- Raven.configuration.current_environment = env_name
20
+ unless config.capture_allowed?
21
+ env_name = config.environments.last || 'production'
22
+ config.current_environment = env_name
24
23
  end
25
24
 
26
- Raven.configuration.verify!
25
+ instance = Raven::Instance.new(nil, config)
27
26
 
28
- Raven.logger.debug "Sending a test event:"
29
- Raven.logger.debug ""
27
+ instance.logger.debug "Sending a test event:"
28
+ instance.logger.debug ""
30
29
 
31
30
  begin
32
31
  1 / 0
33
- rescue ZeroDivisionError => exception
34
- evt = Raven.capture_exception(exception)
32
+ rescue ZeroDivisionError => e
33
+ evt = instance.capture_exception(e)
35
34
  end
36
35
 
37
- if evt && !(evt.is_a? Thread)
38
- if evt.is_a? Hash
39
- Raven.logger.debug "-> event ID: #{evt[:event_id]}"
40
- else
41
- Raven.logger.debug "-> event ID: #{evt.id}"
42
- end
43
- elsif evt # async configuration
44
- if evt.value.is_a? Hash
45
- Raven.logger.debug "-> event ID: #{evt.value[:event_id]}"
46
- else
47
- Raven.logger.debug "-> event ID: #{evt.value.id}"
48
- end
36
+ if evt
37
+ instance.logger.debug "-> event ID: #{evt.id}"
38
+ instance.logger.debug ""
39
+ instance.logger.debug "Done!"
40
+ evt
49
41
  else
50
- Raven.logger.debug ""
51
- Raven.logger.debug "An error occurred while attempting to send the event."
52
- exit 1
42
+ instance.logger.debug ""
43
+ instance.logger.debug "An error occurred while attempting to send the event."
44
+ false
53
45
  end
54
-
55
- Raven.logger.debug ""
56
- Raven.logger.debug "Done!"
57
- true
58
46
  end
59
47
  end
60
48
  end
data/lib/raven/client.rb CHANGED
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'base64'
3
4
  require 'json'
4
5
  require 'zlib'
5
6
 
6
- require 'raven/version'
7
- require 'raven/transports/http'
7
+ require "raven/transports"
8
8
 
9
9
  module Raven
10
10
  # Encodes events and sends them to the Sentry server.
11
11
  class Client
12
- PROTOCOL_VERSION = '5'.freeze
13
- USER_AGENT = "raven-ruby/#{Raven::VERSION}".freeze
14
- CONTENT_TYPE = 'application/json'.freeze
12
+ PROTOCOL_VERSION = '5'
13
+ USER_AGENT = "raven-ruby/#{Raven::VERSION}"
14
+ CONTENT_TYPE = 'application/json'
15
15
 
16
16
  attr_accessor :configuration
17
17
 
@@ -21,9 +21,15 @@ module Raven
21
21
  @state = ClientState.new
22
22
  end
23
23
 
24
- def send_event(event)
24
+ def send_event(event, hint = nil)
25
25
  return false unless configuration.sending_allowed?(event)
26
26
 
27
+ event = configuration.before_send.call(event, hint) if configuration.before_send
28
+ if event.nil?
29
+ configuration.logger.info "Discarded event because before_send returned nil"
30
+ return
31
+ end
32
+
27
33
  # Convert to hash
28
34
  event = event.to_hash
29
35
 
@@ -32,7 +38,8 @@ module Raven
32
38
  return
33
39
  end
34
40
 
35
- Raven.logger.debug "Sending event #{event[:event_id]} to Sentry"
41
+ event_id = event[:event_id] || event['event_id']
42
+ configuration.logger.info "Sending event #{event_id} to Sentry"
36
43
 
37
44
  content_type, encoded_data = encode(event)
38
45
 
@@ -53,6 +60,8 @@ module Raven
53
60
  case configuration.scheme
54
61
  when 'http', 'https'
55
62
  Transports::HTTP.new(configuration)
63
+ when 'stdout'
64
+ Transports::Stdout.new(configuration)
56
65
  when 'dummy'
57
66
  Transports::Dummy.new(configuration)
58
67
  else
@@ -64,7 +73,7 @@ module Raven
64
73
 
65
74
  def encode(event)
66
75
  hash = @processors.reduce(event.to_hash) { |a, e| e.process(a) }
67
- encoded = JSON.generate(hash)
76
+ encoded = JSON.fast_generate(hash)
68
77
 
69
78
  case configuration.encoding
70
79
  when 'gzip'
@@ -74,8 +83,20 @@ module Raven
74
83
  end
75
84
  end
76
85
 
86
+ def get_message_from_exception(event)
87
+ (
88
+ event &&
89
+ event[:exception] &&
90
+ event[:exception][:values] &&
91
+ event[:exception][:values][0] &&
92
+ event[:exception][:values][0][:type] &&
93
+ event[:exception][:values][0][:value] &&
94
+ "#{event[:exception][:values][0][:type]}: #{event[:exception][:values][0][:value]}"
95
+ )
96
+ end
97
+
77
98
  def get_log_message(event)
78
- (event && event[:message]) || '<no message value>'
99
+ (event && event[:message]) || (event && event['message']) || get_message_from_exception(event) || '<no message value>'
79
100
  end
80
101
 
81
102
  def generate_auth_header
@@ -84,9 +105,9 @@ module Raven
84
105
  'sentry_version' => PROTOCOL_VERSION,
85
106
  'sentry_client' => USER_AGENT,
86
107
  'sentry_timestamp' => now,
87
- 'sentry_key' => configuration.public_key,
88
- 'sentry_secret' => configuration.secret_key
108
+ 'sentry_key' => configuration.public_key
89
109
  }
110
+ fields['sentry_secret'] = configuration.secret_key unless configuration.secret_key.nil?
90
111
  'Sentry ' + fields.map { |key, value| "#{key}=#{value}" }.join(', ')
91
112
  end
92
113
 
@@ -95,15 +116,16 @@ module Raven
95
116
  end
96
117
 
97
118
  def failed_send(e, event)
98
- @state.failure
99
119
  if e # exception was raised
100
- Raven.logger.error "Unable to record event with remote Sentry server (#{e.class} - #{e.message})"
101
- e.backtrace[0..10].each { |line| Raven.logger.error(line) }
120
+ @state.failure
121
+ configuration.logger.warn "Unable to record event with remote Sentry server (#{e.class} - #{e.message}):\n#{e.backtrace[0..10].join("\n")}"
102
122
  else
103
- Raven.logger.error "Not sending event due to previous failure(s)."
123
+ configuration.logger.warn "Not sending event due to previous failure(s)."
104
124
  end
105
- Raven.logger.error("Failed to submit event: #{get_log_message(event)}")
106
- configuration.transport_failure_callback.call(event) if configuration.transport_failure_callback
125
+ configuration.logger.warn("Failed to submit event: #{get_log_message(event)}")
126
+
127
+ # configuration.transport_failure_callback can be false & nil
128
+ configuration.transport_failure_callback.call(event, e) if configuration.transport_failure_callback # rubocop:disable Style/SafeNavigation
107
129
  end
108
130
  end
109
131