Sha256: df7e310588c6c9b124eb97590dda929ba3678ca6b193fadd10791fff270f7592

Contents?: true

Size: 1.94 KB

Versions: 7

Compression:

Stored size: 1.94 KB

Contents

Ruby on Rails
=============

In Rails, all uncaught exceptions will be automatically reported.

We support Rails 3 and newer.

Installation
------------

Install the SDK via Rubygems by adding it to your ``Gemfile``:

.. sourcecode:: ruby

    gem "sentry-raven"

Configuration
-------------

Open up ``config/application.rb`` and configure the DSN, and any other :doc:`settings <../config>`
you need:

.. sourcecode:: ruby

    Raven.configure do |config|
      config.dsn = '___DSN___'
    end

If you have added items to `Rails' log filtering
<http://guides.rubyonrails.org/action_controller_overview.html#parameters-filtering>`_,
you can also make sure that those items are not sent to Sentry:

.. sourcecode:: ruby

    # in your application.rb:
    config.filter_parameters << :password

    # in an initializer, like sentry.rb
    Raven.configure do |config|
      config.sanitize_fields = Rails.application.config.filter_parameters.map(&:to_s)
    end

Params and sessions
-------------------

.. sourcecode:: ruby

  class ApplicationController < ActionController::Base
    before_action :set_raven_context

    private

    def set_raven_context
      Raven.user_context(id: session[:current_user_id]) # or anything else in session
      Raven.extra_context(params: params.to_unsafe_h, url: request.url)
    end
  end

Authlogic
---------

When using Authlogic for authentication, you can provide user context by
binding to session ``after_persisting`` and ``after_destroy`` events in
``user_session.rb``:

.. sourcecode:: ruby

    class UserSession < Authlogic::Session::Base
      # events binding
      after_persisting :raven_set_user_context
      after_destroy :raven_clear_user_context

      def raven_set_user_context
        Raven.user_context({
          'id' => self.user.id,
          'email' => self.user.email,
          'username' => self.user.username
        })
      end

      def raven_clear_user_context
        Raven.user_context({})
      end
    end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sentry-raven-2.7.1 docs/integrations/rails.rst
sentry-raven-2.6.3 docs/integrations/rails.rst
sentry-raven-2.6.2 docs/integrations/rails.rst
sentry-raven-2.6.1 docs/integrations/rails.rst
sentry-raven-2.6.0 docs/integrations/rails.rst
sentry-raven-2.5.3 docs/integrations/rails.rst
sentry-raven-2.5.2 docs/integrations/rails.rst