class Raven::Instance

Overview

A copy of Raven's base module class methods, minus some of the integration and global hooks since it's meant to be used explicitly. Useful for sending errors to multiple sentry projects in a large application.

class Foo
  def initialize
    @other_raven = Raven::Instance.new
    @other_raven.configure do |config|
      config.dsn = "http://..."
    end
  end

  def foo
    # ...


  rescue ex
    @other_raven.capture(ex)
  end
end

Defined in:

raven/instance.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(context = nil, config : Nil | Raven::Configuration = nil) #

[View source]

Instance Method Detail

def annotate_exception(ex : Exception, **options) #

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 or Event.from, and can contain the same :user, :tags, etc. options as these methods.

These will be merged with the options parameter to Event.from at the top of execution.

begin
  raise "Hello"
rescue ex
  Raven.annotate_exception(ex, user: {id: 1, email: "foo@example.com"})
  raise ex
end

[View source]
def breadcrumbs #

[View source]
def capture(klass : String, message : String, backtrace : String | Nil = nil, **options, &) #

Captures an exception with given klass, message and optional backtrace.

Raven.capture "FooBarError", "Foo got bar!"

NOTE Useful in scenarios where you need to reconstruct the error (usually along with a backtrace from external source), while having no access to the actual Exception object.


[View source]
def capture(obj : Exception | String, **options, &) #

Captures given Exception or String object and yields created Raven::Event before sending to Sentry.

Raven.capture("boo!") do |event|
  event.extra.merge! foo: "bar"
end

[View source]
def capture(obj : Exception | String, **options) #

Captures given Exception or String object.

begin
  # ...
rescue ex
  Raven.capture ex
end

Raven.capture "boo!"

[View source]
def capture(**options, &) #

Capture and process any exceptions from the given block.

Raven.capture do
  MyApp.run
end

[View source]
def captured_exception?(ex : Exception) #

Returns true in case given ex was already captured, false otherwise.

ex = Exception.new("boo!")

Raven.captured_exception?(ex) # => false
Raven.capture(ex)
Raven.captured_exception?(ex) # => true

[View source]
def client : Client #

The client object is responsible for delivering formatted data to the Sentry server.


[View source]
def client=(client : Client) #

The client object is responsible for delivering formatted data to the Sentry server.


[View source]
def configuration : Configuration #

[View source]
def configuration=(configuration : Configuration) #

[View source]
def configure #

Call this method to modify defaults in your initializers.

Raven.configure do |config|
  config.dsn = "http://..."
end

[View source]
def configure(&) #

Call this method to modify defaults in your initializers.

Raven.configure do |config|
  config.dsn = "http://..."
end

[View source]
def context #

[View source]
def extra_context(hash = nil, **options) #

Bind extra context. Merges with existing context (if any).

Extra context shows up as Additional Data within Sentry, and is completely arbitrary.

Raven.extra_context(my_custom_data: "value")

[View source]
def extra_context(hash = nil, **options, &) #

Bind extra context. Merges with existing context (if any).

See #extra_context


[View source]
def last_event_id #

[View source]
def report_status #

Tell the log that the client is good to go.


[View source]
def send_event(event, hint = nil) #

Send an event to the configured Sentry server.

event = Raven::Event.new(message: "An error")
Raven.send_event(event)

[View source]
def send_feedback(event_id : String, data : Hash) #

Sends User Feedback to Sentry server.

data should be a Hash(String, String) with following keys:

  • name (populated from context.user[:username] if left empty)
  • email (populated from context.user[:email] if left empty)
  • comments
Raven.send_feedback(Raven.last_event_id, {
  "name"     => "...",
  "email"    => "...",
  "comments" => "...",
})

NOTE Sentry server records single (last) feedback for a given event_id.


[View source]
def tags_context(hash = nil, **options) #

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.

Raven.tags_context(my_custom_tag: "tag_value")

[View source]
def tags_context(hash = nil, **options, &) #

Bind tags context. Merges with existing context (if any).

See #tags_context


[View source]
def user_context(hash = nil, **options) #

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.

Raven.user_context(id: 1, email: "foo@example.com")

[View source]
def user_context(hash = nil, **options, &) #

Bind user context. Merges with existing context (if any).

See #user_context


[View source]