當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。