How to Retrieve the History Size of a Running Workflow in Temporal?

I’m currently working with the Temporal Java SDK and I’m trying to retrieve the history size of a running workflow. I understand that Workflow.getInfo().getHistoryLength() gives me the number of history events, but I am looking for a way to get the actual history size (in MB) for a running workflow.

Is there a built-in method or a recommended approach to get the size of the workflow history (not just the event count) from inside the running workflow?

I have explored the DescribeWorkflowExecution API to get this information externally, but I am specifically interested in finding out if there is a way to retrieve this from within the running workflow itself.

Any insights or pointers to documentation would be greatly appreciated!

Thank you!

According to the JavaDoc, the getHistorySize returns the size in bytes. getHistoryLength returns the number of events:

  /**
   * @return length of Workflow history up until the current moment of execution. This value changes
   *     during the lifetime of a Workflow Execution. You may use this information to decide when to
   *     call {@link Workflow#continueAsNew(Object...)}.
   */
  long getHistoryLength();

  /**
   * @return size of Workflow history in bytes up until the current moment of execution. This value
   *     changes during the lifetime of a Workflow Execution.
   */
  long getHistorySize();
2 Likes

Thanks for your quick response! I’m now able to access the history size. It turns out I was using an older version of the SDK, which is why I wasn’t able to see it. After updating to the latest version (1.28.3), I can access the history size and successfully implement the changes.

I really appreciate your support. Thanks again!

1 Like