当前位置: 首页>>代码示例>>Python>>正文


Python sentry_sdk.push_scope方法代码示例

本文整理汇总了Python中sentry_sdk.push_scope方法的典型用法代码示例。如果您正苦于以下问题:Python sentry_sdk.push_scope方法的具体用法?Python sentry_sdk.push_scope怎么用?Python sentry_sdk.push_scope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sentry_sdk的用法示例。


在下文中一共展示了sentry_sdk.push_scope方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: log_exception

# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import push_scope [as 别名]
def log_exception(exception=None, context: commands.Context = None):
        if config.SENTRY_DSN is None:
            return

        with sentry_sdk.push_scope() as scope:
            if context:
                # noinspection PyDunderSlots,PyUnresolvedReferences
                # for some reason pycharm doesn't pick up the attribute setter here
                scope.user = {"id": context.author.id, "username": str(context.author)}
                scope.set_tag("message.content", context.message.content)
                scope.set_tag("is_private_message", context.guild is None)
                scope.set_tag("channel.id", context.channel.id)
                scope.set_tag("channel.name", str(context.channel))
                if context.guild is not None:
                    scope.set_tag("guild.id", context.guild.id)
                    scope.set_tag("guild.name", str(context.guild))
            sentry_sdk.capture_exception(exception) 
开发者ID:avrae,项目名称:avrae,代码行数:19,代码来源:dbot.py

示例2: push_scope_to_sentry

# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import push_scope [as 别名]
def push_scope_to_sentry():
    try:
        # so that we don't have to have sentry sdk installed locally
        import sentry_sdk

    except ImportError:

        class SentryMocker:
            def set_tag(self, k, v):
                pass

        yield SentryMocker()
    else:

        with sentry_sdk.push_scope() as scope:
            yield scope 
开发者ID:packit-service,项目名称:packit-service,代码行数:18,代码来源:sentry_integration.py

示例3: handle_unexpected_error

# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import push_scope [as 别名]
def handle_unexpected_error(ctx: Context, e: errors.CommandError) -> None:
        """Send a generic error message in `ctx` and log the exception as an error with exc_info."""
        await ctx.send(
            f"Sorry, an unexpected error occurred. Please let us know!\n\n"
            f"```{e.__class__.__name__}: {e}```"
        )

        ctx.bot.stats.incr("errors.unexpected")

        with push_scope() as scope:
            scope.user = {
                "id": ctx.author.id,
                "username": str(ctx.author)
            }

            scope.set_tag("command", ctx.command.qualified_name)
            scope.set_tag("message_id", ctx.message.id)
            scope.set_tag("channel_id", ctx.channel.id)

            scope.set_extra("full_message", ctx.message.content)

            if ctx.guild is not None:
                scope.set_extra(
                    "jump_to",
                    f"https://discordapp.com/channels/{ctx.guild.id}/{ctx.channel.id}/{ctx.message.id}"
                )

            log.error(f"Error executing command invoked by {ctx.message.author}: {ctx.message.content}", exc_info=e) 
开发者ID:python-discord,项目名称:bot,代码行数:30,代码来源:error_handler.py

示例4: on_error

# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import push_scope [as 别名]
def on_error(self, event: str, *args, **kwargs) -> None:
        """Log errors raised in event listeners rather than printing them to stderr."""
        self.stats.incr(f"errors.event.{event}")

        with push_scope() as scope:
            scope.set_tag("event", event)
            scope.set_extra("args", args)
            scope.set_extra("kwargs", kwargs)

            log.exception(f"Unhandled exception in {event}.") 
开发者ID:python-discord,项目名称:bot,代码行数:12,代码来源:bot.py

示例5: handle_event

# 需要导入模块: import sentry_sdk [as 别名]
# 或者: from sentry_sdk import push_scope [as 别名]
def handle_event(event: Event, context: Context) -> None:
    """ Calls the handler for the given event.

    Exceptions are caught and generate both error logs and sentry issues.
    Events are not retried after an exception.
    """
    log.debug(
        "Processing event",
        event_=event,
        latest_confirmed_block=context.latest_confirmed_block,
        latest_unconfirmed_block=context.get_latest_unconfirmed_block(),
    )
    handler = HANDLERS.get(type(event))

    if handler:
        with sentry_sdk.push_scope() as sentry_scope:
            sentry_scope.set_tag("event", event.__class__.__name__)
            try:
                handler(event, context)
                log.debug(
                    "Processed event",
                    num_scheduled_events=context.database.scheduled_event_count(),
                )
            except Exception as ex:  # pylint: disable=broad-except
                log.error("Error during event handler", handled_event=event, exc_info=ex)
                sentry_sdk.capture_exception(ex) 
开发者ID:raiden-network,项目名称:raiden-services,代码行数:28,代码来源:service.py


注:本文中的sentry_sdk.push_scope方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。