本文整理汇总了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)
示例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
示例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)
示例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}.")
示例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)