Share via


Tracking Participants in .NET 4 Beta 1

Hello! My name is Miguel Susffalich and I work in the Connected Framework team. In previous posts we have showed an Introduction to Workflow Tracking and a deep dive into Tracking Profiles in .NET 4 Beta 1.

In this post we will explain how Tracking Participants work and how they are used to process and store the Tracking Records emitted from the workflow. We will also cover the out of box Event Tracing for Windows (ETW) Tracking Participant and how to use it to view Tracking Records in Event Viewer.

You can also try out the following samples for a more hands on experience with Tracking in .NET 4 Beta 1. Throughout this blog post, we will be using several examples contained in these resources:

1) WCF and WF samples for .NET 4 Beta 1

2) ETW tracking participant sample

Tracking Participant Overview

As mentioned in the Introduction to Workflow Tracking, in WF 4 there are 3 main components to the tracking infrastructure:

1) Tracking Records are emitted from the Workflow Runtime.

2) Tracking Profiles let you subscribe to Tracking Records in a declarative, flexible manner.

3) Tracking Participants listen to the Tracking Records being emitted from the runtime directly and process them in whatever way they choose to. This includes writing to a specific output (e.g. File, Console, ETW), processing/aggregating the records, or any other combination that might be required.

image

In WF 4, multiple tracking participants can consume the tracking events simultaneously. Each tracking participant can be associated with a different tracking profile.

Tracking Participants are used to get the tracking data emitted from the workflow and store it into different mediums. Likewise, any post processing on the Tracking Records can also be done within the Tracking Participant. In future posts we will cover the full extensibility of the Tracking infrastructure provided in WF 4, including writing Custom Tracking Participants.

Next we will look at the out of box Tracking Participant included in .Net 4 Beta 1; the ETW Tracking Participant.

Out of box ETW Tracking Participant

In .NET 4, we ship an out of box Event Tracing for Windows (ETW) Tracking Participant which writes the Tracking Records to ETW. The ETW Tracking Participant writes these records to an ETW session in a very efficient manner with minimal impact to the app’s performance.

One of the advantages of using this tracking participant is the tracking records can be viewed in the Windows Event Viewer, alongside your application and system logs.

The ETW tracking participant is configured in the web.config as follows

<configuration>

  <system.web>

    <compilation targetFrameworkMoniker=".NETFramework,Version=v4.0"/>

  </system.web>

  <system.serviceModel>

    <diagnostics etwProviderId="52A3165D-4AD9-405C-B1E8-7D9A257EAC9F" />

    <tracking>

      <participants>

        <add name="EtwTrackingParticipant"

             type="System.Activities.Tracking.EtwTrackingParticipant, System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

             profileName="HealthMonitoring_Tracking_Profile"/>

      </participants>

    </tracking>

    <behaviors>

      <serviceBehaviors>

        <behavior name="SampleTrackingSample.SampleWFBehavior">

          <trackingComponents>

            <add name="EtwTrackingParticipant"/>

          </trackingComponents>

        </behavior>

      </serviceBehaviors>

    </behaviors>

  </system.serviceModel>

</configuration>

In ETW, events are written to the ETW session through a Provider Id. The Provider Id that the ETW Tracking Participant uses for writing the Tracking Records to ETW is defined in the diagnostics section of the web.config (under <system.serviceModel><diagnostics> ):

<system.serviceModel>

        <diagnostics etwProviderId="52A3165D-4AD9-405C-B1E8-7D9A257EAC9F" />

By default, the ETW Tracking Participant uses a default Provider ID when one has not been specified.

Tracking Participants are declared in the <system.serviceModel><tracking><participants> section. Each tracking participant can have a profile associated with it to specify the tracking records it has subscribed to:

<system.serviceModel>

    <tracking>

      <participants>

        <add name="EtwTrackingParticipant"

             type="System.Activities.Tracking.EtwTrackingParticipant, System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

             profileName="HealthMonitoring_Tracking_Profile"/>

      </participants>

    </tracking>

… 

Once they have been declared, the Tracking Participants can be added to the service behavior. This will add the selected Tracking Participants to the Workflow instance’s extensions, so that they begin to receive the Tracking Records.

For this, we simply use the same name with which the Tracking Participant was declared in the previous step:

<behaviors>

      <serviceBehaviors>

        <behavior name="SampleTrackingSample.SampleWFBehavior">

          <trackingComponents>

            <add name="EtwTrackingParticipant"/>

          </trackingComponents>

        </behavior>

      </serviceBehaviors>

</behaviors>

A graphical representation of the flow of Tracking data through the ETW Tracking Participant would be as follows:

image

Once the tracking data reaches the ETW Session, it can be consumed in a number of ways. One of the most useful ways to consume these events is through Event Viewer, a common Windows tool used for viewing logs and traces from applications and services.

Consuming Tracking data from the ETW Tracking Participant in Event Viewer

Events that are written to the ETW session by the ETW Tracking Participant can be consumed through Event Viewer (when using the default Provider ID). This allows for rapidly viewing the Tracking Records that have been emitted by the workflow.

To enabling viewing the Tracking Records in Event Viewer:

1) Open Event Viewer (eventvwr.exe)

2) Navigate to “Application and Services Logs”-> “Microsoft” -> “WCF” -> “WF-Development”

3) Right-click and enable View -> “Show Analytic and Debug logs”

4) Enable the log

In the ETW Tracking Participant Sample, the workflow simulates to have an error, and the ETW Tracking Participant is used to trace the issue. The tracking events are displayed in the Event Viewer below:

image

All the Tracking Records have ETW event IDs ranging from 100-112. Other event IDs (200-225) are used for other types of tracing such as WCF Traces. In future posts we will cover correlating tracing and tracking events for a full end-to-end view of the monitoring data.

Tracking Records emitted through the ETW Tracking Participant also appear with the appropriate severity level in Event Viewer. This way it is easy to identify any warnings or errors with the execution of the workflow.

With the ETW Tracking Participant and its integration with Event Viewer, consuming Tracking Records is fast and easy in .Net 4 Beta 1.

What’s Next

In future posts we will cover writing Custom Tracking Participants and emitting Custom Tracking Records. In the meantime, we look forward to your feedback on our samples and Hands on Labs:

1) WCF and WF samples for .NET 4 Beta 1

2) ETW tracking participant sample