Query running workflows by their history size in either events or bytes

Hi all!
I use replay history to check if my local code will cause NonDeterminism error on running workflows. But now there’s 1 million of them and I can’t run replay history on all of them. I’m writing select to get some amount workflow that is enough to run on them replay history to avoid NonDeterminismError. So I wanna get 10 biggest workflows by history, but I see that for running workflows there’s no searchAttributes HistoryLength and HistorySizeBytes . Is there any way to do that?

Both HistoryLength and HistorySizeBytes are added to executions visibility data once exec completes (so not when its running as you correctly noticed).

One way that could maybe work for you is to query your primary persistence store directly. For sql persistence something like:

SELECT public.executions.workflow_id, public.executions.next_event_id 
  FROM public.executions 
  LEFT JOIN public.current_executions
  ON public.executions.workflow_id = public.current_executions.workflow_id
  WHERE public.current_executions.status = 1
  ORDER BY next_event_id desc limit 10