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

  • Luis Rigueira
  • Apr 5, 2024
  • 3 min read

Indeed, simplicity often proves to be the most effective approach. For that reason, this principle applies perfectly when combining the workflow expression with the trigger expression.

For example, consider a scenario with multiple Logic Apps running in parallel. In most cases, each Logic App uses a try‑catch scope to monitor potential failures. As a result, having access to the failed Logic App’s name, run identifier, and execution timestamp becomes essential for troubleshooting and monitoring.

📝 One-Minute Brief

Use workflow and trigger expressions in Azure Logic Apps to capture run details such as workflow name, run ID, and start time, helping you quickly detect, trace, and monitor failed executions.

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.

Scope Try

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

run-after settings

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

  • The Scope – Try:
    • Has timed out
    • Has failed
run-after settings

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

Compose
{
  "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()
response sample
  • trigger()
response sample

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.

Response

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"
}
Postman sample

This information offers versatility in its application, providing opportunities to be used in various contexts, such as Monitoring and Alerting SystemsAnalytics and ReportingResource 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 *

The Ultimate Cloud
Management Platform for Azure

Supercharge your Azure Cost Saving

Learn More
Turbo360 Widget

Back to Top