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/interfaces/http.rb,
lib/raven/transports/http.rb,
lib/raven/transports/dummy.rb,
lib/raven/utils/deep_merge.rb,
lib/raven/integrations/rack.rb,
lib/raven/processor/cookies.rb,
lib/raven/integrations/rails.rb,
lib/raven/interfaces/message.rb,
lib/raven/processor/post_data.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/interfaces/single_exception.rb,
lib/raven/integrations/rails/active_job.rb,
lib/raven/processor/removecircularreferences.rb,
lib/raven/integrations/rails/controller_methods.rb,
lib/raven/integrations/rails/overrides/streaming_reporter.rb,
lib/raven/integrations/rails/overrides/debug_exceptions_catcher.rb
Overview
A much simpler source line cacher because linecache sucks at platform compat
Defined Under Namespace
Modules: OkJson, RackInterface, Transports, Utils Classes: Backtrace, CLI, Client, ClientState, Configuration, Context, Error, Event, ExceptionInterface, HttpInterface, Interface, LineCache, Logger, MessageInterface, Processor, Rack, Rails, Sidekiq, SingleExceptionInterface, StacktraceInterface
Constant Summary collapse
- AVAILABLE_INTEGRATIONS =
%w[delayed_job railties sidekiq rack rake].freeze
- VERSION =
"1.1.0".freeze
- INTERFACES =
TODO: a constant isn’t appropriate here, refactor
{}
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 = {}) ⇒ Object
Capture and process any exceptions from the given block, or globally if no block is given.
- .capture_type(obj, options = {}) ⇒ Object (also: capture_message, capture_exception)
-
.configure {|configuration| ... } ⇒ Object
Call this method to modify defaults in your initializers.
- .context ⇒ Object
-
.extra_context(options = nil) ⇒ Object
Bind extra context.
- .find_interface(name) ⇒ Object
-
.inject ⇒ Object
Injects various integrations.
- .inject_only(*only_integrations) ⇒ Object
- .inject_without(*exclude_integrations) ⇒ Object
- .last_event_id ⇒ Object
- .load_integration(integration) ⇒ Object
- .logger ⇒ Object
- .rack_context(env) ⇒ Object
- .rails_safely_prepend(module_name, opts = {}) ⇒ Object
- .register_interface(mapping) ⇒ Object
-
.report_status ⇒ Object
(also: report_ready)
Tell the log that the client is good to go.
-
.send_event(event) ⇒ Object
Send an event to the configured Sentry server.
- .should_capture?(message_or_exc) ⇒ Boolean
-
.tags_context(options = nil) ⇒ Object
Bind tags context.
-
.user_context(options = nil) ⇒ Object
Bind user context.
Class Attribute Details
.client ⇒ Object
The client object is responsible for delivering formatted data to the Sentry server.
48 49 50 |
# File 'lib/raven/base.rb', line 48 def client @client ||= Client.new(configuration) end |
.configuration ⇒ Object
The configuration object.
43 44 45 |
# File 'lib/raven/base.rb', line 43 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.
156 157 158 159 160 161 |
# File 'lib/raven/base.rb', line 156 def annotate_exception(exc, = {}) notes = (exc.instance_variable_defined?(:@__raven_context) && exc.instance_variable_get(:@__raven_context)) || {} notes.merge!() exc.instance_variable_set(:@__raven_context, notes) exc end |
.capture(options = {}) ⇒ Object
Capture and process any exceptions from the given block, or globally if no block is given
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/raven/base.rb', line 93 def capture( = {}) if block_given? begin yield rescue Error raise # Don't capture Raven errors rescue Exception => e capture_exception(e, ) raise end else install_at_exit_hook() end end |
.capture_type(obj, options = {}) ⇒ Object Also known as: capture_message, capture_exception
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/raven/base.rb', line 108 def capture_type(obj, = {}) return false unless should_capture?(obj) = obj.is_a?(String) ? "message" : "exception" if (evt = Event.send("from_" + , obj, )) yield evt if block_given? if configuration.async? configuration.async.call(evt) else send_event(evt) end Thread.current[:sentry_last_event_id] = evt.id evt end end |
.configure {|configuration| ... } ⇒ Object
Call this method to modify defaults in your initializers.
69 70 71 72 73 74 75 |
# File 'lib/raven/base.rb', line 69 def configure yield(configuration) if block_given? self.client = Client.new(configuration) report_status self.client end |
.extra_context(options = nil) ⇒ Object
Bind extra context. Merges with existing context (if any).
Extra context shows up as Additional Data within Sentry, and is completely arbitrary.
191 192 193 |
# File 'lib/raven/base.rb', line 191 def extra_context( = nil) 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. Default behavior: inject all available integrations
203 204 205 |
# File 'lib/raven/base.rb', line 203 def inject inject_only(*Raven::AVAILABLE_INTEGRATIONS) end |
.inject_only(*only_integrations) ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/raven/base.rb', line 212 def inject_only(*only_integrations) only_integrations = only_integrations.map(&:to_s) integrations_to_load = Raven::AVAILABLE_INTEGRATIONS & only_integrations not_found_integrations = only_integrations - integrations_to_load if not_found_integrations.any? self.logger.warn "Integrations do not exist: #{not_found_integrations.join ', '}" end integrations_to_load &= Gem.loaded_specs.keys # TODO(dcramer): integrations should have some additional checks baked-in # or we should break them out into their own repos. Specifically both the # rails and delayed_job checks are not always valid (i.e. Rails 2.3) and # https://github.com/getsentry/raven-ruby/issues/180 integrations_to_load.each do |integration| load_integration(integration) end end |
.inject_without(*exclude_integrations) ⇒ Object
207 208 209 210 |
# File 'lib/raven/base.rb', line 207 def inject_without(*exclude_integrations) include_integrations = Raven::AVAILABLE_INTEGRATIONS - exclude_integrations.map(&:to_s) inject_only(*include_integrations) end |
.last_event_id ⇒ Object
125 126 127 |
# File 'lib/raven/base.rb', line 125 def last_event_id Thread.current[:sentry_last_event_id] end |
.load_integration(integration) ⇒ Object
229 230 231 232 233 |
# File 'lib/raven/base.rb', line 229 def load_integration(integration) require "raven/integrations/#{integration}" rescue Exception => error self.logger.warn "Unable to load raven/integrations/#{integration}: #{error}" end |
.logger ⇒ Object
37 38 39 |
# File 'lib/raven/base.rb', line 37 def logger @logger ||= Logger.new end |
.rack_context(env) ⇒ Object
195 196 197 198 199 200 |
# File 'lib/raven/base.rb', line 195 def rack_context(env) if env.empty? env = nil end self.context.rack_env = env end |
.rails_safely_prepend(module_name, opts = {}) ⇒ Object
235 236 237 238 239 240 241 242 |
# File 'lib/raven/base.rb', line 235 def rails_safely_prepend(module_name, opts = {}) return if opts[:to].nil? if opts[:to].respond_to?(:prepend, true) opts[:to].send(:prepend, Raven::Rails::Overrides.const_get(module_name)) else opts[:to].send(:include, Raven::Rails::Overrides.const_get("Old" + module_name)) end 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_status ⇒ Object Also known as: report_ready
Tell the log that the client is good to go
53 54 55 56 57 58 59 60 |
# File 'lib/raven/base.rb', line 53 def report_status return if client.configuration.silence_ready if client.configuration.send_in_current_environment? logger.info "Raven #{VERSION} ready to catch errors" else logger.info "Raven #{VERSION} configured not to send errors." end end |
.send_event(event) ⇒ Object
Send an event to the configured Sentry server
82 83 84 |
# File 'lib/raven/base.rb', line 82 def send_event(event) client.send_event(event) end |
.should_capture?(message_or_exc) ⇒ Boolean
129 130 131 132 133 134 135 |
# File 'lib/raven/base.rb', line 129 def should_capture?() if configuration.should_capture configuration.should_capture.call(*[]) else true end end |
.tags_context(options = nil) ⇒ 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.
181 182 183 |
# File 'lib/raven/base.rb', line 181 def ( = nil) self.context..merge!( || {}) end |
.user_context(options = nil) ⇒ 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.
170 171 172 |
# File 'lib/raven/base.rb', line 170 def user_context( = nil) self.context.user = || {} end |