推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
Ehco1996
V2EX  ›  Python

sentry 怎么用在 asyncio 里?

  •  
  •   Ehco1996 · Oct 28, 2018 · 3230 views
    This topic created in 2891 days ago, the information mentioned may be changed or developed.

    好像 asyncio 的协程报错之后

    exit context 并不会被跑出来

    所以是不是 sentry 不能被集成进去?

    8 replies  •  2018-10-28 14:53:56 +08:00
    klesh
        1
    klesh  
       Oct 28, 2018 via Android
    虽然看不懂你在说什么,但是 asyncio 一样可以 try catch 的。我集成过 aiohttp, 没有问题
    Ehco1996
        2
    Ehco1996  
    OP
       Oct 28, 2018
    @klesh 不是 try catch 的问题
    我就是想知道程序哪里会报错,才想把 sentry 集成进去的
    so1n
        3
    so1n  
       Oct 28, 2018 via Android
    你用的是哪个 web 框架? sentry 官方封装了一个 aio 报错客户端,很多人也移植到其他异步 web 框架
    Ehco1996
        4
    Ehco1996  
    OP
       Oct 28, 2018 via iPhone
    @so1n 是自己写的小项目,不是 web 的
    Trim21
        5
    Trim21  
       Oct 28, 2018 via Android
    可以手动 try catch 之后把对应的错误给 sentry 上报

    from sentry_sdk import capture_exception

    try:
    a_potentially_failing_function()
    except Exception as e:
    # Alternatively the argument can be omitted
    capture_exception(e)
    Capturing Messages
    Ehco1996
        6
    Ehco1996  
    OP
       Oct 28, 2018 via iPhone
    @Trim21 主要我是全局的 catch...
    看来好像没什么好办法
    Trim21
        7
    Trim21  
       Oct 28, 2018 via Android
    @Ehco1996 考虑一下用装饰器,把可能出错的函数包起来 try except 然后再 raise 出去?
    so1n
        8
    so1n  
       Oct 28, 2018 via Android
    @Ehco1996 有没有用到 http 请求呢?如果有的话,官方有封装一个异步的 sentry 请求库,可以到他们 github 看看,我之前是找 sanic 找到 sanic-sentry 看到他直接调用官方的异步库
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2714 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 07:13 · PVG 15:13 · LAX 00:13 · JFK 03:13
    ♥ Do have faith in what you're doing.