首页 > 解决方案 > Camunda:如何使用 Java API 读取事件堆栈跟踪

问题描述

假设我org.camunda.bpm.engine.runtime.Incident使用RuntimeService.createIncidentQuery()....

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

标签: camunda

解决方案


如果作业失败,则事件的配置/有效负载将是作业 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));
}

推荐阅读