getsentry / sentry-elixir

The official Elixir SDK for Sentry (sentry.io)
https://sentry.io
MIT License
610 stars 179 forks source link

Quantum cron integration doesnt appear to work #749

Open nsweeting opened 1 week ago

nsweeting commented 1 week ago

Environment

erlang 26.2.5.1 elixir 1.17.1-otp-26 sentry 10.6.2

Steps to Reproduce

  1. Added quantum integration config as specified in docs. I can confirm check-ins were being called through :dbg.
  2. Added the accompanying monitor in sentry. Docs could likely be improved here. I had to dive into the code to understand what the monitor slug would be (specifically that is prefixed with "quantum").

Expected Result

Check-ins should show in the sentry UI when a quantum job runs.

Actual Result

No check-ins occur.

I can manually trigger a check in as specified in the docs.

  # Report that the job started.
  {:ok, check_in_id} = Sentry.capture_check_in(status: :in_progress, monitor_slug: "genserver-job")

  :ok = do_job(state)

  # Report that the job ended successfully.
  Sentry.capture_check_in(check_in_id: check_in_id, status: :ok, monitor_slug: "genserver-job")

This is different than what the quantum integration does though. The integration passes its own check_in_id for the :in_progress check. The same id is used for the final :ok check in.

https://github.com/getsentry/sentry-elixir/blob/68fbfb5707620913efdf1ac06735470f4a0d5a8f/lib/sentry/integrations/quantum/cron.ex#L65

It appears that sentry expects the ID that is returned from the first :in_progress check in to be passed to the final :ok check in. When manually doing this - the check in is successful.

whatyouhide commented 1 week ago

Thanks for the report! This is helpful. @savhappy do you have time to take a look at this?

savhappy commented 1 week ago

@whatyouhide yep yep! Will get to this tomorrow.

savhappy commented 1 week ago

@nsweeting thanks for the direction! It does appear a different check_in_id is being passed each time for every call because the ref is changing. Perhaps we can pass in a :name instead or use telemetry to track jobs. I'll dig a bit more

whatyouhide commented 1 week ago

@savhappy thank you! The only other way (that I can think of) to get the check-in ID returned by Sentry in the :in_progress check in and use it for the :ok check in is this: we store check-in IDs in an ETS table keyed by Quantum cron job ID and then we fetch it later on. But let's see if :name works out.

savhappy commented 4 days ago

Update: The envelope isn't utilizing the correct id, instead of using the check_in structs id, we generate a new UUID every time and set this as the event_id. This also means Oban isn't working right.

After correcting this, we have the problem of the cron jobs setting a check_in_id in the incorrect format (non UUIDs) as the docs mention the requirement of event_id's being a UUID. @whatyouhide's suggestion of storing the cron job id in an ETS table and mapping it to an eventid UUID seems to be the best solution. Working on this ^^