- Print
- Comment
- DarkLight
- PDF
Logic App Errors Impact Assessment
Recently we had an issue with Logic Apps where an issue on Azure was causing a number of our Logic Apps to get errors. In addition to the underlying error and fixing it, the challenge was also about how to workout the scale and impact of the effect on your organisation.
Back in the day when we implemented BizTalk integration solutions you would have a centralized integration broker and a single view of all interfaces in the management console. Even with a centralized view it can sometimes be hard to workout the impact but with Logic Apps you have a decentralized model for deployment of interfaces. Each Logic App is its own management and deployment unit and also you might have multiple different teams managing Logic Apps across different resource groups and different data centres or even subscriptions.
When you have an issue how do you workout which Logic Apps are affected and how many errors you are dealing with.
In our case fortunately we had all of our Logic Apps in 1 resource group which made things a bit easier, but we have way over 400 Logic Apps and its not easy to workout which ones are affected by a given error. There can also be different errors for different Logic Apps happening which may not be part of the issue you are investigating.
What I wanted to do was firstly get rid of the noise, then zone in on which Logic Apps had possibly been having a problem then easily see the instances which had an error and which actions they were having an error with.
I put together the script at the bottom of the post and the output from it will show the following:
Logic Apps with Error/Success Count
Summarised list of Logic Apps which had Errors
List of the Errors and which action had the error
This will easily help you get to the instance and start troubleshooting
List of Logic Apps which had no errors
Script
The Powershell script to run this is below and hopefully it will help you out if you have an issue. Maybe we will also automate this to give a daily review of all Logic Apps.
$resourceGroupName = 'My resource Group Name'
$myDateFormat = "MM/dd/yyyy HH:mm:ss"
#$localTime = [DateTime]::Now
#$targetTime = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($localTime, 'Mountain Standard Time')
$targetTime = [DateTime]::Now
$startDate = $targetTime.AddHours(-10)
$endDate = $targetTime.AddDays(1)
$logicAppsWithNoErrors = New-Object "System.Collections.Generic.List[System.String]"
$logicAppsWithErrors = New-Object "System.Collections.Generic.List[System.String]"
$errors = New-Object "System.Collections.Generic.List[System.String]"
function LogMessage([string] $message, [ConsoleColor] $color){
Write-Host $message -ForegroundColor $color
}
[datetime]$runDate = New-Object DateTime
Write-Host 'Checking for Logic App Errors between: ' $startDate ' and ' $endDate
$logicApps = Get-AzLogicApp -ResourceGroupName $resourceGroupName
foreach($logicApp in $logicApps){
$logicAppErrorCount = 0
$logicAppSuccessCount = 0
$message = $logicApp.Name + ' checking for errors'
LogMessage -Message $message -color White
$runHistoryList = Get-AzLogicAppRunHistory -ResourceGroupName $resourceGroupName -Name $logicApp.Name
foreach($runHistory in $runHistoryList){
#Parse run date as a date for comparison
$parsed = [DateTime]::TryParseExact($runHistory.StartTime, $myDateFormat,
[System.Globalization.CultureInfo]::InvariantCulture,
[System.Globalization.DateTimeStyles]::None,
[ref]$runDate)
if($parsed -eq $false){
Write-Host 'Date for logic app run does not parse correctly' -ForegroundColor Red
}
if($runDate -ge $startDate){
if($runDate -le $endDate){
if($runHistory.Status -eq 'Succeeded'){
$logicAppSuccessCount = $logicAppSuccessCount + 1
}
if($runHistory.Status -eq 'Failed'){
#Increment error count
$logicAppErrorCount = $logicAppErrorCount + 1
#Add Logic App Error
$message = $logicApp.Name + ':' + $runHistory.Status + ':' + $runHistory.Name + ':' + $runHistory.StartTime
$errors.Add($message)
$runActions = Get-AzLogicAppRunAction -ResourceGroupName $resourceGroupName -Name $logicApp.Name -RunName $runHistory.Name
foreach($runAction in $runActions){
if($runAction.Status -eq 'Failed'){
$message = "`t`t ERROR ACTION = " + $runAction.Name + ' : ' + $runAction.Status
$errors.Add($message)
}
}
$errors.Add('')
}
}
}
}
if($logicAppErrorCount -gt 0){
$message = $logicApp.Name + ' has ' + $logicAppErrorCount + ' errors' + ' and ' + $logicAppSuccessCount + ' successful runs'
$logicAppsWithErrors.Add($message);
$message = "`t`t ERRORS = " + $logicAppErrorCount
Write-Host $message -ForegroundColor Red
}
else{
$message = $logicApp.Name + ' has no errors' + ' and ' + $logicAppSuccessCount + ' successful runs'
$logicAppsWithNoErrors.Add($message);
$message = "`t`t ERRORS = " + $logicAppErrorCount
Write-Host $message -ForegroundColor Green
}
if($logicAppSuccessCount -gt 0){
$message = "`t`t SUCCESS = " + $logicAppSuccessCount
Write-Host $message -ForegroundColor Green
}
else{
$message = "`t`t SUCCESS = " + $logicAppSuccessCount
Write-Host $message -ForegroundColor White
}
}
$message = 'Logic Apps WITH errors'
LogMessage -Message $message -color White
foreach($message in $logicAppsWithErrors){
LogMessage -Message $message -color DarkYellow
}
LogMessage -Message '' -color White
LogMessage -Message '' -color White
$message = 'Errors'
LogMessage -Message $message -color White
foreach($message in $errors){
LogMessage -Message $message -color DarkYellow
}
LogMessage -Message '' -color White
LogMessage -Message '' -color White
$message = 'Logic Apps with NO errors'
LogMessage -Message $message -color White
foreach($message in $logicAppsWithNoErrors){
LogMessage -Message $message -color Green
}
LogMessage -Message '' -color White
LogMessage -Message '' -color White