You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The log here, I think it should be that if found_exception is not None, the value of log is equal to str(exc).
If the operation is normal, do you need other operation logs?
We'were planning to remove log completely, so people rely on alerting systems like sentry. But your comment makes sense. Maybe we can even propogate error with stacktrace?
Hi, @vvanglro. We merged a request with serializable exceptions. Now you can actually raise an error on client-side.
With new API TaskiqResult has error field and raise_for_error method.
task=awaitmy_task.kiq(param)
# Now the exception will be thrown if there's an error.result= (awaittask.wait_result()).raise_for_error()
Suddenly it's almost impossible to serialize traceback. And even if you can, it can lead to some security issues.
If you want to send exception to some libraries, you can do it in middlewares! Since middlewares can execute code on worker-side, you'll be able to show traceback and everything.
Also, I've created a test file for sentry integration. So if you would ever decide to move forward with sentry as an error tracking system. Here's a cool integration that helps tracking errors.
importasynciofromtypingimportAny, Coroutineimportsentry_sdkfromsentry_sdk.integrations.loggingimportLoggingIntegration, ignore_loggerfromtaskiq_redisimportRedisAsyncResultBackendfromtaskiqimportTaskiqMiddleware, ZeroMQBrokerfromtaskiq.eventsimportTaskiqEventsfromtaskiq.messageimportTaskiqMessagefromtaskiq.resultimportTaskiqResultfromtaskiq.stateimportTaskiqStateclassExcSender(TaskiqMiddleware):
defon_error(
self,
message: TaskiqMessage,
result: TaskiqResult[Any],
exception: BaseException,
) ->Coroutine[Any, Any, None] |None:
sentry_sdk.capture_exception(
exception,
tags={
"taskiq_task_name": message.task_name,
"taskiq_task_id": message.task_id,
},
)
print("SENDING EXCEPTION TO SENTRY!")
broker= (
ZeroMQBroker()
.with_result_backend(
RedisAsyncResultBackend("redis://localhost"),
)
.with_middlewares(ExcSender())
)
# Here we initialize sentry inside workers. # If you have framework integration, probably, you won't need to call it# explicitly.@broker.on_event(TaskiqEvents.WORKER_STARTUP)defsentry_init(_: TaskiqState):
# We ignore this logger, because it's events may overwrite# exception we capture in middlewares with new tags. ignore_logger("taskiq.receiver.receiver")
sentry_sdk.init(
"https://key@your-sentry-instance",
environment="dev",
integrations=[LoggingIntegration()],
)
@broker.taskasyncdefmy_task() ->None:
try:
print(1/0)
exceptBaseExceptionasexc:
raiseException("Lol") fromexcasyncdefmain():
awaitbroker.startup()
awaitasyncio.sleep(2)
task=awaitmy_task.kiq()
res=awaittask.wait_result()
# Here it just prints an error.print(res)
awaitbroker.shutdown()
if__name__=="__main__":
asyncio.run(main())
It works and sends all events with propper task_id's and task names.
Activity
s3rius commentedon May 8, 2023
We'were planning to remove log completely, so people rely on alerting systems like sentry. But your comment makes sense. Maybe we can even propogate error with stacktrace?
vvanglro commentedon May 8, 2023
Yes, when there is no third-party alarm system and other plugins, you can get the error log by checking whether is_err is True.
s3rius commentedon May 22, 2023
Hi, @vvanglro. We merged a request with serializable exceptions. Now you can actually raise an error on client-side.
With new API
TaskiqResulthaserrorfield andraise_for_errormethod.Suddenly it's almost impossible to serialize traceback. And even if you can, it can lead to some security issues.
If you want to send exception to some libraries, you can do it in middlewares! Since middlewares can execute code on worker-side, you'll be able to show traceback and everything.
s3rius commentedon May 22, 2023
Also, I've created a test file for sentry integration. So if you would ever decide to move forward with sentry as an error tracking system. Here's a cool integration that helps tracking errors.
It works and sends all events with propper task_id's and task names.
vvanglro commentedon May 23, 2023
This is a good example of collecting errors with sentry, Maybe it should be added to the docs.
This issue can also be searched by the people behind.