【问题标题】:remove current breadcrumbs in sentry删除哨兵中的当前面包屑
【发布时间】:2019-06-03 10:37:03
【问题描述】:

我有这样的简单同步代码:

import sentry_sdk
from time import sleep


sentry_sdk.init(MY_DSN)
while True:
    # remove sentry breadcrumbs here, so they would not accumulate
    try:
        do_my_stuff()
    except:
        handle_my_exception()

    sleep(some_non_linear_algorithm())  # I would like not to use crontab

当异常发生时,哨兵会捕获它和以前迭代的所有面包屑,所以我需要在每次迭代开始时删除所有当前的面包屑。但我在哨兵文档中找不到任何 API 来做到这一点。

【问题讨论】:

    标签: python sentry


    【解决方案1】:

    将您的代码包装在此:

    with sentry_sdk.push_scope():
        try:
            ...
        except:
            ...
    

    这将确保您不会在迭代之间泄漏面包屑、标签等。

    您也可以使用:

    with sentry_sdk.configure_scope() as scope:
        scope.clear()
    

    【讨论】:

    • 这行得通,但我使用 scope.clear_breadcrumbs() 代替 scope.clear()(我还没有使用任何标签)。
    猜你喜欢
    • 2019-07-15
    • 2021-11-11
    • 2021-11-14
    • 2021-07-24
    • 1970-01-01
    • 2018-08-19
    • 2014-11-29
    • 1970-01-01
    • 2023-04-08
    相关资源
    最近更新 更多