Create a stack trace in Power Automate flows

Many pro developers will be familiar with the concept of stack traces. Can we take this idea into the low code world?

Stack Trace

Within Power Automate I like to use child flows and after the introduction of the Try Catch Finally pattern over 5 years ago and the idea of passing Parent flow URLs to child flows, I’ve been thinking about creating a stack trace.

Create a stack trace in Power Automate flows Microsoft Power Automate image 35

In the pro code world a stack trace can show you which functions/procedures/methods are being called before the current function.

No taking this into Power Automate, if you are a fan of child flows and you develop complicated solutions then this post might help you too.

Imagine if I have two flows (Flow 1 and Flow 2), both these flows call a Child flow and these child flows call another child flow. Now my 3rd Child Flow fails every now and then.

Create a stack trace in Power Automate flows Microsoft Power Automate image 29

Now it will be useful to find out if Flow 1 started the process or if it was Flow 2.

Building the Parent flows

For simplicity reasons I’m going to implement my flows without the Try Catch pattern. Most likely you will want to use that pattern here as well.

From my parent flow I’m going to call a child flow. Notice that all child flows have an input property called Stack.

Create a stack trace in Power Automate flows Microsoft Power Automate image 30

In the above Stack property I’m using the following code to include the flow display name and the URL to the flow run. But we could add more fields ( I’m separating the fields by a comma.)

@{workflow().tags.flowDisplayName}, @{concat('https://make.powerautomate.com/environments/', workflow()?['tags']['environmentName'], '/flows/', workflow()?['name'], '/runs/', workflow()?['run']['name'])}, 

Also notice that there is an empty line and the end of the Stack property.

And then from my child flow I will call another child flow.

Create a stack trace in Power Automate flows Microsoft Power Automate image 31

Now in the first level child flow I’m calling the second child flow and using the Stack property passed in and a similar expression to the earlier child flow call I’m building up my stack trace. This time I’m also including a date/time stamp.

@{triggerBody()['text']}@{workflow().tags.flowDisplayName}, @{concat('https://make.powerautomate.com/environments/', workflow()?['tags']['environmentName'], '/flows/', workflow()?['name'], '/runs/', workflow()?['run']['name'])}, @{utcNow()},

And in my 3rd flow I’m repeating this pattern, but this time I’m sending out an email with the failures details including the stack.

Create a stack trace in Power Automate flows Microsoft Power Automate image 33

And now when we look at the email that was sent, we will find the following stack trace with our flow run details:

Stack Trace in an error handling email form Power Automate

Yes of course, we could now look at formatting the stack trace a bit nicer, but that is merely a small bit of detail. that is easily solved.

Continue Reading Pieter Veenstra’s Article on their blog

Create a stack trace in Power Automate flows

Many pro developers will be familiar with the concept of stack traces. Can we take this idea into the low code world? Within Power Automate I like to use child flows and after the introduction of the Try Catch Finally pattern over 5 years ago and the idea of passing Parent flow URLs to child flows, I’ve been thinking about creating a stack trace.

Blog Syndicated with Pieter Veenstra’s Permission

Author: Pieter Veenstra

Share This Post On
Share via
Copy link
Powered by Social Snap