Friday Fact: Workflow and Trigger expressions can help monitor your Logic Apps.

Indeed, simplicity often proves to be the most effective approach. This holds true, particularly in the context of using the workflow expression alongside the trigger expression.

Consider a scenario where we have numerous Logic Apps operating. Each of them uses a try-catch scope for monitoring potential failures. In these cases, knowing the failed Logic App’s name, run, and timestamp is very important.

To exemplify this, we created a simple Logic App that starts with:

  • When a HTTP request is received trigger
  • Next, we added a Scope named Scope – Try
  • And we added an HTTP connector.

For the sake of this Friday Fact, the HTTP call intentionally fails. As is common with API calls, unforeseen issues can occur, leading to failures or timeouts.

Knowing about potential failures, we added a Catch scope, configuring its run-after to activate under specific conditions.

The idea is to ensure that this Scope executes only when:

  • The Scope – Try:
    • Has timed out
    • Has failed

Next, we added a Compose action with the following JSON and expressions:

  "LogicAppName": "workflow()?['name']",
  "LogicAppRun": "workflow()?['run']?['name']",
  "TriggerStartTime": "replace(first(take(split(trigger()?['startTime'], '.'), sub(length(split(trigger()?['startTime'], '.')), 1))),'T',' ')"

Without accessing properties, this is the result of these individual expressions:

  • workflow()
  • trigger()

When integrated, these expressions facilitate the monitoring of your Logic Apps, providing crucial details such as the name of the failed Logic App, its corresponding run identifier, and the timestamp of the occurrence. To complete the process, we added a response with the Headers key as:

  • content-type

And the value:

  • application/json

Next, we dynamically select the outputs generated by our Compose action.

The result is precious information that can help us save time and make our Logic Apps more efficient.

    "LogicAppName": "LA-TestFailedRuns-POC",
    "LogicAppRun": "08584895385281062838981686639CU96",
    "TriggerStartTime": "2024-04-02 14:32:37"

This information offers versatility in its application, providing opportunities to be used in various contexts, such as, Monitoring and Alerting Systems, Analytics and Reporting, Resource Optimization or Quality Assurance and Testing, always leaving the door open for staying on alert regarding the health of our Logic Apps!

And with this information at hand, and with only two simple expressions, we can create a way to always be notified of which Logic Apps are failing!

Join us next Friday, for another FridayFact!

To lazy to read? We’ve got you covered! Check out our video version of this content!

Hope you find this helpful! If you enjoyed the content or found it useful and wish to support our efforts to create more, you can contribute towards purchasing a Star Wars Lego for Sandro’s son!

Author: Luis Rigueira

Luis Rigueira is a Enterprise Integration Consultant at DevScope

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to Top