Module: Raven
- Defined in:
- lib/raven/okjson.rb,
lib/raven/cli.rb,
lib/raven/base.rb,
lib/raven/error.rb,
lib/raven/event.rb,
lib/raven/client.rb,
lib/raven/logger.rb,
lib/raven/context.rb,
lib/raven/version.rb,
lib/raven/backtrace.rb,
lib/raven/linecache.rb,
lib/raven/processor.rb,
lib/raven/interfaces.rb,
lib/raven/transports.rb,
lib/raven/configuration.rb,
lib/raven/transports/udp.rb,
lib/raven/interfaces/http.rb,
lib/raven/transports/http.rb,
lib/raven/integrations/rack.rb,
lib/raven/integrations/rails.rb,
lib/raven/interfaces/message.rb,
lib/raven/better_attr_accessor.rb,
lib/raven/integrations/sidekiq.rb,
lib/raven/interfaces/exception.rb,
lib/raven/interfaces/stack_trace.rb,
lib/raven/processor/sanitizedata.rb,
lib/raven/processor/utf8conversion.rb,
lib/raven/processor/removestacktrace.rb,
lib/raven/processor/removecircularreferences.rb,
lib/raven/integrations/rails/controller_methods.rb,
lib/raven/integrations/rails/middleware/debug_exceptions_catcher.rb
Overview
A much simpler source line cacher because linecache sucks at platform compat
Defined Under Namespace
Modules: BetterAttrAccessor, OkJson, Transports Classes: Backtrace, CLI, Client, Configuration, Context, Error, Event, ExceptionInterface, HttpInterface, Interface, LineCache, Logger, MessageInterface, Processor, Rack, Rails, Sidekiq, StacktraceInterface
Constant Summary collapse
- VERSION =
"0.12.2"
- INTERFACES =
{}
Class Attribute Summary collapse
-
.client ⇒ Object
The client object is responsible for delivering formatted data to the Sentry server.
-
.configuration ⇒ Object
The configuration object.
Class Method Summary collapse
-
.annotate_exception(exc, options = {}) ⇒ Object
(also: annotateException, annotate)
Provides extra context to the exception prior to it being handled by Raven.
-
.capture(options = {}, &block) ⇒ Object
Capture and process any exceptions from the given block, or globally if no block is given.
- .capture_exception(exception, options = {}) ⇒ Object (also: captureException)
- .capture_message(message, options = {}) ⇒ Object (also: captureMessage)
-
.configure(silent = false) {|configuration| ... } ⇒ Object
Call this method to modify defaults in your initializers.
- .context ⇒ Object
-
.extra_context(options = {}) ⇒ Object
Bind extra context.
- .find_interface(name) ⇒ Object
-
.inject ⇒ Object
Injects various integrations.
- .logger ⇒ Object
- .rack_context(env) ⇒ Object
- .register_interface(mapping) ⇒ Object
-
.report_ready ⇒ Object
Tell the log that the client is good to go.
-
.send(evt) ⇒ Object
Send an event to the configured Sentry server.
- .send_or_skip(exc) ⇒ Object
-
.tags_context(options = {}) ⇒ Object
Bind tags context.
-
.user_context(options = {}) ⇒ Object
Bind user context.
Class Attribute Details
.client ⇒ Object
The client object is responsible for delivering formatted data to the Sentry server.
42 43 44 |
# File 'lib/raven/base.rb', line 42 def client @client ||= Client.new(configuration) end |
.configuration ⇒ Object
The configuration object.
37 38 39 |
# File 'lib/raven/base.rb', line 37 def configuration @configuration ||= Configuration.new end |
Class Method Details
.annotate_exception(exc, options = {}) ⇒ Object Also known as: annotateException, annotate
Provides extra context to the exception prior to it being handled by Raven. An exception can have multiple annotations, which are merged together.
The options (annotation) is treated the same as the “options“ parameter to “capture_exception“ or “Event.from_exception“, and can contain the same “:user“, “:tags“, etc. options as these methods.
These will be merged with the “options“ parameter to “Event.from_exception“ at the top of execution.
161 162 163 164 165 166 |
# File 'lib/raven/base.rb', line 161 def annotate_exception(exc, = {}) notes = exc.instance_variable_get(:@__raven_context) || {} notes.merge!() exc.instance_variable_set(:@__raven_context, notes) exc end |
.capture(options = {}, &block) ⇒ Object
Capture and process any exceptions from the given block, or globally if no block is given
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/raven/base.rb', line 81 def capture( = {}, &block) if block begin block.call rescue Error raise # Don't capture Raven errors rescue Exception => e capture_exception(e, ) raise end else # Install at_exit hook at_exit do if $ERROR_INFO logger.debug "Caught a post-mortem exception: #{$ERROR_INFO.inspect}" capture_exception($ERROR_INFO, ) end end end end |
.capture_exception(exception, options = {}) ⇒ Object Also known as: captureException
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/raven/base.rb', line 102 def capture_exception(exception, = {}) send_or_skip(exception) do if evt = Event.from_exception(exception, ) yield evt if block_given? if configuration.async? configuration.async.call(evt) else send(evt) end end end end |
.capture_message(message, options = {}) ⇒ Object Also known as: captureMessage
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/raven/base.rb', line 115 def (, = {}) send_or_skip() do if evt = Event.(, ) yield evt if block_given? if configuration.async? configuration.async.call(evt) else send(evt) end end end end |
.configure(silent = false) {|configuration| ... } ⇒ Object
Call this method to modify defaults in your initializers.
57 58 59 60 61 62 63 |
# File 'lib/raven/base.rb', line 57 def configure(silent = false) yield(configuration) if block_given? self.client = Client.new(configuration) report_ready unless silent self.client end |
.extra_context(options = {}) ⇒ Object
Bind extra context. Merges with existing context (if any).
Extra context shows up as Additional Data within Sentry, and is completely arbitrary.
196 197 198 |
# File 'lib/raven/base.rb', line 196 def extra_context( = {}) self.context.extra.merge!() end |
.find_interface(name) ⇒ Object
31 32 33 |
# File 'lib/raven/interfaces.rb', line 31 def self.find_interface(name) INTERFACES[name.to_s] end |
.inject ⇒ Object
Injects various integrations
208 209 210 211 212 |
# File 'lib/raven/base.rb', line 208 def inject available_integrations = %w[delayed_job rails sidekiq rack rake] integrations_to_load = available_integrations & Gem.loaded_specs.keys integrations_to_load.each { |integration| require "raven/integrations/#{integration}" } end |
.logger ⇒ Object
31 32 33 |
# File 'lib/raven/base.rb', line 31 def logger @logger ||= Logger.new end |
.rack_context(env) ⇒ Object
200 201 202 203 204 205 |
# File 'lib/raven/base.rb', line 200 def rack_context(env) if env.empty? env = nil end self.context.rack_env = env end |
.register_interface(mapping) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/raven/interfaces.rb', line 24 def self.register_interface(mapping) mapping.each_pair do |key, klass| INTERFACES[key.to_s] = klass INTERFACES[klass.name] = klass end end |
.report_ready ⇒ Object
Tell the log that the client is good to go
47 48 49 |
# File 'lib/raven/base.rb', line 47 def report_ready self.logger.info "Raven #{VERSION} ready to catch errors" end |
.send(evt) ⇒ Object
Send an event to the configured Sentry server
70 71 72 |
# File 'lib/raven/base.rb', line 70 def send(evt) client.send(evt) end |
.send_or_skip(exc) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/raven/base.rb', line 128 def send_or_skip(exc) should_send = if configuration.should_send configuration.should_send.call(*[exc]) else true end if configuration.send_in_current_environment? && should_send yield if block_given? else configuration. end end |
.tags_context(options = {}) ⇒ Object
Bind tags context. Merges with existing context (if any).
Tags are key / value pairs which generally represent things like application version, environment, role, and server names.
186 187 188 |
# File 'lib/raven/base.rb', line 186 def ( = {}) self.context..merge!() end |
.user_context(options = {}) ⇒ Object
Bind user context. Merges with existing context (if any).
It is recommending that you send at least the “id“ and “email“ values. All other values are arbitrary.
175 176 177 |
# File 'lib/raven/base.rb', line 175 def user_context( = {}) self.context.user = end |