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.

Hello friends, I would like to know what is the dependency that is used to invoke this method DescribeWorkflowExecution

I hope response thanks

Which Temporal Java SDK version are you using? You should just need
io.temporal:temporal-sdk
which pulls in temporal-serviceclient.

1 Like

Hey friend thanks for answering; If you look I’m using the following,

openjdk version “11.0.17” 2022-10-18 LTS
OpenJDK Runtime Environment Corretto-11.0.17.8.1 (build 11.0.17+8-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.17.8.1 (build 11.0.17+8-LTS, mixed mode

I’m still going to use the dependency you mention, thanks.

hi @tihomir i want to send temporal history as response of an api call. But im getting the below error

through reference chain: com.bre.commons.dto.CommonResponseDto["response"]->io.temporal.internal.common.WorkflowExecutionHistory["history"]->io.temporal.api.history.v1.History["unknownFields"]->com.google.protobuf.UnknownFieldSet["defaultInstanceForType"] : This part of the error message shows the path of the cyclic dependency in the object’s structure.

When Im logging the history it is fine
Please help me resolve

@anil_kumble or @apolo_01 any of you where able to implement this api