123456 |
- {
- "html": "<div class=\"section\" id=\"installation\">\n<h2>Installation</h2>\n<p>If you haven’t already, start by downloading Raven. The easiest way is\nwith <em>pip</em>:</p>\n<div class=\"highlight-python\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span>pip install raven --upgrade\n</pre></div>\n</div>\n</div>\n\n\n<div class=\"section\" id=\"setup\">\n<h2>Setup</h2>\n<p>The first thing you’ll need to do is to disable catchall in your Bottle app:</p>\n<div class=\"highlight-python\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">bottle</span>\n\n<span style=\"color: #111111\">app</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #111111\">bottle</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">app()</span>\n<span style=\"color: #111111\">app</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">catchall</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #45c2c9\">False</span>\n</pre></div>\n</div>\n<div class=\"admonition note\">\n<p class=\"first admonition-title\">Note</p>\n<p class=\"last\">Bottle will not propagate exceptions to the underlying WSGI\nmiddleware by default. Setting catchall to False disables that.</p>\n</div>\n<p>Sentry will then act as Middleware:</p>\n<div class=\"highlight-python\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">from</span> <span style=\"color: #111111\">raven</span> <span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">Client</span>\n<span style=\"color: #2eb0f7\">from</span> <span style=\"color: #111111\">raven.contrib.bottle</span> <span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">Sentry</span>\n<span style=\"color: #111111\">client</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #111111\">Client(</span><span style=\"color: #e8535a\">'___DSN___'</span><span style=\"color: #111111\">)</span>\n<span style=\"color: #111111\">app</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #111111\">Sentry(app,</span> <span style=\"color: #111111\">client)</span>\n</pre></div>\n</div>\n</div>\n\n\n<div class=\"section\" id=\"usage\">\n<h2>Usage</h2>\n<p>Once you’ve configured the Sentry application you need only call run with it:</p>\n<div class=\"highlight-python\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">run(app</span><span style=\"color: #4b4f5c\">=</span><span style=\"color: #111111\">app)</span>\n</pre></div>\n</div>\n<p>If you want to send additional events, a couple of shortcuts are provided\non the Bottle request app object.</p>\n<p>Capture an arbitrary exception by calling <code class=\"docutils literal\"><span class=\"pre\">captureException</span></code>:</p>\n<div class=\"highlight-python\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">try</span><span style=\"color: #111111\">:</span>\n <span style=\"color: #45c2c9\">1</span> <span style=\"color: #4b4f5c\">/</span> <span style=\"color: #45c2c9\">0</span>\n<span style=\"color: #2eb0f7\">except</span> <span style=\"color: #e8535a\">ZeroDivisionError</span><span style=\"color: #111111\">:</span>\n <span style=\"color: #111111\">request</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">app</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">captureException()</span>\n</pre></div>\n</div>\n<p>Log a generic message with <code class=\"docutils literal\"><span class=\"pre\">captureMessage</span></code>:</p>\n<div class=\"highlight-python\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">request</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">app</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">captureMessage(</span><span style=\"color: #e8535a\">'Hello, world!'</span><span style=\"color: #111111\">)</span>\n</pre></div>\n</div>\n</div>\n",
- "link": "https://docs.getsentry.com/clients/python/integrations/bottle/",
- "id": "python-bottle",
- "name": "Bottle"
- }
|