In a distributed system containing interconnected services, it is necessary to determine causal relationships between the services. It is important to understand the various components that were part of a request flow to support critical scenarios such as health monitoring, troubleshooting, and root cause analysis. To enable the correlation of traces between various services, the .NET Framework 4 has additional support through the following features:

  • Analytic tracing: A high performance and low verbosity tracing feature using Event Tracing for Windows (ETW).
  • End-to-end activity model for WCF/WF services: This feature supports correlation of traces generated by the System.ServiceModel and System.WorkflowModel namespaces.
  • ETW tracking for WF: This feature uses tracking records generated by WF services to provide visibility into the workflow’s current state and progress.

Errors logged in a tracking or tracing record can be used to find code defects or incorrectly formed messages. The ActivityId property of the Correlation node in the event’s message header can be used to determine the faulting activity. To enable message flow tracing by activity ID, see the Configuring Message Flow Tracing topic in the MSDN library.

The following steps demonstrate how to enable message flow tracing in the project created in the Getting Started tutorial in Visual Studio 2010.

  1. Open Event Viewer by clicking Start, Run, and entering eventvwr.exe.

  2. If you haven’t enabled analytic tracing, expand Applications and Services Logs, Microsoft, Windows, Application Server-Applications. Select View, Show Analytic and Debug Logs. Right-click Analytic and select Enable Log. Leave Event Viewer open so that traces can be viewed.

  3. Open the sample created in the Getting Started Tutorial in Visual Studio 2010. Note that you must run Visual Studio 2010 as an administrator so that the service can be created. If you have the WCF samples installed, you can open the Getting Started Sample, which contains the completed project created in the tutorial.

  4. Right-click the Service project and select Add, New Item. Select Application Configuration File and click OK.

  5. Add the following code to the App.Config file created in the previous step.

    <system.serviceModel>  <diagnostics>     <endToEndTracing propagateActivity="true" messageFlowTracing="true"/>   </diagnostics></system.serviceModel>
  6. Execute the server application without debugging by pressing CTRL+F5. Execute the client project by right-clicking the Client project and selecting Debug, Start New Instance.

  7. To trace the events from the client to the server, add the following to the application configuration file in the Client project.

      <endToEndTracing propagateActivity="true" messageFlowTracing="true"/>

  8. In Program.cs in the client, add the following Using statement.

    using System.Diagnostics;

  9. In the Main method in the program.cs file in the client project, set the Trace GUID to be propagated in the event log.

    Guid guid = Guid.NewGuid();
    Trace.CorrelationManager.ActivityId = guid;

  10. Refresh and examine the Analytic log. Look for an event with Event ID 220. Select the event, and click the Details tab in the preview pane. This event will contain the correlation ID for the calling activity.

    <Correlation ActivityID="{A066CCF1-8AB3-459B-B62F-F79F957A5036}" />
    All events with the same GUID in the ActivityID are related to one request. This can be used to correlate messages from a specific client to a specific service. If the client called another service, then the same client could be identified by ActivityID.  


  11. In some cases, the ActivityID can change from the original GUID to a new ActivityID. In that case, a transfer event is emitted. This event ID is 499, and the event will contain the following data in the header.

    <Event xmlns="">
            <Provider Name="Microsoft-Windows-Application Server-Applications" Guid="{c651f5f6-1c0d-492e-8ae1-b4efd7c9d503}" />
            <Correlation ActivityID="{A066CCF1-8AB3-459B-B62F-F79F957A5036}" RelatedActivityID="{85FC0930-9C49-42DA-804B-A7368104BD1B}" />
    The transfer event records the change of the active ActivityID from the GUID specified as the ActivityID to the GUID specified as RelatedActivityID. After the transfer event is emitted, all events will contain the new GUID as the ActivityID.