Workflow code is stateful with the Temporal framework preserving it over various software and hardware failures. The state is constantly mutated during Workflow execution. To expose this internal state to the external world Temporal provides a synchronous query feature. From the Workflow implementer point of view the query is exposed as a synchronous callback that is invoked by external entities. Multiple such callbacks can be provided per Workflow type exposing different information to different external systems.
To execute a query an external client calls a synchronous Temporal API providing namespace, workflowId, query name and optional query arguments.
Query callbacks must be read-only not mutating the Workflow state in any way. The other limitation is that the query callback cannot contain any blocking code. Both above limitations rule out ability to invoke Activities from the query handlers.
The Temporal client libraries expose some predefined queries out of the box. Currently the only supported built-in query is stack_trace. This query returns stacks of all Workflow owned threads. This is a great way to troubleshoot any Workflow in production.