Camunda:如何使用 Java API 读取事件堆栈跟踪

Camunda: How to read incident stack trace with Java API

假设我使用 RuntimeService.createIncidentQuery()....

发现事件 (org.camunda.bpm.engine.runtime.Incident)

有没有办法使用 Java API 读取实际事件堆栈跟踪?在 Cockpit 中可访问相同的堆栈跟踪。

如果作业失败,则事件的配置/负载将是作业 ID。如果事件是由失败的外部任务引起的,那么它将是外部任务 ID。

https://docs.camunda.org/javadoc/camunda-bpm-platform/7.15/org/camunda/bpm/engine/runtime/Incident.html

https://docs.camunda.org/javadoc/camunda-bpm-platform/7.15/org/camunda/bpm/engine/ManagementService.html#getJobExceptionStacktrace-java.lang.String-

https://docs.camunda.org/javadoc/camunda-bpm-platform/7.15/org/camunda/bpm/client/task/ExternalTask.html#getErrorDetails--

因此:

Incident incident = runtimeService.createIncidentQuery().singleResult();
String configuration = incident.getConfiguration();

log.info("Incident type: {}", incident.getIncidentType());
if (incident.getIncidentType().equals(Incident.FAILED_JOB_HANDLER_TYPE)) {
    log.info("Here comes the stacktrace: {}", managementService.getJobExceptionStacktrace(configuration));
} else {
    log.info("Here come the error details: {}", externalTaskService.getExternalTaskErrorDetails(configuration));
}