Stacktrace in flow

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

Stack Trace

Table of Contents

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.

In this post I will take this concept 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

It will be useful to find out if Flow 1 started the process or if it was Flow 2 that initiated the chiuld flow.

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 with 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

In the first level child flow I’m calling the second child flow. Using the Stack input property, I passed in a similar expression to the earlier child flow call. This way 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 implemented.

Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications Microsoft MVP working as the Head of Power Platform at Vantage 365. You can contact me using contact@sharepains.com

2 thoughts on “Create a stack trace in Power Automate flows”
  1. Hi

    Is there any function to list all running instances of a concurrent flow ?

    I found a power shell command but not sure how it can be integrated with a power automate flow

    I am running concurrent instances of a child flow – when all of them runs I need to update a variable in the parent but not sure how to do it

    kind regards

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains by Microsoft MVP Pieter Veenstra

Subscribe now to keep reading and get access to the full archive.

Continue reading