0
votes

I am building an azure durable function which has may activities/azure functions to be called as a part of Job execution.

I have a requirement to view the total execution time taken for completing an orchestration instance. Is there any way to read the total execution time took to run an instance of durable function orchestration?

1
If you have configured Application Insights it will show you those results, see docs.microsoft.com/en-us/azure/azure-functions/…Peter Bons
Hi Peter, Thanks, Yeah this option is possible only when insights are enabled. I am looking for some kind of API using which I can query orchestration steps on instance id?. Any known api's ?AmrutRayabagi
wel, application insights does store this as well so you can create queries to do this. Maybe you can use GetStatus as well.Peter Bons
Yeah this helps!. Thanks.AmrutRayabagi

1 Answers

1
votes

You can calculate the total execution time for an orchestration by calling the statusQueryGetUri returned when the durable function is first created. The call URI should look like this:

http://<functionappname>.azurewebsites.net/runtime/webhooks/durabletask/instances/<instanceId>?taskHub=<taskHub>&connection=<connectionName>&code=<systemKey>&showHistory=true

The response should look like this:

{
  "createdTime": "2018-02-28T05:18:49Z",
  "historyEvents": [
      ...
  ],
  "input": null,
  "customStatus": { "nextActions": ["A", "B", "C"], "foo": 2 },
  "lastUpdatedTime": "2018-02-28T05:18:54Z",
  "output": [
      ...
  ],
  "runtimeStatus": "Completed"
}

The duration can be determined by polling the status URI until the runtimeStatus reaches any of the terminal states (Failed, Cancelled, Terminated, or Completed), and then subtracting createdTime from lastUpdatedTime.

The following Typescript snippet shows how a the above JSON response (parsed into the status variable) could be processed to show duration as hh:mm:ss:

  formatDuration(status: DurableFunctionJob): string {
    const diff:number = (new Date(status.lastUpdatedTime).getTime() 
                         - new Date(status.createdTime).getTime());
    return new Date(diff).toISOString().substr(11,8);
  }

For the example response, this function outputs 00:00:05.