Getting Started with Logic Apps - What happened to the Request? | Tracking and Monitoring Logic App request

{tocify} $title={Table of Contents}

Introduction


What happened to the request  or what happened to the order with Order No #xyz or why the particular order is not processed etc etc – I am sure most of us have faced or at least heard of it and it is most common thing if you are working in Integration domain 😊 .


Off course it is well known situation and way to handle it is to identify the key business entities and have them logged in database/monitoring application and run query against it to do the findings. 

If custom Integration application is build then it should be definitely considered  while designing.

If you are to use someone one else’s product or services  then do check if there is provision for tracking or any out of box monitoring capability available and you can search or query on that tracked data based on the needs.  

If you know BizTalk, then you know that there is out of box feature available i.e. Business Activity Monitoring (BAM) .

Now let’s get to the topic of blog post, tracking key business entities in logic app. 

We do have provision in Logic App wherein the run history of each logic app is maintained and the happenings around each action can be seen (inputs and outputs) – I personally think this is very powerful and helps a lot in troubleshooting the issues but does this solve the above mentioned issue “What happened to the order with Order No #xyz”.

Up to certain extent yes it is helpful, say if you know the time when request was processed then you traversed down to that request processed time or near to it and check few logic apps one by one. 

Now what if there are hundreds or thousands of requests processed during same time?  
- Still it can be done by going through them one by one but the amount of time needed would be too much and the frustration too 😏.

Logic App Product team should really consider this and add a search capability on top of run history.

I am sure down the line in the near future it will be provisioned, but how do we cater the situation now?

For now we can have a function written to log the details to either custom database or application insights and call that function from the logic app and we can search/query the database/application Insight thus saving lot of time and efforts. But note we are to put efforts to write code and efforts in managing (code and database).


So is there a better Way


Yes, there is and it is with the help of Log Analytics service, it is azure monitor log service which collects  Log data (from any Azure resources or any external resource) and  stores it in a Log Analytics workspace (which can be further analyzed by the Log Analytics service through the Log analytics portal).

And provision to integrate Logic App with Log Analytics workspace is through linking them while creating logic app instance and mentioning the properties to track wile developing logic App. In our Logic App, we can add tracked properties onto different actions to track our custom data(e.g, OrderID or MsgID etc)
in diagnostics data.

Let's see how to do it 


Create your Log Analytics Workspace


create log Analytics Workspace


 In Azure Portal-->All services -->Monitor and select Log Analytics workspace

configure log analytics workspace

Give the desired Name,select resource group or create new, select subscription and location. Pricing tier - I would suggest to use Free one as the data is retained for 7 days and it's good enough to  get started .  If you need more days of data retention then choose accordingly 

Note: The first 5 GB of data ingested per customer to the Azure Log Analytics service every month is offered free

Create your Logic App



Order Processing Logic App


While creating instance of Logic App, switch On the Log Analytics and then select from drop down list the workspace created in above step.

When you do this you are telling Logic App runtime engine that it should now start sending Diagnostics Logs to the selected Log Analytics workspace. Details such as status, execution time , Start/end of each run, Start/end for each action, resubmission status,Run ids, Resource group, resource name  and correlation IDs.

Behind the scene , all the above data is added to AzureDiagnostics Table. 


For the sake of simplicity, a simple logic app is created here which will accept Purchase Order (xml) and will send email to the Bill to contact person

Order Process Logic App Design


Next step is to add Tracked Properties, and to add those select the action (not supported in trigger Action) where you want tracking to happened. 


action settings

You can either edit Logic app in code view and add tracked properties or you can use designer to do by clicking on ellipsis of action and selecting the Settings



Add Tracked Properties in Logic App

Give the name of property being tracked and provide the expression to extract the value, here I want to track only orderID of the purchase Order thus below expression

                  json(xml(triggerBody())).purchaseOrder.orderID

                                          

But you can add more than one property if needed. And below is how it looks in code view


logic App code view



What happens when we add Tracked Properties 


When you add tracked properties, a column trackedProperties_Propertyname_s gets added to AzureDiagnostics table of the workspace you created and at runtime only after the particular action on which tracked properties are added is executed then entry is made in this column. So here if SendEmail action is executed then only orderID will be added else nothing will be seen in that column.


Testing 


To test you can use tool like Postman, ARC etc. I have used ARC 

ARC

And following XML as message body

<purchaseOrder>
    <orderID>PO0025</orderID>
<orderDate>2019-10-20</orderDate>
<description>Discount applied on the Order</description>
    <shipTo>
        <name>Mike Taylor</name>
        <street>MG Road</street>
        <city>Pune</city>
        <state>MH</state>
        <pin>411001</pin>
<country>India</country>
    </shipTo>
    <billTo>
        <name>Mike Taylor</name>
        <street>MG Road</street>
        <city>Pune</city>
        <state>MH</state>
        <pin>411001</pin>
<country>India</country>
<emailID>maheshkumar.tiwari@emtecinc.com</emailID>
    </billTo>
    <items>
        <item>
    <productID>ABC123</productID>
            <productName>ABC product</productName>
            <quantity>1</quantity>
            <price>148.95</price>
    <shipDate>2019-10-21</shipDate>
            <comment>Confirm this is electric</comment>
        </item>
        <item>
    <productID>XYZ123</productID>
            <productName>XYZ product</productName>
            <quantity>1</quantity>
            <price>39.98</price>
            <shipDate>2019-10-22</shipDate>
        </item>
    </items>
</purchaseOrder>

Check the logs

checking Logic App tracked properties in logs

Now to check if all went as desired go to Log Workpace created and click on logs and run query on AzureDiagnostics Table. Say to check about all the orders having orderID having PO002 in it ,following query is fired 

AzureDiagnostics
| where trackedProperties_OrderID__s contains "PO002"


Microsoft is on its way to provide Logic App management solutions on top of AzureDiagnostics.It is still in preview but looks promising 

logic app monitoring solution

Click on configure monitoring solutions and you should see all details presented to you as below

Logic App Monitoring Solution

Apart from grouping the requests, there is feature to apply filters and narrow down the search based on our requirement and another very good feature is the abiltiy to  Resubmit one or more logic apps runs that failed, succeeded, or are still running, like in Biztalk we have ESB Portal.


Conclusion


So if I have to search any Order say having OrderId as PO0031 then I have two options


Query the Diagnostics log


In Query tab fire following query

AzureDiagnostics
| where trackedProperties_OrderID__s == "PO0031"

And the result would be as below

result1


Search it in Logic App management solution


Click on Logic App runs tile and apply filter on Tracked Properties column

filter on tracked properties

 And the result would be as below

result


Note : It takes time for the tracked data to get synched in Log Analytics. I experienced around 5-10 minutes lag.



If you know any better way then do share !!!


If you have questions or suggestions, feel free to do in comments section below !!!


Do share if you find this helpful .......
 
                         Knowledge Sharing is Caring !!!!!!


Learn More about Logic App

Post a Comment

If you have any suggestions or questions or want to share something then please drop a comment

Previous Post Next Post