Sunday, February 19, 2012

Workflow Foundation 4 App-fabric Tracking Variables

Windows Server AppFabric provides a great set of tools and options to manage, scale and monitor application hosted in IIS. Especially for windows workflow applications AppFabric is a required tool to monitor , control and to scale the work-flows.

AppFabric Contoso HR Sample is a good tutorial to start with WF with AppFabric. In this post I'm going to describe how to add tracking variables to the Appfabric event log. This is a huge requirement when we are dealing with WorkFlows. Because in events written by AppFabrric contains a Guid to identify the workflow instance. But it is better if we can write our own id of the workflow in to the tracked events.

Let' say as an example in a order processing system. In this case the order we want to track the worrkflow instances by the order id. So here is how I did it,

First we need to define new tracking profile in the web config system.serviceModel section.





We can create several queries as we want. It may be queries for all activities or some specific activity. The query with activityName="*" will write orderid to the event log in all activities of the activity while query with activityName="Process New Order" will write several other variables in "Process New Order" activity to the events.
To enable this tracking profile for the service we need to go to the Appofabric configuration of the relevant service. Go to AppFabric dashboard of the service -> Services ->Select the service and click Configure .
And then go to Monitoring -> Configure , From the dropdown menu select our tracking profile (My Tracking Profile)

Then when the workflow is running we can see the tracked events with our our variables in tracked variables section.