Work on aiohttp transport

This commit is contained in:
Andrew Svetlov 2014-06-19 18:49:48 +03:00
parent 8a9536aeed
commit b0264e9252
6 changed files with 36 additions and 40 deletions

View File

@ -9,6 +9,8 @@ This document describes configuration options available to Sentry.
.. toctree::
:maxdepth: 2
aiohttp
asyncio
bottle
celery
django
@ -62,7 +64,11 @@ It is composed of six important pieces:
* The project ID which the authenticated user is bound to.
.. note:: Protocol may also contain transporter type: gevent+http, gevent+https, twisted+http, tornado+http, eventlet+http, eventlet+https
.. note::
Protocol may also contain transporter type: gevent+http, gevent+https, twisted+http, tornado+http, eventlet+http, eventlet+https
For *Python 3.3+* also available: aiohttp+http, aiohttp+https, asycio+udp
Client Arguments
----------------

View File

@ -25,6 +25,15 @@ For example, to increase the timeout and to disable SSL verification:
SENTRY_DSN = 'http://public:secret@example.com/1?timeout=5&verify_ssl=0'
aiohttp
-------
Should only be used within a Tornado IO loop.
::
SENTRY_DSN = 'aiohttp+http://public:secret@example.com/1'
Eventlet
--------

View File

@ -22,5 +22,5 @@ from raven.transport.threaded import * # NOQA
from raven.transport.tornado import * # NOQA
from raven.transport.udp import * # NOQA
if sys.version_info() >= (3.3):
from raven.transport.asyncio import * # NOQA
if sys.version_info >= (3, 3):
from raven.transport.aiohttp import * # NOQA

View File

@ -5,36 +5,30 @@ raven.transport.asyncio
:copyright: (c) 2010-2014 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
from __future__ import absolute_import
import logging
from raven.transport.base import AsyncTransport
from raven.transport.http import HTTPTransport
from raven.transport.udp import BaseUDPTransport
try:
import asyncio
import aiohttp
has_asyncio = True
import asyncio
has_aiohttp = True
except:
has_asyncio = False
has_aiohttp = False
class AsyncioHttpTransport(AsyncTransport, HTTPTransport):
class AioHttpTransport(AsyncTransport, HTTPTransport):
scheme = ['asyncio+http', 'asyncio+https']
scheme = ['aiohttp+http', 'aiohttp+https']
def __init__(self, parsed_url, *, loop=None):
if not has_asyncio:
raise ImportError('AIOHttpTransport requires asyncio and aiohttp.')
if not has_aiohttp:
raise ImportError('AioHttpTransport requires asyncio and aiohttp.')
if loop is None:
loop = asyncio.get_event_loop()
self._loop = loop
super().__init__(parsed_url)
self.logger = logging.getLogger('sentry.errors')
# remove the aiohttp+ from the protocol, as it is not a real protocol
self._url = self._url.split('+', 1)[-1]
@ -52,21 +46,3 @@ class AsyncioHttpTransport(AsyncTransport, HTTPTransport):
except Exception as exc:
failure_cb(exc)
asyncio.async(f(), loop=self._loop)
class AsyncioUDPTransport(BaseUDPTransport):
scheme = ['asyncio+udp']
def __init__(self, parsed_url, *, loop=None):
super().__init__(parsed_url)
if not has_asyncio:
raise ImportError('AsyncioUDPTransport requires asyncio.')
if loop is None:
loop = asyncio.get_event_loop()
self._loop = loop
self._transport, _ = loop.run_until_complete(
loop.create_datagram_endpoint(asyncio.DatagramProtocol))
def _send_data(self, data, addr):
self._transport.send_to(data, addr)

View File

@ -20,8 +20,8 @@ from raven.transport.tornado import TornadoHTTPTransport
from raven.transport.udp import UDPTransport
from raven.utils import urlparse
if sys.version_info() >= (3.3):
from raven.transport.asyncio import AsyncioHttpTransport
if sys.version_info >= (3, 3):
from raven.transport.aiohttp import AioHttpTransport
class TransportRegistry(object):
@ -83,5 +83,5 @@ default_transports = [
EventletHTTPTransport,
]
if sys.version_info() >= (3.3):
default_transports += [AsyncioHttpTransport,]
if sys.version_info >= (3, 3):
default_transports += [AioHttpTransport]

View File

@ -54,6 +54,11 @@ if sys.version_info[0] == 3:
unittest2_requires = []
webpy_tests_requires = []
if sys.version_info >= (3, 3):
aiohttp_requires = ['aiohttp']
else:
aiohttp_requires = []
tests_require = [
'bottle',
@ -74,8 +79,8 @@ tests_require = [
'webob',
'webtest',
'anyjson',
] + (flask_requires + flask_tests_requires + unittest2_requires +
webpy_tests_requires)
] + (aiohttp_requires + flask_requires + flask_tests_requires +
unittest2_requires + webpy_tests_requires)
class PyTest(TestCommand):