raven-aiohttp, raven python的aiohttp传输

分享于 

3分钟阅读

GitHub

  繁體 雙語
An aiohttp transport for raven-python
  • 源代码名称:raven-aiohttp
  • 源代码网址:http://www.github.com/getsentry/raven-aiohttp
  • raven-aiohttp源代码文档
  • raven-aiohttp源代码下载
  • Git URL:
    git://www.github.com/getsentry/raven-aiohttp.git
    Git Clone代码到本地:
    git clone http://www.github.com/getsentry/raven-aiohttp
    Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/getsentry/raven-aiohttp
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    

    Sentry website

    raven raven raven Sentry SDK SDK SDK

    PyPi page link -- versionhttps://travis-ci.org/getsentry/raven-aiohttp.svg?branch=masterPyPi page link -- BSD licencePyPi page link -- Python versions

    支持 python 3 asyncio接口的哨兵 python的传输。 有关岗哨和 python SDK的详细信息,请参阅我们的python 文档框架集成和其他工具。

    要求

    • raven-python> =5.4 0
    • python> =3。4.2
    • aiohttp> =2.0

    用法

    raven-aiohttp为 raven.Client 提供了两个基于asyncio的传输: AioHttpTransport和 QueuedAioHttpTransport。

    AioHttpTransport

    sentry server的所有消息都将由"fire Forget"

    每条新消息产生它拥有的asyncio.Task, 数量不有限

    
    
    
    
    import asyncio
    
    
    
    from raven import Client
    
    
    from raven_aiohttp import AioHttpTransport
    
    
    
    client = Client(transport=AioHttpTransport)
    
    
    
    try:
    
    
     1 / 0
    
    
    except ZeroDivisionError:
    
    
     client.captureException()
    
    
    
    # graceful shutdown waits until all pending messages are send
    
    
    
    loop = asyncio.get_event_loop()
    
    
    loop.run_until_complete(client.remote.get_transport().close())
    
    
    
    
    QueuedAioHttpTransport

    将所有消息发送到岗哨服务器由队列系统生成

    创建传输时,会产生有限数量的asyncio.Task,它从内部 asyncio.Queue 逐个发送消息

    
    
    
    
    import asyncio
    
    
    from functools import partial
    
    
    
    from raven import Client
    
    
    from raven_aiohttp import QueuedAioHttpTransport
    
    
    
    client = Client(transport=partial(QueuedAioHttpTransport, workers=5, qsize=1000))
    
    
    
    try:
    
    
     1 / 0
    
    
    except ZeroDivisionError:
    
    
     client.captureException()
    
    
    
    # graceful shutdown waits until internal queue is empty
    
    
    
    loop = asyncio.get_event_loop()
    
    
    loop.run_until_complete(client.remote.get_transport().close())
    
    
    
    

    资源


    Transport  Raven  AIO  aiohttp