Επεξεργασία

Κοινή χρήση μέσω


Message Flow Overview

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, in the .NET Framework 4 we added 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.Workflow.ComponentModel 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 Configuring Message Flow Tracing. This topic demonstrates how to enable message flow tracing in the project created in the Getting Started tutorial.

To enable message flow tracing in the Getting Started tutorial

  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 2012. Note that you must run Visual Studio 2012 as an administrator so that the service can be created. If you have the WCF samples installed, you can open the Getting Started, 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.

    <diagnostics>
      <endToEndTracing propagateActivity="true" messageFlowTracing="true"/>
    </diagnostics>
    
  8. In Program.cs in the client, add the following using directive.

    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}" />
    

    Note

    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="http://schemas.microsoft.com/win/2004/08/events/event">
        <System>
            <Provider Name="Microsoft-Windows-Application Server-Applications" Guid="{c651f5f6-1c0d-492e-8ae1-b4efd7c9d503}" />
            <EventID>499</EventID>
            ...
            <Correlation ActivityID="{A066CCF1-8AB3-459B-B62F-F79F957A5036}" RelatedActivityID="{85FC0930-9C49-42DA-804B-A7368104BD1B}" />
            ...
       </System>
    </Event>
    

    Note

    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.