How to get the workflow execution details other than Temporal web UI

Team,

As we are yet to implement the authentication in Temporal web UI we wanted to find the details of a workflow execution from temporal-cli or from some other source.

We wanted to get the Summary, History, Stacktrace, and Query details of workflow execution.

Is there any way to get that?

Stacktrace

You can get the stack trace for running workflow executions via the QueryWorkflowRequest and the built-in “__stack_trace” query, for example:


QueryWorkflowRequest req =
                QueryWorkflowRequest.newBuilder()
                        .setNamespace(client.getOptions().getNamespace())
                        .setQuery(WorkflowQuery.newBuilder()
                                .setQueryType("__stack_trace").build())
                        .setExecution(workflowExecution)
                        .build();
        QueryWorkflowResponse res = service.blockingStub().queryWorkflow(req);
        String trace = res.getQueryResult();

If you have the workflow id and runid as string you can build your WorkflowExecution instance with for example:

WorkflowExecution execution = WorkflowExecution.newBuilder()
                .setWorkflowId("myworkflowid")
                .setRunId("myworkflowrunid")
                .build();

Summary

You can get this via DescribeWorkflowExecution api, for example:

DescribeWorkflowExecutionRequest req =
                    DescribeWorkflowExecutionRequest.newBuilder()
                            .setNamespace(client.getOptions().getNamespace())
                            .setExecution(info.getExecution()).build();
            DescribeWorkflowExecutionResponse res =
                    service.blockingStub().describeWorkflowExecution(req);

The top section info of the web-ui summary page you can get via

WorkflowExecutionInfo info = res.getWorkflowExecutionInfo();
// ....

Pending activities are also available from the response:

List<PendingActivityInfo> pendingActivitiesList = describeWorkflowExecutionResponse.getPendingActivitiesList();

History

You can get workflow history as JSON via SDK as well, via GetWorkflowExecutionHistory api:


GetWorkflowExecutionHistoryRequest request =
                GetWorkflowExecutionHistoryRequest.newBuilder()
                        .setNamespace("default")
                        .setExecution(WorkflowExecution.newBuilder()
                                .setWorkflowId(wfId)
                                .setRunId(wfRunId)
                                .build())
                        .build();
        String history = new WorkflowExecutionHistory(
                service.blockingStub().getWorkflowExecutionHistory(request).getHistory()).toJson(true);

Query

You can use QueryWorkflow api like with the stack trace but provide your query type (query name which is by default the name of your QueryMethod).

Thanks for the response @tihomir

It can be only done via Java Code.
Can we achieve it from temporal-cli or by querying the database?

You should not have to query your db for any of this (its also not recommended), rather use tctl (cli) or your sdk apis.

For tctl:

Stack trace

tctl wf stack -h

Query

tctl wf query -h

History

tctl wf show -h

to store json to file:
tctl wf show -w <wfid> -r <runid> --output_filename myhistory.json

Summary

tctl wf desc -h

There is also docs on this here.