python-celery.json 5.7 KB

123456
  1. {
  2. "html": "<div class=\"section\" id=\"installation\">\n<h2>Installation</h2>\n<p>If you haven&#8217;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=\"celery\">\n<h2>Celery</h2>\n<p><a class=\"reference external\" href=\"http://www.celeryproject.org/\">Celery</a> is a distributed task queue\nsystem for Python built on AMQP principles. For Celery built-in support\nby Raven is provided but it requires some manual configuration.</p>\n<div class=\"section\" id=\"installation\">\n<h3>Installation</h3>\n<p>If you haven&#8217;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<div class=\"section\" id=\"setup\">\n<h3>Setup</h3>\n<p>To capture errors, you need to register a couple of signals to hijack\nCelery error handling:</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.celery</span> <span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">register_signal,</span> <span style=\"color: #111111\">register_logger_signal</span>\n\n<span style=\"color: #111111\">client</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #111111\">Client(</span><span style=\"color: #e8535a\">&#39;___DSN___&#39;</span><span style=\"color: #111111\">)</span>\n\n<span style=\"color: #34c08b; font-style: italic\"># register a custom filter to filter out duplicate logs</span>\n<span style=\"color: #111111\">register_logger_signal(client)</span>\n\n<span style=\"color: #34c08b; font-style: italic\"># The register_logger_signal function can also take an optional argument</span>\n<span style=\"color: #34c08b; font-style: italic\"># `loglevel` which is the level used for the handler created.</span>\n<span style=\"color: #34c08b; font-style: italic\"># Defaults to `logging.ERROR`</span>\n<span style=\"color: #111111\">register_logger_signal(client,</span> <span style=\"color: #111111\">loglevel</span><span style=\"color: #4b4f5c\">=</span><span style=\"color: #111111\">logging</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">INFO)</span>\n\n<span style=\"color: #34c08b; font-style: italic\"># hook into the Celery error handler</span>\n<span style=\"color: #111111\">register_signal(client)</span>\n\n<span style=\"color: #34c08b; font-style: italic\"># The register_signal function can also take an optional argument</span>\n<span style=\"color: #34c08b; font-style: italic\"># `ignore_expected` which causes exception classes specified in Task.throws</span>\n<span style=\"color: #34c08b; font-style: italic\"># to be ignored</span>\n<span style=\"color: #111111\">register_signal(client,</span> <span style=\"color: #111111\">ignore_expected</span><span style=\"color: #4b4f5c\">=</span><span style=\"color: #45c2c9\">True</span><span style=\"color: #111111\">)</span>\n</pre></div>\n</div>\n<p>A more complex version to encapsulate behavior:</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\">celery</span>\n<span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">raven</span>\n<span style=\"color: #2eb0f7\">from</span> <span style=\"color: #111111\">raven.contrib.celery</span> <span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">register_signal,</span> <span style=\"color: #111111\">register_logger_signal</span>\n\n<span style=\"color: #2eb0f7\">class</span> <span style=\"color: #111111\">Celery(celery</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">Celery):</span>\n\n <span style=\"color: #2eb0f7\">def</span> <span style=\"color: #111111\">on_configure(</span><span style=\"color: #45c2c9\">self</span><span style=\"color: #111111\">):</span>\n <span style=\"color: #111111\">client</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #111111\">raven</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">Client(</span><span style=\"color: #e8535a\">&#39;___DSN___&#39;</span><span style=\"color: #111111\">)</span>\n\n <span style=\"color: #34c08b; font-style: italic\"># register a custom filter to filter out duplicate logs</span>\n <span style=\"color: #111111\">register_logger_signal(client)</span>\n\n <span style=\"color: #34c08b; font-style: italic\"># hook into the Celery error handler</span>\n <span style=\"color: #111111\">register_signal(client)</span>\n\n<span style=\"color: #111111\">app</span> <span style=\"color: #4b4f5c\">=</span> <span style=\"color: #111111\">Celery(__name__)</span>\n<span style=\"color: #111111\">app</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #111111\">config_from_object(</span><span style=\"color: #e8535a\">&#39;django.conf:settings&#39;</span><span style=\"color: #111111\">)</span>\n</pre></div>\n</div>\n</div>\n</div>\n",
  3. "link": "https://docs.getsentry.com/clients/python/integrations/celery/",
  4. "id": "python-celery",
  5. "name": "Celery"
  6. }