Hardcoded transaction name for ARQ cron jobs
How do you use Sentry?
Self-hosted/on-premise
Version
2.5.1
Steps to Reproduce
- demo.py
import sentry_sdk
from sentry_sdk.integrations.arq import ArqIntegration
from arq import cron
sentry_sdk.init(...)
async def task(ctx):
1/0 # raises an error!
class WorkerSettings:
functions = [task]
cron_jobs = [cron(task, minute=0)]
- Run a worker with
arq demo.WorkerSettings
Expected Result
Expected transaction name in Sentry is task
Actual Result
But got unknown arq task because it hardcoded in the integration https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/arq.py#L103
transaction = Transaction(
name="unknown arq task",
status="ok",
op=OP.QUEUE_TASK_ARQ,
source=TRANSACTION_SOURCE_TASK,
origin=ArqIntegration.origin,
)
with sentry_sdk.start_transaction(transaction):
return await old_run_job(self, job_id, score)
But the task name can be extracted fron job_id
ipdb> job_id
'cron:task:1719844800123'
ipdb> job_id.split(":")
['cron', 'task', '1719844800123']
ipdb> job_id.split(":")[1]
'task'
Sounds like a good idea! Will place this suggestion on our backlog, but I would expect this to be a relatively easy change, so we would happily accept PRs if you'd like to contribute.
Hi @rombr, I looked into this issue a bit more today and attempted to reproduce it; however, I was unable to reproduce the problem. I was getting the transaction name cron:transaction for the code you provided.
While you are correct that we initially set the transaction name to "unknown arq task," the transaction name should be overwritten in the event processor before we send the transaction event to Sentry:
https://github.com/getsentry/sentry-python/blob/855c15f49f845f67e528a9fa63e5d15121de1ab9/sentry_sdk/integrations/arq.py#L142-L144
Could you please provide more information on your setup/how you are initializing Sentry? Perhaps, something in your configuration is preventing this event processor from running as expected.
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀
@szokeasaurusrex I am running into a similar problem now. I don't see that arq automatically set 'job_name' in its ctx, however even when I do it at the beginning of my run I still get 'unkonwn_arq_task'
Hi @aysan0, thank you for reaching out.
Could you please open a separate bug report issue for the problem you are experiencing? Please make sure to fill out the issue template completely with a full reproduction if possible, since that will make it much easier for us to help you. You can also reference this issue in your new issue.
Thanks in advance!