Custom History Plugin - Determine Process Instance Externally Cancelled

We are working on a Composite History Event Handler plugin that is based on this example: https://github.com/camunda-consulting/code/tree/master/snippets/engine-plugin-custom-history-event-handler

We don’t see that it is possible to determine from the History Event for a Process Instance that the instance was externally cancelled, for example via the REST API.

For this experiment we start a Process Instance, then cancel it via the REST API. The History Event that is logged has no indication that the instance was externally terminated, as seen below:

01-Apr-2022 19:18:15.463 INFO [http-nio-8080-exec-52] com.camunda.demo.engine_plugin_custom_history_event_handler.MyCustomHistoryEventHandler.handleEvent ----- HISTORY EVENT PRODUCED: HistoricProcessInstanceEventEntity[businessKey=null, startUserId=null, superProcessInstanceId=null, rootProcessInstanceId=ab37135d-5f6d-11ec-9a15-0242ac150007, superCaseInstanceId=null, deleteReason=null, durationInMillis=null, startTime=null, endTime=Fri Apr 01 19:18:14 UTC 2022, removalTime=null, endActivityId=null, startActivityId=null, id=ab37135d-5f6d-11ec-9a15-0242ac150007, eventType=end, executionId=ab37135d-5f6d-11ec-9a15-0242ac150007, processDefinitionId=8faa6be1-5f6c-11ec-9a15-0242ac150007, processInstanceId=ab37135d-5f6d-11ec-9a15-0242ac150007, tenantId=d724baf2-572d-4422-9dc8-25be682c7383]

However, after the instance has been canceled, we query ACT_HI_PROCINST and see that the STATE_ column has the expected value: “EXTERNALLY_TERMINATED”.

How can we determine that the Process Instance was EXTERNALLY_TERMINATED from within the History plugin?

Hi, just wondering if anyone has any thoughts on the post above. Thanks.