ruby-rails.json 8.3 KB

123456
  1. {
  2. "html": "<div class=\"section\" id=\"ruby-on-rails\">\n<h2>Ruby on Rails</h2>\n<p>In Rails, all uncaught exceptions will be automatically reported.</p>\n<p>We support Rails 3 and newer.</p>\n<div class=\"section\" id=\"installation\">\n<h3>Installation</h3>\n<p>Install the SDK via Rubygems by adding it to your <code class=\"docutils literal\"><span class=\"pre\">Gemfile</span></code>:</p>\n<div class=\"highlight-ruby\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">gem</span> <span style=\"color: #e8535a\">&quot;sentry-raven&quot;</span>\n</pre></div>\n</div>\n</div>\n<div class=\"section\" id=\"configuration\">\n<h3>Configuration</h3>\n<p>Open up <code class=\"docutils literal\"><span class=\"pre\">config/application.rb</span></code> and configure the DSN, and any other <a class=\"reference internal\" href=\"https://docs.getsentry.com/clients/ruby/config/\"><em>settings</em></a>\nyou need:</p>\n<div class=\"highlight-ruby\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">Raven</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">configure</span> <span style=\"color: #2eb0f7\">do</span> <span style=\"color: #4b4f5c\">|</span><span style=\"color: #111111\">config</span><span style=\"color: #4b4f5c\">|</span>\n <span style=\"color: #111111\">config</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">dsn</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #e8535a\">&#39;___DSN___&#39;</span>\n<span style=\"color: #2eb0f7\">end</span>\n</pre></div>\n</div>\n<p>If you have added items to <a class=\"reference external\" href=\"http://guides.rubyonrails.org/action_controller_overview.html#parameters-filtering\">Rails&#8217; log filtering</a>,\nyou can also make sure that those items are not sent to Sentry:</p>\n<div class=\"highlight-ruby\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #34c08b; font-style: italic\"># in your application.rb:</span>\n<span style=\"color: #111111\">config</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">filter_parameters</span> <span style=\"color: #4b4f5c\">&lt;&lt;</span> <span style=\"color: #e8535a\">:password</span>\n\n<span style=\"color: #34c08b; font-style: italic\"># in an initializer, like sentry.rb</span>\n<span style=\"color: #111111\">Raven</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">configure</span> <span style=\"color: #2eb0f7\">do</span> <span style=\"color: #4b4f5c\">|</span><span style=\"color: #111111\">config</span><span style=\"color: #4b4f5c\">|</span>\n <span style=\"color: #111111\">config</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">sanitize_fields</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #111111\">Rails</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">application</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">config</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">filter_parameters</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">map(</span><span style=\"color: #4b4f5c\">&amp;</span><span style=\"color: #e8535a\">:to_s</span><span style=\"color: #111111\">)</span>\n<span style=\"color: #2eb0f7\">end</span>\n</pre></div>\n</div>\n</div>\n<div class=\"section\" id=\"params-and-sessions\">\n<h3>Params and sessions</h3>\n<div class=\"highlight-ruby\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">class</span> <span style=\"color: #111111\">ApplicationController</span> <span style=\"color: #4b4f5c\">&lt;</span> <span style=\"color: #111111\">ActionController</span><span style=\"color: #4b4f5c\">::</span><span style=\"color: #111111\">Base</span>\n <span style=\"color: #111111\">before_action</span> <span style=\"color: #e8535a\">:set_raven_context</span>\n\n <span style=\"color: #2eb0f7\">private</span>\n\n <span style=\"color: #2eb0f7\">def</span> <span style=\"color: #111111\">set_raven_context</span>\n <span style=\"color: #111111\">Raven</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">user_context(</span><span style=\"color: #2eb0f7\">id</span><span style=\"color: #111111\">:</span> <span style=\"color: #111111\">session</span><span style=\"color: #4b4f5c\">[</span><span style=\"color: #e8535a\">:current_user_id</span><span style=\"color: #4b4f5c\">]</span><span style=\"color: #111111\">)</span> <span style=\"color: #34c08b; font-style: italic\"># or anything else in session</span>\n <span style=\"color: #111111\">Raven</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">extra_context(</span><span style=\"color: #e8535a\">params</span><span style=\"color: #111111\">:</span> <span style=\"color: #111111\">params</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">to_unsafe_h,</span> <span style=\"color: #e8535a\">url</span><span style=\"color: #111111\">:</span> <span style=\"color: #111111\">request</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">url)</span>\n <span style=\"color: #2eb0f7\">end</span>\n<span style=\"color: #2eb0f7\">end</span>\n</pre></div>\n</div>\n</div>\n<div class=\"section\" id=\"authlogic\">\n<h3>Authlogic</h3>\n<p>When using Authlogic for authentication, you can provide user context by\nbinding to session <code class=\"docutils literal\"><span class=\"pre\">after_persisting</span></code> and <code class=\"docutils literal\"><span class=\"pre\">after_destroy</span></code> events in\n<code class=\"docutils literal\"><span class=\"pre\">user_session.rb</span></code>:</p>\n<div class=\"highlight-ruby\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">class</span> <span style=\"color: #111111\">UserSession</span> <span style=\"color: #4b4f5c\">&lt;</span> <span style=\"color: #111111\">Authlogic</span><span style=\"color: #4b4f5c\">::</span><span style=\"color: #111111\">Session</span><span style=\"color: #4b4f5c\">::</span><span style=\"color: #111111\">Base</span>\n <span style=\"color: #34c08b; font-style: italic\"># events binding</span>\n <span style=\"color: #111111\">after_persisting</span> <span style=\"color: #e8535a\">:raven_set_user_context</span>\n <span style=\"color: #111111\">after_destroy</span> <span style=\"color: #e8535a\">:raven_clear_user_context</span>\n\n <span style=\"color: #2eb0f7\">def</span> <span style=\"color: #111111\">raven_set_user_context</span>\n <span style=\"color: #111111\">Raven</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">user_context({</span>\n <span style=\"color: #e8535a\">&#39;id&#39;</span> <span style=\"color: #4b4f5c\">=&gt;</span> <span style=\"color: #2eb0f7\">self</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">user</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">id,</span>\n <span style=\"color: #e8535a\">&#39;email&#39;</span> <span style=\"color: #4b4f5c\">=&gt;</span> <span style=\"color: #2eb0f7\">self</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">user</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">email,</span>\n <span style=\"color: #e8535a\">&#39;username&#39;</span> <span style=\"color: #4b4f5c\">=&gt;</span> <span style=\"color: #2eb0f7\">self</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">user</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">username</span>\n <span style=\"color: #111111\">})</span>\n <span style=\"color: #2eb0f7\">end</span>\n\n <span style=\"color: #2eb0f7\">def</span> <span style=\"color: #111111\">raven_clear_user_context</span>\n <span style=\"color: #111111\">Raven</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">user_context({})</span>\n <span style=\"color: #2eb0f7\">end</span>\n<span style=\"color: #2eb0f7\">end</span>\n</pre></div>\n</div>\n</div>\n</div>\n",
  3. "link": "https://docs.getsentry.com/clients/ruby/integrations/rails/",
  4. "id": "ruby-rails",
  5. "name": "Rails"
  6. }