Skip to content

Commit

Permalink
Merge pull request #2 from mattbennett/nameko-controlled-greenthread
Browse files Browse the repository at this point in the history
Nameko controlled greenthread
  • Loading branch information
mattbennett committed Jan 23, 2016
2 parents 71eab3f + c9b89eb commit 7e5795c
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 119 deletions.
83 changes: 0 additions & 83 deletions conftest.py

This file was deleted.

37 changes: 33 additions & 4 deletions nameko_sentry.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
import logging

from eventlet.queue import Queue
from nameko.extensions import DependencyProvider
from raven import Client
from raven.transport.eventlet import EventletHTTPTransport


class SentryReporter(DependencyProvider):
""" Send exceptions generated by entrypoints to a sentry server.
"""
_gt = None
queue = None
client = None

def _run(self):

while True:
item = self.queue.get()
if item is None:
break

exc_info, message, extra, data = item
self.client.captureException(
exc_info, message=message, extra=extra, data=data)

# these will remain in scope until the next iteration and
# can potentially be large, so delete to reclaim the memory now
del exc_info, message, extra, data, item

def start(self):
self._gt = self.container.spawn_managed_thread(
self._run, protected=True)

def stop(self):
self.queue.put(None)

if self._gt is not None:
self._gt.wait()

def setup(self):
sentry_config = self.container.config.get('SENTRY')

dsn = sentry_config['DSN']
kwargs = sentry_config.get('CLIENT_CONFIG', {})

self.client = Client(dsn, transport=EventletHTTPTransport, **kwargs)
self.queue = Queue()
self.client = Client(dsn, **kwargs)

def worker_result(self, worker_ctx, result, exc_info):
if exc_info is None:
Expand Down Expand Up @@ -51,5 +81,4 @@ def worker_result(self, worker_ctx, result, exc_info):

extra = {'exc': exc}

self.client.captureException(
exc_info, message=message, extra=extra, data=data)
self.queue.put((exc_info, message, extra, data))
15 changes: 6 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@

setup(
name='nameko-sentry',
version='0.0.1',
version='0.0.2',
description='Nameko extension sends entrypoint exceptions to sentry',
author='Matt Bennett',
author_email='[email protected]',
url='http://github.com/mattbennett/nameko-sentry',
py_modules=['nameko_sentry'],
install_requires=[
"nameko>=2.0.0",
"nameko>=2.2.0",
"raven>=3.0.0"
],
extras_require={
'dev': [
"coverage==4.0a1",
"flake8==2.1.0",
"mccabe==0.3",
"pep8==1.6.1",
"pyflakes==0.8.1",
"pylint==1.0.0",
"pytest==2.4.2",
"coverage==4.0.3",
"flake8==2.5.0",
"pylint==1.5.1",
"pytest==2.8.3",
]
},
dependency_links=[],
Expand Down
Loading

0 comments on commit 7e5795c

Please sign in to comment.