Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ If you want to report a message rather than an exception you can use the

Raven.capture_message("Something went very wrong")

Referencing Events
------------------

The client exposes a ``last_event_id`` accessor allowing you to easily
reference the last captured event. This is useful, for example, if you wanted
to show the user a reference on your error page::

.. code-block:: ruby

# somewhere deep in the stack
Raven.capture do
1 / 0
end

Now you can easily expose this to your error handler:

.. code-block:: ruby

class ErrorsController < ApplicationController
def internal_server_error
render(:status => 500, :sentry_event_id => Raven.last_event_id)
end
end

Optional Attributes
-------------------

Expand Down
6 changes: 5 additions & 1 deletion lib/raven/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,17 @@ def capture_type(obj, options = {})
else
send_event(evt)
end

Thread.current[:sentry_last_event_id] = evt.id
evt
end
end
alias_method :capture_message, :capture_type
alias_method :capture_exception, :capture_type

def last_event_id
Thread.current[:sentry_last_event_id]
end

def should_capture?(message_or_exc)
if configuration.should_capture
configuration.should_capture.call(*[message_or_exc])
Expand Down
18 changes: 17 additions & 1 deletion spec/raven/raven_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Raven do
let(:event) { double("event") }
let(:event) { double("event", :id => "event_id") }
let(:options) { double("options") }

before do
Expand Down Expand Up @@ -245,4 +245,20 @@ def ivars(object)
Raven.inject_without(:delayed_job, :railties, :sidekiq, :rack)
end
end

describe '.last_event_id' do
let(:message) { "Test message" }

it 'sends the result of Event.capture_message' do
expect(Raven).to receive(:send_event).with(event)

Raven.capture_message("Test message", options)

expect(Raven.last_event_id).to eq(event.id)
end

it 'yields the event to a passed block' do
expect { |b| Raven.capture_message(message, options, &b) }.to yield_with_args(event)
end
end
end